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

Side by Side Diff: service/rawdatastore/interface.go

Issue 1253263002: Make rawdatastore API safer for writing filters. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix comments Created 5 years, 4 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/rawdatastore/datastore_key_test.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package rawdatastore 5 package rawdatastore
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 9
10 "golang.org/x/net/context" 10 "golang.org/x/net/context"
11 ) 11 )
12 12
13 /// Kinds + Keys
14
15 // Key is the equivalent of *datastore.Key from the original SDK, except that 13 // Key is the equivalent of *datastore.Key from the original SDK, except that
16 // it can have multiple implementations. See helper.Key* methods for missing 14 // it can have multiple implementations. See helper.Key* methods for missing
17 // methods like KeyIncomplete (and some new ones like KeyValid). 15 // methods like KeyIncomplete (and some new ones like KeyValid).
18 type Key interface { 16 type Key interface {
19 Kind() string 17 Kind() string
20 StringID() string 18 StringID() string
21 IntID() int64 19 IntID() int64
22 Parent() Key 20 Parent() Key
23 AppID() string 21 AppID() string
24 Namespace() string 22 Namespace() string
(...skipping 21 matching lines...) Expand all
46 EventualConsistency() Query 44 EventualConsistency() Query
47 Filter(filterStr string, value interface{}) Query 45 Filter(filterStr string, value interface{}) Query
48 KeysOnly() Query 46 KeysOnly() Query
49 Limit(limit int) Query 47 Limit(limit int) Query
50 Offset(offset int) Query 48 Offset(offset int) Query
51 Order(fieldName string) Query 49 Order(fieldName string) Query
52 Project(fieldNames ...string) Query 50 Project(fieldNames ...string) Query
53 Start(c Cursor) Query 51 Start(c Cursor) Query
54 } 52 }
55 53
56 // Iterator wraps datastore.Iterator. 54 // RunCB is the callback signature provided to Interface.Run
57 type Iterator interface { 55 //
58 » Cursor() (Cursor, error) 56 // - key is the Key of the entity
59 » Next(dst PropertyLoadSaver) (Key, error) 57 // - val is the data of the entity (or nil, if the query was keys-only)
60 } 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)
61 83
62 // Interface implements the datastore functionality without any of the fancy 84 // Interface implements the datastore functionality without any of the fancy
63 // reflection stuff. This is so that Filters can avoid doing lots of redundant 85 // reflection stuff. This is so that Filters can avoid doing lots of redundant
64 // reflection work. See helper.Datastore for a more user-friendly interface. 86 // reflection work. See datastore.Interface for a more user-friendly interface.
65 type Interface interface { 87 type Interface interface {
66 NewKey(kind, stringID string, intID int64, parent Key) Key 88 NewKey(kind, stringID string, intID int64, parent Key) Key
67 DecodeKey(encoded string) (Key, error) 89 DecodeKey(encoded string) (Key, error)
68
69 NewQuery(kind string) Query 90 NewQuery(kind string) Query
70 Count(q Query) (int, error)
71 91
72 RunInTransaction(f func(c context.Context) error, opts *TransactionOptio ns) error 92 RunInTransaction(f func(c context.Context) error, opts *TransactionOptio ns) error
73 93
74 » Run(q Query) Iterator 94 » // Run executes the given query, and calls `cb` for each successfully it em.
75 » GetAll(q Query, dst *[]PropertyMap) ([]Key, error) 95 » Run(q Query, cb RunCB) error
76 96
77 » Put(key Key, src PropertyLoadSaver) (Key, error) 97 » // GetMulti retrieves items from the datastore.
78 » Get(key Key, dst PropertyLoadSaver) error 98 » //
79 » Delete(key Key) error 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
80 106
81 » // These allow you to read and write a multiple datastore objects in 107 » // PutMulti writes items to the datastore.
82 » // a non-atomic batch. 108 » //
83 » DeleteMulti(keys []Key) error 109 » // Callback execues once per item, in the order of itemss. Callback may not
84 » GetMulti(keys []Key, dst []PropertyLoadSaver) error 110 » // execute at all if there's a server error.
85 » PutMulti(keys []Key, src []PropertyLoadSaver) ([]Key, 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
86 } 127 }
OLDNEW
« no previous file with comments | « service/rawdatastore/datastore_key_test.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698