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

Method Where

docstore/query.go:43–65  ·  view source on GitHub ↗

Where expresses a condition on the query. Valid ops are: "=", ">", "<", ">=", "<=, "in", "not-in". Valid values are strings, integers, floating-point numbers, time.Time and boolean (only for "=", "in" and "not-in") values.

(fp FieldPath, op string, value any)

Source from the content-addressed store, hash-verified

41// Valid ops are: "=", ">", "<", ">=", "<=, "in", "not-in".
42// Valid values are strings, integers, floating-point numbers, time.Time and boolean (only for "=", "in" and "not-in") values.
43func (q *Query) Where(fp FieldPath, op string, value any) *Query {
44 if q.err != nil {
45 return q
46 }
47 pfp, err := parseFieldPath(fp)
48 if err != nil {
49 q.err = err
50 return q
51 }
52 validator, ok := validOp[op]
53 if !ok {
54 return q.invalidf("invalid filter operator: %q. Use one of: =, >, <, >=, <=, in, not-in", op)
55 }
56 if !validator(value) {
57 return q.invalidf("invalid filter value: %v", value)
58 }
59 q.dq.Filters = append(q.dq.Filters, driver.Filter{
60 FieldPath: pfp,
61 Op: op,
62 Value: value,
63 })
64 return q
65}
66
67type valueValidator func(any) bool
68

Callers 13

TestQueryValidFilterFunction · 0.95
ExecuteMethod · 0.80
ExecuteMethod · 0.80
TestInvalidQueryFunction · 0.80
ExampleQuery_GetFunction · 0.80
ExampleQuery_Get_fullFunction · 0.80
TestQueryNestedFunction · 0.80
TestQueryErrorsFunction · 0.80
testGetQueryKeyFieldFunction · 0.80
testGetQueryFunction · 0.80
testExampleInDocFunction · 0.80
testAsFunction · 0.80

Calls 2

invalidfMethod · 0.95
parseFieldPathFunction · 0.85

Tested by 7

TestQueryValidFilterFunction · 0.76
TestInvalidQueryFunction · 0.64
ExampleQuery_GetFunction · 0.64
ExampleQuery_Get_fullFunction · 0.64
TestQueryNestedFunction · 0.64
TestQueryErrorsFunction · 0.64
TestLowercaseFieldsFunction · 0.64