OLD | NEW |
1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package dumper | 5 package dumper |
6 | 6 |
7 import ( | 7 import ( |
8 "fmt" | 8 "fmt" |
9 | 9 |
10 "github.com/luci/gae/impl/memory" | 10 "github.com/luci/gae/impl/memory" |
11 » "github.com/luci/gae/service/datastore" | 11 » ds "github.com/luci/gae/service/datastore" |
| 12 |
12 "golang.org/x/net/context" | 13 "golang.org/x/net/context" |
13 ) | 14 ) |
14 | 15 |
15 type ExampleModel struct { | 16 type ExampleModel struct { |
16 » Kind string `gae:"$kind,Example"` | 17 » Kind string `gae:"$kind,Example"` |
17 » ID int64 `gae:"$id"` | 18 » ID int64 `gae:"$id"` |
18 » Parent *datastore.Key `gae:"$parent"` | 19 » Parent *ds.Key `gae:"$parent"` |
19 | 20 |
20 Vals []string | 21 Vals []string |
21 Number int64 | 22 Number int64 |
22 HexNumber int64 | 23 HexNumber int64 |
23 } | 24 } |
24 | 25 |
25 func ExampleConfig_Query() { | 26 func ExampleConfig_Query() { |
26 c := context.Background() | 27 c := context.Background() |
27 c = memory.Use(c) | 28 c = memory.Use(c) |
28 | 29 |
29 » ds := datastore.Get(c) | 30 » root := ds.MakeKey(c, "Parent", 1) |
30 » root := ds.MakeKey("Parent", 1) | |
31 models := []*ExampleModel{ | 31 models := []*ExampleModel{ |
32 {ID: 1, Vals: []string{"hi", "there"}, Number: 10, HexNumber: 20
}, | 32 {ID: 1, Vals: []string{"hi", "there"}, Number: 10, HexNumber: 20
}, |
33 {ID: 2, Vals: []string{"other"}, Number: 11, HexNumber: 21}, | 33 {ID: 2, Vals: []string{"other"}, Number: 11, HexNumber: 21}, |
34 {ID: 1, Parent: root, Vals: []string{"child", "ent"}}, | 34 {ID: 1, Parent: root, Vals: []string{"child", "ent"}}, |
35 {Kind: "Other", ID: 1, Vals: []string{"other"}, Number: 11, HexN
umber: 21}, | 35 {Kind: "Other", ID: 1, Vals: []string{"other"}, Number: 11, HexN
umber: 21}, |
36 } | 36 } |
37 » if err := ds.Put(models); err != nil { | 37 » if err := ds.Put(c, models); err != nil { |
38 panic(err) | 38 panic(err) |
39 } | 39 } |
40 // indexes must be up-to-date here. | 40 // indexes must be up-to-date here. |
41 » ds.Testable().CatchupIndexes() | 41 » ds.GetTestable(c).CatchupIndexes() |
42 | 42 |
43 _, err := Config{ | 43 _, err := Config{ |
44 PropFilters: PropFilterMap{ | 44 PropFilters: PropFilterMap{ |
45 » » » {"Example", "HexNumber"}: func(p datastore.Property) str
ing { | 45 » » » {"Example", "HexNumber"}: func(p ds.Property) string { |
46 return fmt.Sprintf("0x%04x", p.Value()) | 46 return fmt.Sprintf("0x%04x", p.Value()) |
47 }, | 47 }, |
48 }, | 48 }, |
49 KindFilters: KindFilterMap{ | 49 KindFilters: KindFilterMap{ |
50 » » » "Other": func(key *datastore.Key, pm datastore.PropertyM
ap) string { | 50 » » » "Other": func(key *ds.Key, pm ds.PropertyMap) string { |
51 return "I AM A BANANA" | 51 return "I AM A BANANA" |
52 }, | 52 }, |
53 }, | 53 }, |
54 }.Query(c, nil) | 54 }.Query(c, nil) |
55 if err != nil { | 55 if err != nil { |
56 panic(err) | 56 panic(err) |
57 } | 57 } |
58 | 58 |
59 // Output: | 59 // Output: |
60 // dev~app::/Example,1: | 60 // dev~app::/Example,1: |
(...skipping 13 matching lines...) Expand all Loading... |
74 // I AM A BANANA | 74 // I AM A BANANA |
75 // | 75 // |
76 // dev~app::/Parent,1/Example,1: | 76 // dev~app::/Parent,1/Example,1: |
77 // "HexNumber": 0x0000 | 77 // "HexNumber": 0x0000 |
78 // "Number": PTInt(0) | 78 // "Number": PTInt(0) |
79 // "Vals": [ | 79 // "Vals": [ |
80 // PTString("child"), | 80 // PTString("child"), |
81 // PTString("ent") | 81 // PTString("ent") |
82 // ] | 82 // ] |
83 } | 83 } |
OLD | NEW |