Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Drizzle ORM · Function

or

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.

How it works

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().

Syntax

or(...conditions)

Parameters

NameTypeDescription
conditionsSQL expressionsOne or more Drizzle filter expressions to combine with logical OR.

Returns

A composable SQL condition representing the logical OR of the supplied filter expressions.

Key points

  • Use or as a condition supplied to .where() when selecting rows.
  • The condition is intended for SQL-like, type-safe query composition.
  • Drizzle’s filter operators are represented as SQL expressions.
  • The built-in filter set can be extended with custom SQL-based operators.

Common mistakes

  • Use the resulting expression as a .where() filter; it is not a standalone query.
  • The documented filter operators are SQL-backed expressions, so compose them as query conditions rather than ordinary JavaScript booleans.

Example: Combine alternative filters

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.

When to use it

Alternative predicates

A query should match any of several permitted roles, statuses, or categories.

Nested logical filters

A reusable filter needs to be combined with a mandatory condition using and.

Custom SQL filters

The required filtering behavior is not covered by a built-in operator.

Interview questions

QWhat does Drizzle ORM’s 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'))).

QWhen would you use 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().

QHow does 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.

  • and
  • eq
  • sql
  • .where()

Source: SQL Select - Drizzle ORM. Checked 2026-10-16.