Reduce request overhead
Combine related reads and writes into one database request.
Drizzle ORM · Module
db.batch runs multiple supported Drizzle query builders as one batch with the Neon HTTP PostgreSQL driver. The typed response preserves the input order.
db.batch accepts an array of supported Drizzle query builders and returns a tuple whose entries correspond positionally to those builders. The documented Batch API covers the Neon HTTP PostgreSQL driver and supports relational queries, selects, inserts, updates, and deletes.
await db.batch([queryBuilder, ...queryBuilders])| Name | Type | Description |
|---|---|---|
queries | QueryBuilder[] | An array of supported Drizzle query builders, including relational queries, selects, updates, deletes, and inserts. |
A typed tuple of results corresponding to the supplied builders in the same order.
db.batch with an array of query builders and await its result.findMany queries are valid members of the batch.findFirst queries are also listed as supported.import { drizzle } from 'drizzle-orm/neon-http';
import { eq } from 'drizzle-orm';
import { usersTable } from './schema';
const db = drizzle(process.env.DATABASE_URL!);
const [inserted, updated, users] = await db.batch([
db.insert(usersTable).values({ id: 1, name: 'John' }).returning({ id: usersTable.id }),
db.update(usersTable).set({ name: 'Dan' }).where(eq(usersTable.id, 1)),
db.query.usersTable.findMany({}),
]);
console.log(inserted, updated, users);This sends supported query builders in one batch and receives results in the same order.
Combine related reads and writes into one database request.
Collect insert, update, and query results from a single call.
Use Drizzle's inferred result types for positional batch responses.
db.batch return?db.batch takes an array of supported query builders and executes them as a batch. Its result is typed as a tuple, so each returned value matches the corresponding statement's position and result shape.
Follow-up: How would you associate a result with a statement? Use the array position: the first result belongs to the first builder, the second to the second, and so on.
The page documents db.query.<table>.findMany(), findFirst(), select builders, update, delete, and insert builders as valid batch members. These statements can be mixed in one batch.
Follow-up: Can an arbitrary promise be passed? The page only establishes the listed builder categories, so an arbitrary promise should not be treated as supported.
The page presents Batch API usage with the Neon HTTP driver for PostgreSQL. A batch is supplied as an array, and the response preserves the statements' order through its tuple type.
Follow-up: What should be checked before using this with another driver? Consult that driver's own official documentation, because this page's stated scope is Neon HTTP PostgreSQL.
db.query.<table>.findMany()db.query.<table>.findFirst()db.select()db.update()db.delete()db.insert()