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)
| 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. |
| 43 | func (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 | |
| 67 | type valueValidator func(any) bool |
| 68 |