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

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

Issue 1279703003: Get rid of awkward proto argument to Interface.Run (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: rename test helper 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/datastore/datastore_test.go ('k') | service/datastore/raw_interface.go » ('j') | 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 datastore 5 package datastore
6 6
7 import ( 7 import (
8 "golang.org/x/net/context" 8 "golang.org/x/net/context"
9 ) 9 )
10 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
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 // Interface is the 'user-friendly' interface to access the current filtered 11 // Interface is the 'user-friendly' interface to access the current filtered
20 // datastore service implementation. 12 // datastore service implementation.
21 // 13 //
22 // Note that in exchange for userfriendliness, this interface ends up doing 14 // Note that in exchange for userfriendliness, this interface ends up doing
23 // a lot of reflection. 15 // a lot of reflection.
24 // 16 //
25 // Methods taking 'interface{}' objects describe what a valid type for that 17 // Methods taking 'interface{}' objects describe what a valid type for that
26 // interface are in the comments. 18 // interface are in the comments.
27 // 19 //
28 // Struct objects passed in will be converted to PropertyLoadSaver interfaces 20 // Struct objects passed in will be converted to PropertyLoadSaver interfaces
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // datastore. 65 // datastore.
74 // 66 //
75 // Note that the behavior of transactions may change depending on what f ilters 67 // Note that the behavior of transactions may change depending on what f ilters
76 // have been installed. It's possible that we'll end up implementing thi ngs 68 // have been installed. It's possible that we'll end up implementing thi ngs
77 // like nested/buffered transactions as filters. 69 // like nested/buffered transactions as filters.
78 RunInTransaction(f func(c context.Context) error, opts *TransactionOptio ns) error 70 RunInTransaction(f func(c context.Context) error, opts *TransactionOptio ns) error
79 71
80 // Run executes the given query, and calls `cb` for each successfully 72 // Run executes the given query, and calls `cb` for each successfully
81 // retrieved item. 73 // retrieved item.
82 // 74 //
83 » // proto is a prototype of the objects which will be passed to the callb ack. 75 » // cb is a callback function whose signature is
84 » // It will be used solely for type information, and the actual proto obj ect 76 » // func(obj TYPE, getCursor CursorCB) bool
85 » // may be zero/nil. It must be of the form: 77 » //
78 » // Where TYPE is one of:
86 // - S or *S where S is a struct 79 // - S or *S where S is a struct
87 // - P or *P where *P is a concrete type implementing PropertyLoadSave r 80 // - P or *P where *P is a concrete type implementing PropertyLoadSave r
88 » // - *Key implies a keys-only query (and cb will be invoked with Key o bjects) 81 » // - Key (implies a keys-only query)
89 » // Run will create a new, populated instance of proto for each call of 82 » //
90 » // cb. Run stops on the first error encountered. 83 » // Run stops on the first error encountered.
91 » Run(q Query, proto interface{}, cb RunCB) error 84 » Run(q Query, cb interface{}) error
92 85
93 // GetAll retrieves all of the Query results into dst. 86 // GetAll retrieves all of the Query results into dst.
94 // 87 //
95 // dst must be one of: 88 // dst must be one of:
96 // - *[]S or *[]*S where S is a struct 89 // - *[]S or *[]*S where S is a struct
97 // - *[]P or *[]*P where *P is a concrete type implementing PropertyLo adSaver 90 // - *[]P or *[]*P where *P is a concrete type implementing PropertyLo adSaver
98 // - *[]Key implies a keys-only query. 91 // - *[]Key implies a keys-only query.
99 GetAll(q Query, dst interface{}) error 92 GetAll(q Query, dst interface{}) error
100 93
101 // Get retrieves a single object from the datastore 94 // Get retrieves a single object from the datastore
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 PutMulti(src interface{}) error 134 PutMulti(src interface{}) error
142 135
143 // DeleteMulti removes items from the datastore. 136 // DeleteMulti removes items from the datastore.
144 DeleteMulti(keys []Key) error 137 DeleteMulti(keys []Key) error
145 138
146 // Raw returns the underlying RawInterface. The Interface and RawInterfa ce may 139 // Raw returns the underlying RawInterface. The Interface and RawInterfa ce may
147 // be used interchangably; there's no danger of interleaving access to t he 140 // be used interchangably; there's no danger of interleaving access to t he
148 // datastore via the two. 141 // datastore via the two.
149 Raw() RawInterface 142 Raw() RawInterface
150 } 143 }
OLDNEW
« no previous file with comments | « service/datastore/datastore_test.go ('k') | service/datastore/raw_interface.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698