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

Function ExampleQuery_Get

docstore/example_test.go:172–194  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

170}
171
172func ExampleQuery_Get() {
173 // PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored.
174 // PRAGMA: On gocloud.dev, hide lines until the next blank line.
175 ctx := context.Background()
176 var coll *docstore.Collection
177
178 // Ask for all players with scores at least 20.
179 iter := coll.Query().Where("Score", ">=", 20).OrderBy("Score", docstore.Descending).Get(ctx)
180 defer iter.Stop()
181
182 // Query.Get returns an iterator. Call Next on it until io.EOF.
183 for {
184 var p Player
185 err := iter.Next(ctx, &p)
186 if err == io.EOF {
187 break
188 } else if err != nil {
189 log.Fatal(err)
190 } else {
191 fmt.Printf("%s: %d\n", p.Name, p.Score)
192 }
193 }
194}
195
196func ExampleQuery_Get_full() {
197 ctx := context.Background()

Callers

nothing calls this directly

Calls 6

QueryMethod · 0.95
OrderByMethod · 0.80
WhereMethod · 0.80
StopMethod · 0.65
NextMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected