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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « service/rawdatastore/datastore_key_test.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/rawdatastore/interface.go
diff --git a/service/rawdatastore/interface.go b/service/rawdatastore/interface.go
index 0764031d1daeecd31ea004df681794aeb0fee2b4..220cf6ec5026f9fa2e7008beb77499ee3f5f95a0 100644
--- a/service/rawdatastore/interface.go
+++ b/service/rawdatastore/interface.go
@@ -10,8 +10,6 @@ import (
"golang.org/x/net/context"
)
-/// Kinds + Keys
-
// Key is the equivalent of *datastore.Key from the original SDK, except that
// it can have multiple implementations. See helper.Key* methods for missing
// methods like KeyIncomplete (and some new ones like KeyValid).
@@ -53,34 +51,77 @@ type Query interface {
Start(c Cursor) Query
}
-// Iterator wraps datastore.Iterator.
-type Iterator interface {
- Cursor() (Cursor, error)
- Next(dst PropertyLoadSaver) (Key, error)
-}
+// RunCB is the callback signature provided to Interface.Run
+//
+// - key is the Key of the entity
+// - val is the data of the entity (or nil, if the query was keys-only)
+// - getCursor can be invoked to obtain the current cursor.
+//
+// Return true to continue iterating through the query results, or false to stop.
+type RunCB func(key Key, val PropertyMap, getCursor func() (Cursor, error)) bool
+
+// GetMultiCB is the callback signature provided to Interface.GetMulti
+//
+// - val is the data of the entity
+// * It may be nil if some of the keys to the GetMulti were bad, since all
+// keys are validated before the RPC occurs!
+// - err is an error associated with this entity (e.g. ErrNoSuchEntity).
+type GetMultiCB func(val PropertyMap, err error)
+
+// PutMultiCB is the callback signature provided to Interface.PutMulti
+//
+// - key is the new key for the entity (if the original was incomplete)
+// * It may be nil if some of the keys/vals to the PutMulti were bad, since
+// all keys are validated before the RPC occurs!
+// - err is an error associated with putting this entity.
+type PutMultiCB func(key Key, err error)
+
+// DeleteMultiCB is the callback signature provided to Interface.DeleteMulti
+//
+// - err is an error associated with deleting this entity.
+type DeleteMultiCB func(err error)
// Interface implements the datastore functionality without any of the fancy
// reflection stuff. This is so that Filters can avoid doing lots of redundant
-// reflection work. See helper.Datastore for a more user-friendly interface.
+// reflection work. See datastore.Interface for a more user-friendly interface.
type Interface interface {
NewKey(kind, stringID string, intID int64, parent Key) Key
DecodeKey(encoded string) (Key, error)
-
NewQuery(kind string) Query
- Count(q Query) (int, error)
RunInTransaction(f func(c context.Context) error, opts *TransactionOptions) error
- Run(q Query) Iterator
- GetAll(q Query, dst *[]PropertyMap) ([]Key, error)
-
- Put(key Key, src PropertyLoadSaver) (Key, error)
- Get(key Key, dst PropertyLoadSaver) error
- Delete(key Key) error
-
- // These allow you to read and write a multiple datastore objects in
- // a non-atomic batch.
- DeleteMulti(keys []Key) error
- GetMulti(keys []Key, dst []PropertyLoadSaver) error
- PutMulti(keys []Key, src []PropertyLoadSaver) ([]Key, error)
+ // Run executes the given query, and calls `cb` for each successfully item.
+ Run(q Query, cb RunCB) error
+
+ // GetMulti retrieves items from the datastore.
+ //
+ // Callback execues once per key, in the order of keys. Callback may not
+ // execute at all if there's a server error. If callback is nil, this
+ // method does nothing.
+ //
+ // NOTE: Implementations and filters are guaranteed that keys are all Valid
+ // and Complete, and in the correct namespace.
+ GetMulti(keys []Key, cb GetMultiCB) error
+
+ // PutMulti writes items to the datastore.
+ //
+ // Callback execues once per item, in the order of itemss. Callback may not
+ // execute at all if there's a server error.
+ //
+ // NOTE: Implementations and filters are guaranteed that len(keys) ==
+ // len(vals), that keys are all Valid, and in the correct namespace.
+ // Additionally, vals are guaranteed to be PropertyMaps already. Callback
+ // may be nil.
+ PutMulti(keys []Key, vals []PropertyLoadSaver, cb PutMultiCB) error
+
+ // DeleteMulti removes items from the datastore.
+ //
+ // Callback execues once per key, in the order of keys. Callback may not
+ // execute at all if there's a server error.
+ //
+ // NOTE: Implementations and filters are guaranteed that keys are all Valid
+ // and Complete, and in the correct namespace, and are not 'special'.
+ // Callback may be nil.
+ DeleteMulti(keys []Key, cb DeleteMultiCB) error
}
« 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