Alternative predicates
A query should match any of several permitted roles, statuses, or categories.
Drizzle ORM · Function
or combines Drizzle filter expressions into a logical SQL OR condition. Use the result with query methods such as .where() to match rows satisfying at least one alternative.
or combines filter conditions into a SQL OR expression. Pass individual conditions or nested logical expressions, then use the returned expression in a query method such as .where().
or(...conditions)| Name | Type | Description |
|---|---|---|
conditions | SQL expressions | One or more Drizzle filter expressions to combine with logical OR. |
A composable SQL condition representing the logical OR of the supplied filter expressions.
or as a condition supplied to .where() when selecting rows..where() filter; it is not a standalone query.import { and, eq, or } from 'drizzle-orm';
const filter = or(
eq(users.role, 'admin'),
eq(users.role, 'editor'),
);
const rows = await db
.select()
.from(users)
.where(filter);Builds a reusable filter that matches users with either role.
A query should match any of several permitted roles, statuses, or categories.
A reusable filter needs to be combined with a mandatory condition using and.
The required filtering behavior is not covered by a built-in operator.
or function do?or creates a composable SQL condition representing logical OR between its supplied filter expressions. It is typically passed to .where() to restrict selected rows.
Follow-up: How would you combine two alternatives with a required condition? Nest or inside and, for example and(eq(users.active, true), or(eq(users.role, 'admin'), eq(users.role, 'editor'))).
or instead of separate queries?The function is useful when a row should satisfy at least one of several predicates. Each predicate remains a Drizzle filter expression and can be composed with other operators.
Follow-up: Can the alternatives be built conditionally? Yes: construct an array or expression from the available filters, while ensuring the resulting condition is valid before passing it to .where().
or fit Drizzle’s filter system?Use or inside a select query’s .where() clause to express alternatives in the generated SQL. This keeps the filtering type-safe and composable with Drizzle’s query builder.
Follow-up: What is the broader extension point for unsupported filters? The documentation says filters are implemented with sql, which can also be used to write arbitrary SQL filters or custom operators.
andeqsql.where()