MCPcopy Create free account
hub / github.com/google/go-cloud / ExampleQuery_Get_full

Function ExampleQuery_Get_full

docstore/example_test.go:196–234  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

194}
195
196func ExampleQuery_Get_full() {
197 ctx := context.Background()
198 coll, err := memdocstore.OpenCollection("Name", nil)
199 if err != nil {
200 log.Fatal(err)
201 }
202 defer coll.Close()
203
204 // Add some documents to the collection.
205 err = coll.Actions().
206 Put(&Player{Name: "Pat", Score: 10}).
207 Put(&Player{Name: "Mel", Score: 20}).
208 Put(&Player{Name: "Fran", Score: 30}).
209 Do(ctx)
210 if err != nil {
211 log.Fatal(err)
212 }
213
214 // Ask for all players with scores at least 20.
215 iter := coll.Query().Where("Score", ">=", 20).OrderBy("Score", docstore.Descending).Get(ctx)
216 defer iter.Stop()
217
218 // Query.Get returns an iterator. Call Next on it until io.EOF.
219 for {
220 var p Player
221 err := iter.Next(ctx, &p)
222 if err == io.EOF {
223 break
224 } else if err != nil {
225 log.Fatal(err)
226 } else {
227 fmt.Printf("%s: %d\n", p.Name, p.Score)
228 }
229 }
230
231 // Output:
232 // Fran: 30
233 // Mel: 20
234}
235
236func Example_optimisticLocking() {
237 // PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored.

Callers

nothing calls this directly

Calls 11

OpenCollectionFunction · 0.92
DoMethod · 0.80
ActionsMethod · 0.80
OrderByMethod · 0.80
WhereMethod · 0.80
QueryMethod · 0.80
CloseMethod · 0.65
StopMethod · 0.65
NextMethod · 0.65
PutMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected