Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(565)

Side by Side Diff: service/datastore/dumper/dumper_example_test.go

Issue 2037433002: Add datastore dumper tool. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/gae@allow_unsigned
Patch Set: fix copyright Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « service/datastore/dumper/dumper.go ('k') | service/datastore/properties.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package dumper
6
7 import (
8 "fmt"
9
10 "github.com/luci/gae/impl/memory"
11 "github.com/luci/gae/service/datastore"
12 "golang.org/x/net/context"
13 )
14
15 type ExampleModel struct {
16 Kind string `gae:"$kind,Example"`
17 ID int64 `gae:"$id"`
18 Parent *datastore.Key `gae:"$parent"`
19
20 Vals []string
21 Number int64
22 HexNumber int64
23 }
24
25 func ExampleConfig_Query() {
26 c := context.Background()
27 c = memory.Use(c)
28
29 ds := datastore.Get(c)
30 root := ds.MakeKey("Parent", 1)
31 models := []*ExampleModel{
32 {ID: 1, Vals: []string{"hi", "there"}, Number: 10, HexNumber: 20 },
33 {ID: 2, Vals: []string{"other"}, Number: 11, HexNumber: 21},
34 {ID: 1, Parent: root, Vals: []string{"child", "ent"}},
35 {Kind: "Other", ID: 1, Vals: []string{"other"}, Number: 11, HexN umber: 21},
36 }
37 if err := ds.Put(models); err != nil {
38 panic(err)
39 }
40 // indexes must be up-to-date here.
41 ds.Testable().CatchupIndexes()
42
43 _, err := Config{
44 PropFilters: PropFilterMap{
45 {"Example", "HexNumber"}: func(p datastore.Property) str ing {
46 return fmt.Sprintf("0x%04x", p.Value())
47 },
48 },
49 KindFilters: KindFilterMap{
50 "Other": func(key *datastore.Key, pm datastore.PropertyM ap) string {
51 return "I AM A BANANA"
52 },
53 },
54 }.Query(c, nil)
55 if err != nil {
56 panic(err)
57 }
58
59 // Output:
60 // dev~app::/Example,1:
61 // "HexNumber": [0x0014]
62 // "Number": [PTInt(10)]
63 // "Vals": [
64 // PTString("hi"),
65 // PTString("there")
66 // ]
67 //
68 // dev~app::/Example,2:
69 // "HexNumber": [0x0015]
70 // "Number": [PTInt(11)]
71 // "Vals": [PTString("other")]
72 //
73 // dev~app::/Other,1:
74 // I AM A BANANA
75 //
76 // dev~app::/Parent,1/Example,1:
77 // "HexNumber": [0x0000]
78 // "Number": [PTInt(0)]
79 // "Vals": [
80 // PTString("child"),
81 // PTString("ent")
82 // ]
83 }
OLDNEW
« no previous file with comments | « service/datastore/dumper/dumper.go ('k') | service/datastore/properties.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698