OLD | NEW |
| (Empty) |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 package rawdatastore | |
6 | |
7 import ( | |
8 "fmt" | |
9 | |
10 "golang.org/x/net/context" | |
11 ) | |
12 | |
13 // Key is the equivalent of *datastore.Key from the original SDK, except that | |
14 // it can have multiple implementations. See helper.Key* methods for missing | |
15 // methods like KeyIncomplete (and some new ones like KeyValid). | |
16 type Key interface { | |
17 Kind() string | |
18 StringID() string | |
19 IntID() int64 | |
20 Parent() Key | |
21 AppID() string | |
22 Namespace() string | |
23 | |
24 String() string | |
25 } | |
26 | |
27 // KeyTok is a single token from a multi-part Key. | |
28 type KeyTok struct { | |
29 Kind string | |
30 IntID int64 | |
31 StringID string | |
32 } | |
33 | |
34 // Cursor wraps datastore.Cursor. | |
35 type Cursor interface { | |
36 fmt.Stringer | |
37 } | |
38 | |
39 // Query wraps datastore.Query. | |
40 type Query interface { | |
41 Ancestor(ancestor Key) Query | |
42 Distinct() Query | |
43 End(c Cursor) Query | |
44 EventualConsistency() Query | |
45 Filter(filterStr string, value interface{}) Query | |
46 KeysOnly() Query | |
47 Limit(limit int) Query | |
48 Offset(offset int) Query | |
49 Order(fieldName string) Query | |
50 Project(fieldNames ...string) Query | |
51 Start(c Cursor) Query | |
52 } | |
53 | |
54 // RunCB is the callback signature provided to Interface.Run | |
55 // | |
56 // - key is the Key of the entity | |
57 // - val is the data of the entity (or nil, if the query was keys-only) | |
58 // - getCursor can be invoked to obtain the current cursor. | |
59 // | |
60 // Return true to continue iterating through the query results, or false to stop
. | |
61 type RunCB func(key Key, val PropertyMap, getCursor func() (Cursor, error)) bool | |
62 | |
63 // GetMultiCB is the callback signature provided to Interface.GetMulti | |
64 // | |
65 // - val is the data of the entity | |
66 // * It may be nil if some of the keys to the GetMulti were bad, since all | |
67 // keys are validated before the RPC occurs! | |
68 // - err is an error associated with this entity (e.g. ErrNoSuchEntity). | |
69 type GetMultiCB func(val PropertyMap, err error) | |
70 | |
71 // PutMultiCB is the callback signature provided to Interface.PutMulti | |
72 // | |
73 // - key is the new key for the entity (if the original was incomplete) | |
74 // * It may be nil if some of the keys/vals to the PutMulti were bad, since | |
75 // all keys are validated before the RPC occurs! | |
76 // - err is an error associated with putting this entity. | |
77 type PutMultiCB func(key Key, err error) | |
78 | |
79 // DeleteMultiCB is the callback signature provided to Interface.DeleteMulti | |
80 // | |
81 // - err is an error associated with deleting this entity. | |
82 type DeleteMultiCB func(err error) | |
83 | |
84 // Interface implements the datastore functionality without any of the fancy | |
85 // reflection stuff. This is so that Filters can avoid doing lots of redundant | |
86 // reflection work. See datastore.Interface for a more user-friendly interface. | |
87 type Interface interface { | |
88 NewKey(kind, stringID string, intID int64, parent Key) Key | |
89 DecodeKey(encoded string) (Key, error) | |
90 NewQuery(kind string) Query | |
91 | |
92 RunInTransaction(f func(c context.Context) error, opts *TransactionOptio
ns) error | |
93 | |
94 // Run executes the given query, and calls `cb` for each successfully it
em. | |
95 Run(q Query, cb RunCB) error | |
96 | |
97 // GetMulti retrieves items from the datastore. | |
98 // | |
99 // Callback execues once per key, in the order of keys. Callback may not | |
100 // execute at all if there's a server error. If callback is nil, this | |
101 // method does nothing. | |
102 // | |
103 // NOTE: Implementations and filters are guaranteed that keys are all Va
lid | |
104 // and Complete, and in the correct namespace. | |
105 GetMulti(keys []Key, cb GetMultiCB) error | |
106 | |
107 // PutMulti writes items to the datastore. | |
108 // | |
109 // Callback execues once per item, in the order of itemss. Callback may
not | |
110 // execute at all if there's a server error. | |
111 // | |
112 // NOTE: Implementations and filters are guaranteed that len(keys) == | |
113 // len(vals), that keys are all Valid, and in the correct namespace. | |
114 // Additionally, vals are guaranteed to be PropertyMaps already. Callbac
k | |
115 // may be nil. | |
116 PutMulti(keys []Key, vals []PropertyLoadSaver, cb PutMultiCB) error | |
117 | |
118 // DeleteMulti removes items from the datastore. | |
119 // | |
120 // Callback execues once per key, in the order of keys. Callback may not | |
121 // execute at all if there's a server error. | |
122 // | |
123 // NOTE: Implementations and filters are guaranteed that keys are all Va
lid | |
124 // and Complete, and in the correct namespace, and are not 'special'. | |
125 // Callback may be nil. | |
126 DeleteMulti(keys []Key, cb DeleteMultiCB) error | |
127 } | |
OLD | NEW |