feat: version 2 beta

This commit is contained in:
2025-04-25 22:39:47 +00:00
commit 1e58359905
75 changed files with 6899 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
import postgres, { type Sql } from "postgres";
import { PostgresConnection } from "./connection.ts";
export class PostgresDatabase {
readonly #connection: PostgresConnection;
#sql?: Sql;
constructor(connection: PostgresConnection) {
this.#connection = connection;
}
get sql(): Sql {
if (this.#sql === undefined) {
const connection = this.#connection;
if (Array.isArray(connection)) {
const [urlOrOptions, option] = connection;
if (typeof urlOrOptions === "string") {
this.#sql = postgres(urlOrOptions, option);
} else {
this.#sql = postgres(urlOrOptions);
}
} else if ("options" in connection) {
this.#sql = connection;
} else {
this.#sql = connection();
}
}
return this.#sql;
}
}
export type DatabaseAccessor = {
sql: Sql;
};