kysely-prisma-postgres
Version:
Prisma Postgres (PPG) dialect for Kysely
84 lines (80 loc) • 1.77 kB
JavaScript
// src/dialect.mts
import {
PostgresAdapter,
PostgresIntrospector,
PostgresQueryCompiler
} from "kysely";
// src/driver.mts
var PPGDriver = class {
#config;
#connection;
constructor(config) {
this.#config = config;
}
async acquireConnection() {
return this.#connection;
}
beginTransaction(_connection, _settings) {
throw new Error("PPGDialect doesn't support interactive transactions.");
}
async commitTransaction(_connection) {
}
async destroy() {
}
async init() {
const { ppg } = this.#config;
this.#connection ||= new PPGDatabaseConnection(
isPPGSql(ppg) ? ppg : await ppg()
);
}
async releaseConnection(_connection) {
}
async rollbackTransaction(_connection) {
}
};
function isPPGSql(thing) {
return typeof thing === "function" && "query" in thing;
}
var PPGDatabaseConnection = class {
#ppg;
constructor(ppg) {
this.#ppg = ppg;
}
async executeQuery(compiledQuery) {
const result = await this.#ppg.query(compiledQuery.sql, [
...compiledQuery.parameters
]);
return { rows: result };
}
streamQuery(_compiledQuery, _chunkSize) {
throw new Error("PPGDialect doesn't support streaming.");
}
};
// src/utils.mts
function freeze(obj) {
return Object.freeze(obj);
}
// src/dialect.mts
var PPGDialect = class {
#config;
constructor(config) {
this.#config = freeze({ ...config });
}
createAdapter() {
return new PostgresAdapter();
}
createDriver() {
return new PPGDriver(this.#config);
}
// biome-ignore lint/suspicious/noExplicitAny: this is fine.
createIntrospector(db) {
return new PostgresIntrospector(db);
}
createQueryCompiler() {
return new PostgresQueryCompiler();
}
};
export {
PPGDialect,
PPGDriver
};