@earth-app/collegedb
    Preparing search index...

    Interface SQLBatchOptions<C>

    Controls whether an adapter may run a SQLDatabase.runBatch group inside one transaction, and on which connection.

    A transaction is only correct when every statement in it, BEGIN and COMMIT included, travels down the same connection. A pool does not guarantee that, and a pool cannot be told apart from a single connection by inspection: pg's Client and Pool both expose connect(), and any of them can be wrapped in something that exposes only query(). So the adapter never guesses. It batches when it recognizes a pool it knows how to lease from, when you hand it a SQLBatchOptions.lease of your own, or when you state that the handle is a single connection. Otherwise statements run one at a time, exactly as before.

    A single connection runs one transaction at a time. While a batch is open, every other statement on that connection waits until it commits or rolls back, and two batches run one after the other, so one slow batch delays every other request that shares the connection. Use a pool when requests need to run concurrently: a pool leases one connection per batch and never waits.

    1.3.0

    interface SQLBatchOptions<C = unknown> {
        lease?: () => Promise<LeasedConnection<C>>;
        singleConnection?: boolean;
    }

    Type Parameters

    • C = unknown
    Index
    lease?: () => Promise<LeasedConnection<C>>

    Leases a dedicated connection for one batch. Takes precedence over SQLBatchOptions.singleConnection and over pool autodetection, and is the escape hatch for a handle CollegeDB does not recognize.

    On its own, a lease adds no wait for plain statements, because the adapter cannot tell a pool from one shared connection. If the lease hands out one shared connection, also set singleConnection: true, or serialize the statements yourself.

    singleConnection?: boolean

    Declares that the handle is one dedicated connection, so BEGIN/COMMIT can be issued straight through it. Set this for a pg.Client, a mysql2 connection, or any SQLite handle. Do not set it for a pool.

    The adapter then holds every plain statement back while a batch is open, so none can run inside the batch's transaction. The wait is the cost: one slow batch delays every other statement on the connection. A pool avoids it.

    Combined with SQLBatchOptions.lease, the lease still supplies the batch's connection, and the wait applies to plain statements all the same.