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

Method OrderBy

docstore/query.go:173–189  ·  view source on GitHub ↗

OrderBy specifies that the returned documents appear sorted by the given field in the given direction. A query can have at most one OrderBy clause. If it has none, the order of returned documents is unspecified. If a query has a Where clause and an OrderBy clause, the OrderBy clause's field must app

(field, direction string)

Source from the content-addressed store, hash-verified

171// must appear in a Where clause.
172// It is an error to specify OrderBy in a Delete or Update query.
173func (q *Query) OrderBy(field, direction string) *Query {
174 if q.err != nil {
175 return q
176 }
177 if field == "" {
178 return q.invalidf("OrderBy: empty field")
179 }
180 if direction != Ascending && direction != Descending {
181 return q.invalidf("OrderBy: direction must be one of %q or %q", Ascending, Descending)
182 }
183 if q.dq.OrderByField != "" {
184 return q.invalidf("a query can have at most one OrderBy")
185 }
186 q.dq.OrderByField = field
187 q.dq.OrderAscending = (direction == Ascending)
188 return q
189}
190
191// BeforeQuery takes a callback function that will be called before the Query is
192// executed to the underlying service's query functionality. The callback takes

Callers 5

TestInvalidQueryFunction · 0.80
ExampleQuery_GetFunction · 0.80
ExampleQuery_Get_fullFunction · 0.80
testGetQueryFunction · 0.80
TestLowercaseFieldsFunction · 0.80

Calls 1

invalidfMethod · 0.95

Tested by 4

TestInvalidQueryFunction · 0.64
ExampleQuery_GetFunction · 0.64
ExampleQuery_Get_fullFunction · 0.64
TestLowercaseFieldsFunction · 0.64