Querying

Filters

The where model — scalar operators, logical combinators, null handling, and dropping to raw Drizzle SQL.

where is shared by every read, count, exists, update, delete, and upsert. It is typed against your table's columns and relations.

Equality shorthand

The simplest filter is a direct value — it means "equals":

await client.users.findMany({
	where: { active: true, name: 'Alice' },
});

That is identical to the explicit form:

await client.users.findMany({
	where: { active: { equals: true } },
});

Multiple keys are combined with AND.

String filters

String columns accept equality, membership, and pattern operators:

await client.users.findMany({
	where: {
		name: { contains: 'ali', mode: 'insensitive' },
		email: { endsWith: '@example.com' },
	},
});
OperatorMeaning
equalsexact match
in / notInvalue is (not) in a list
containssubstring match
startsWith / endsWithprefix / suffix match
mode'default' (case-sensitive) or 'insensitive'
notnegate a value or a nested filter

Numeric and date filters

Numbers, bigints, and dates accept range comparisons:

await client.users.findMany({
	where: {
		id: { gte: 100, lte: 200 },
	},
});
OperatorMeaning
equalsexact match
in / notInvalue is (not) in a list
lt / lteless than / less than or equal
gt / gtegreater than / greater than or equal
notnegate a value or a nested filter

Boolean filters

await client.users.findMany({
	where: { active: { equals: true } },
});

Boolean columns support equals and not.

Null and negation

Nullable columns accept null directly, and any operator can be negated with not:

await client.posts.findMany({
	where: {
		deletedAt: null, // IS NULL
		title: { not: { contains: 'draft' } },
	},
});

Logical operators

Combine conditions with AND, OR, and NOT. They nest arbitrarily:

await client.users.findMany({
	where: {
		AND: [
			{ active: true },
			{
				OR: [
					{ email: { endsWith: '@company.com' } },
					{ name: { startsWith: 'Admin' } },
				],
			},
		],
	},
});

Top-level keys are already AND-ed

You only need explicit AND when you want to group an OR next to other conditions, or to express the same condition on a field twice.

Filtering by relations

where also reaches across relations with some / every / none (to-many) and is / isNot (to-one). That has its own page:

Dropping to raw Drizzle SQL

When you need an expression the structured filter does not model, pass a Drizzle SQL fragment straight into where:

import { eq } from 'drizzle-orm';
import { users } from './schema';

const user = await client.users.findFirst({
	where: eq(users.id, 1),
});

Anything that produces a Drizzle SQL / SQLWrapper is accepted, so you keep the full expressive power of Drizzle for the cases that need it.

On this page