MCPcopy Create free account
hub / github.com/golang/appengine / Order

Method Order

v2/datastore/query.go:171–191  ·  view source on GitHub ↗

Order returns a derivative query with a field-based sort order. Orders are applied in the order they are added. The default order is ascending; to sort in descending order prefix the fieldName with a minus sign (-).

(fieldName string)

Source from the content-addressed store, hash-verified

169// applied in the order they are added. The default order is ascending; to sort
170// in descending order prefix the fieldName with a minus sign (-).
171func (q *Query) Order(fieldName string) *Query {
172 q = q.clone()
173 fieldName = strings.TrimSpace(fieldName)
174 o := order{
175 Direction: ascending,
176 FieldName: fieldName,
177 }
178 if strings.HasPrefix(fieldName, "-") {
179 o.Direction = descending
180 o.FieldName = strings.TrimSpace(fieldName[1:])
181 } else if strings.HasPrefix(fieldName, "+") {
182 q.err = fmt.Errorf("datastore: invalid order: %q", fieldName)
183 return q
184 }
185 if len(o.FieldName) == 0 {
186 q.err = errors.New("datastore: empty order")
187 return q
188 }
189 q.order = append(q.order, o)
190 return q
191}
192
193// Project returns a derivative query that yields only the given fields. It
194// cannot be used with KeysOnly.

Callers 3

TestQueriesAreImmutableFunction · 0.95
TestQueryConstructionFunction · 0.45
TestQueryToProtoFunction · 0.45

Calls 1

cloneMethod · 0.95

Tested by 3

TestQueriesAreImmutableFunction · 0.76
TestQueryConstructionFunction · 0.36
TestQueryToProtoFunction · 0.36