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

Method Filter

datastore/query.go:138–166  ·  view source on GitHub ↗

Filter returns a derivative query with a field-based filter. The filterStr argument must be a field name followed by optional space, followed by an operator, one of ">", "<", ">=", "<=", or "=". Fields are compared against the provided value using the operator. Multiple filters are AND'ed together.

(filterStr string, value interface{})

Source from the content-addressed store, hash-verified

136// Fields are compared against the provided value using the operator.
137// Multiple filters are AND'ed together.
138func (q *Query) Filter(filterStr string, value interface{}) *Query {
139 q = q.clone()
140 filterStr = strings.TrimSpace(filterStr)
141 if len(filterStr) < 1 {
142 q.err = errors.New("datastore: invalid filter: " + filterStr)
143 return q
144 }
145 f := filter{
146 FieldName: strings.TrimRight(filterStr, " ><=!"),
147 Value: value,
148 }
149 switch op := strings.TrimSpace(filterStr[len(f.FieldName):]); op {
150 case "<=":
151 f.Op = lessEq
152 case ">=":
153 f.Op = greaterEq
154 case "<":
155 f.Op = lessThan
156 case ">":
157 f.Op = greaterThan
158 case "=":
159 f.Op = equal
160 default:
161 q.err = fmt.Errorf("datastore: invalid operator %q in filter %q", op, filterStr)
162 return q
163 }
164 q.filter = append(q.filter, f)
165 return q
166}
167
168// Order returns a derivative query with a field-based sort order. Orders are
169// applied in the order they are added. The default order is ascending; to sort

Callers 4

TestQueryConstructionFunction · 0.45
TestFilterParserFunction · 0.45
TestQueryToProtoFunction · 0.45
AllocateIDRangeFunction · 0.45

Calls 1

cloneMethod · 0.95

Tested by 3

TestQueryConstructionFunction · 0.36
TestFilterParserFunction · 0.36
TestQueryToProtoFunction · 0.36