Skip to content

Where

Where clauses are declarative. They don’t use callbacks, they don’t generate SQL strings. Models describe metadata; they never execute logic.

where: {
active: true,
name: "Juan",
}
// → WHERE active = true AND name = 'Juan'
where: {
name: { contains: "john" },
age: { gte: 18 },
price: { lte: 100 },
id: { gte: 1, lte: 100 },
}
// → WHERE name LIKE '%john%' AND age >= 18 AND price <= 100 AND id BETWEEN 1 AND 100
where: {
status: ["active", "pending"],
}
// → WHERE status IN ('active', 'pending')
where: {
role: { name: "admin" },
}
// → WHERE ... role.name = 'admin'
where: {
active: true,
name: { contains: "john" },
role: { name: "admin" },
createdAt: { gte: new Date("2024-01-01") },
}
Operator SQL Description
(direct value) = Equality
contains LIKE Contains
gte >= Greater than or equal
lte <= Less than or equal
gt > Greater than
lt < Less than
ne != Not equal
in IN In list
eq = Explicit equality
startsWith LIKE '...%' Starts with
endsWith LIKE '%...' Ends with
isNull IS NULL Is null