method

bun.ReservedSQL.reserve

options?: { signal: AbortSignal }
): Promise<ReservedSQL>;

Reserves a connection from the pool and returns a client that wraps that single connection. Use it to run queries on an isolated connection.

Calling reserve() on a reserved client returns a new reserved connection, not the same one (behavior matches the postgres package).

@param options

signal aborts the reservation while it is still waiting for a connection; the returned promise rejects with signal.reason and no connection is taken from the pool. Aborting after the promise resolved has no effect: the caller owns the connection and must release() it.

Rejects if the adapter does not support connection pooling (SQLite).

const reserved = await sql.reserve();
await reserved`select * from users`;
await reserved.release();

// In production, release in a finally block
const reserved = await sql.reserve();
try {
  // ... queries
} finally {
  await reserved.release();
}

// Bun supports Symbol.dispose and Symbol.asyncDispose,
// so `using` releases the connection at the end of the scope
using reserved = await sql.reserve()
await reserved`select * from users`

// Give up on the reservation if no connection frees up in time
const reserved = await sql.reserve({ signal: AbortSignal.timeout(5000) });