List records
Retrieve a collection of table records for a list or API response.
Drizzle ORM · Module
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.
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.
await db.query.<table>.findMany(config?)| Name | Type | Description |
|---|---|---|
config | FindManyConfig | Optional relational-query configuration, including columns, with, where, orderBy, limit, and offset. |
A promise resolving to an array of typed records whose fields and nested relations match the query configuration.
findMany when the expected result is a collection; use findFirst when the query should return one matching record.db.query.with to include related records and receive nested, aggregated objects in the result.db.query cannot use the schema relationships.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.
Retrieve a collection of table records for a list or API response.
Return only the fields needed by a screen or endpoint.
Fetch parent rows together with declared child relations.
Apply filtering and pagination to a collection query.
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.
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.
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.
findFirstdb.querywithcolumnswhereorderBylimitoffset