import "../types/pg.js";
import { READ_COMMITTED } from "./mode-enum.js";
const IDLE_IN_TRANSACTION_SESSION_TIMEOUT_MS = parseInt(
  process.env.ZERO_IDLE_IN_TRANSACTION_SESSION_TIMEOUT ?? "60000"
);
function runTx(db, fn, opts = {}) {
  const {
    // Explicitly default to the Postgres default to override any custom
    // `default_transaction_isolation`.
    mode = READ_COMMITTED
  } = opts;
  return db.begin(mode, (sql) => {
    void sql`SET LOCAL statement_timeout = 0;`.execute();
    void sql.unsafe(
      /*sql*/
      `SET LOCAL idle_in_transaction_session_timeout = ${IDLE_IN_TRANSACTION_SESSION_TIMEOUT_MS}`
    ).execute();
    return fn(sql);
  });
}
export {
  runTx
};
//# sourceMappingURL=run-transaction.js.map
