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

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

Issue 1259593005: Add 'user friendly' datastore API. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: 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
OLDNEW
(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 datastore
6
7 import (
8 "golang.org/x/net/context"
9 )
10
11 // RunCB is the callback signature provided to Interface.Run
12 //
13 // - obj is an object as specified by the proto argument of Run
Vadim Sh. 2015/07/29 16:21:43 consider passing a struct type PartialResult str
iannucci 2015/08/03 03:56:31 I tried this, but it's not really worth the extra
14 // - getCursor can be invoked to obtain the current cursor.
15 //
16 // Return true to continue iterating through the query results, or false to stop .
17 type RunCB func(obj interface{}, getCursor func() (Cursor, error)) bool
18
19 type Interface interface {
20 NewKey(kind, stringID string, intID int64, parent Key) Key
21
22 // NewKeyObj extracts a key from src.
23 //
24 // If there's a probjem obtaining the key, this method will panic.
25 //
26 // src must be one of:
27 // - *S where S is a struct
Vadim Sh. 2015/07/29 16:21:43 struct tagged with meta-how-do-you-call-them tags?
iannucci 2015/08/03 03:56:32 Done.
28 // - a PropertyLoadSaver
29 NewKeyObj(src interface{}) Key
30
31 // NewKeyObjErr extracts a key from src.
32 //
33 // src must be one of:
34 // - *S where S is a struct
35 // - a PropertyLoadSaver
36 NewKeyObjErr(src interface{}) (Key, error)
37
38 DecodeKey(encoded string) (Key, error)
Vadim Sh. 2015/07/29 16:21:43 document?
iannucci 2015/08/03 03:56:32 Done.
39 NewQuery(kind string) Query
40
41 RunInTransaction(f func(c context.Context) error, opts *TransactionOptio ns) error
42
43 // Run executes the given query, and calls `cb` for each successfully it em.
Vadim Sh. 2015/07/29 16:21:43 typos: successfully item
iannucci 2015/08/03 03:56:32 Done.
44 //
45 // proto is a prototype of the objects which will be passed to the callb ack.
Vadim Sh. 2015/07/29 16:21:43 It won't be written to, right?
iannucci 2015/08/03 03:56:32 correct. documented.
46 // It must be of the form:
47 // - *S where S is a struct
48 // - *P where *P is a concrete type implementing PropertyLoadSaver
49 // - *Key implies a keys-only query (and cb will be invoked with Key's )
50 // Run will create a new, populated instance of proto for each call of
51 // cb. Run stops on the first error encountered.
52 Run(q Query, proto interface{}, cb RunCB) error
53
54 // GetAll retrieves all of the Query results into dst.
55 //
56 // dst must be one of:
57 // - *[]S or *[]*S where S is a struct
58 // - *[]P or *[]*P where *P is a concrete type implementing PropertyLo adSaver
59 // - *[]Key implies a keys-only query.
60 GetAll(q Query, dst interface{}) error
61
62 // Get retrieves a single object from the datastore
63 //
64 // dst must be one of:
65 // - *S where S is a struct
66 // - *P where *P is a concrete type implementing PropertyLoadSaver
67 Get(dst interface{}) error
68
69 // Put inserts a single object into the datastore
70 //
71 // src must be one of:
72 // - *S where S is a struct
73 // - *P where *P is a concrete type implementing PropertyLoadSaver
74 //
75 // If src resolves to an Incomplete key, Put will write the
Vadim Sh. 2015/07/29 16:21:43 its for autogenerating ids?
iannucci 2015/08/03 03:56:32 right. Incomplete specifically means `StringID ==
76 // resolved key back to src.
77 Put(src interface{}) error
78
79 // Delete removes an item from the datastore.
80 Delete(key Key) error
81
82 // GetMulti retrieves items from the datastore.
83 //
84 // dst must be one of:
85 // - []S or []*S where S is a struct
86 // - []P or []*P where *P is a concrete type implementing PropertyLoad Saver
87 // - []I where I is some interface type. Each element of the slice mus t
88 // be non-nil, and its underlying type must be either *S o r *P.
89 GetMulti(dst interface{}) error
90
91 // PutMulti writes items to the datastore.
92 //
93 // src must be one of:
94 // - []S or []*S where S is a struct
95 // - []P or []*P where *P is a concrete type implementing PropertyLoad Saver
96 // - []I where i is some interface type. Each elemet of the slice must
97 // be non-nil, and its underlying type must be either *S or *P.
98 //
99 // If items in src resolve to Incomplete keys, PutMulti will write the
100 // resolved keys back to the items in src.
101 PutMulti(src interface{}) error
102
103 // DeleteMulti removes items from the datastore.
104 DeleteMulti(keys []Key) error
105
106 // Raw returns the underlying RawInterface. The Interface and RawInterfa ce may
107 // be used interchangably; there's no danger of interleaving access to t he
108 // datastore via the two.
109 Raw() RawInterface
110 }
111
112 // Get gets the Interface implementation from context.
113 func Get(c context.Context) Interface {
114 return &datastoreImpl{GetRaw(c)}
115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698