Predicates are type-safe conditions used to filter records in select, update, upsert and delete. They are built from the Fields namespace generated by the @SurrealModel macro.
Comparison operators
Each field supports the standard comparison operators:
Person.Fields.name == "Ada"
Person.Fields.name != "Bob"
Person.Fields.age > 18
Person.Fields.age >= 21
Person.Fields.age < 65
Person.Fields.age <= 60Combining predicates
Combine predicates with the logical operators &&, || and !:
let combined = Person.Fields.age >= 18 && Person.Fields.published == true
let either = Person.Fields.age < 18 || Person.Fields.name == "Admin"
let negated = !(Person.Fields.published == false)Raw predicates
When you need an expression that the DSL does not cover, or when using a manually conformed model without a Fields namespace, you can supply a raw SurrealQL condition:
let raw = SurrealPredicate(raw: "age > 18 AND name != 'Bot'")Using a predicate
Pass a predicate to any method that accepts a where: argument:
let adults = try await client.select(
Person.self,
where: Person.Fields.age >= 18,
limit: 20,
start: 0
)