import postgres from "postgres";
import { executePostgresQuery } from "../pg-query-executor.js";
import { ZQLDatabase } from "../zql-database.js";
class PostgresJSConnection {
  #pg;
  constructor(pg) {
    this.#pg = pg;
  }
  transaction(fn) {
    return this.#pg.begin(
      (pgTx) => fn(new PostgresJsTransactionInternal(pgTx))
    );
  }
}
class PostgresJsTransactionInternal {
  wrappedTransaction;
  constructor(pgTx) {
    this.wrappedTransaction = pgTx;
  }
  query(sql, params) {
    return this.wrappedTransaction.unsafe(sql, params);
  }
  runQuery(ast, format, schema, serverSchema) {
    return executePostgresQuery(
      this,
      ast,
      format,
      schema,
      serverSchema
    );
  }
}
function zeroPostgresJS(schema, pg) {
  if (typeof pg === "string") {
    pg = postgres(pg);
  }
  return new ZQLDatabase(new PostgresJSConnection(pg), schema);
}
export {
  PostgresJSConnection,
  PostgresJsTransactionInternal,
  zeroPostgresJS
};
//# sourceMappingURL=postgresjs.js.map
