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

Drizzle ORM · Module

.findMany

findMany retrieves multiple records through Drizzle’s relational Queries API. Configure its options to select fields, filter and paginate rows, and include typed nested relations.

How it works

Use db.query.<table>.findMany() to retrieve multiple rows through Drizzle’s relational Queries API. Its options can shape the result by selecting columns, filtering records, ordering them, limiting the count, and loading related records; the returned value is typed as an array matching that selection.

Syntax

await db.query.<table>.findMany(config?)

Parameters

NameTypeDescription
configFindManyConfigOptional relational-query configuration, including columns, with, where, orderBy, limit, and offset.

Returns

A promise resolving to an array of typed records whose fields and nested relations match the query configuration.

Key points

  • Use findMany when the expected result is a collection; use findFirst when the query should return one matching record.
  • The method belongs to Drizzle’s relational Queries API rather than the lower-level SQL-like query builder.
  • Configure the database instance with the schema tables and relations before calling db.query.
  • Use with to include related records and receive nested, aggregated objects in the result.

Common mistakes

  • Initialize Drizzle with the tables and relations needed by the relational query API; otherwise db.query cannot use the schema relationships.

Example: Fetch selected columns with findMany

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

const db = drizzle(process.env.DATABASE_URL!);
const rows = await db.query.users.findMany({
  columns: { id: true, name: true },
});
console.log(rows);

Fetches all users while selecting only their IDs and names.

When to use it

List records

Retrieve a collection of table records for a list or API response.

Project columns

Return only the fields needed by a screen or endpoint.

Load nested data

Fetch parent rows together with declared child relations.

Constrain results

Apply filtering and pagination to a collection query.

Interview questions

QWhat does findMany do?

findMany is the relational query method for retrieving multiple records from a table. It returns an array, and its result type follows the requested columns and relations.

Follow-up: How would you load child records? Pass a with option, such as with: { posts: true }, provided the relation is defined in the schema.

QHow is findMany accessed?

Call it through the relational query API as db.query.users.findMany(). The database instance must be initialized with the relevant schema tables and relations.

Follow-up: Why does relation configuration matter? The with option depends on declared relations to describe nested data and generate the relational query.

QHow can findMany shape relational results?

The method supports nested relational data through with, while the returned structure remains type-safe and reflects the selected shape. Drizzle’s Queries API handles relational fetching and data mapping for you.

Follow-up: How can you reduce the selected payload? Use columns to include or exclude fields, including distinct column selections inside nested relations.

  • findFirst
  • db.query
  • with
  • columns
  • where
  • orderBy
  • limit
  • offset

Source: Drizzle ORM - Query. Checked 2026-10-16.