30 lines
702 B
TypeScript
30 lines
702 B
TypeScript
import { Kysely, PostgresDialect } from "kysely";
|
|
import { Pool } from "pg";
|
|
import type { DB } from "../../generated/db";
|
|
import { connectionConfig } from "../database";
|
|
|
|
const db = new Kysely<DB>({
|
|
dialect: new PostgresDialect({
|
|
pool: new Pool(connectionConfig),
|
|
}),
|
|
log(event) {
|
|
if (event.level === "query") {
|
|
// FIXME: Wire this up to the logging system
|
|
console.log("SQL:", event.query.sql);
|
|
console.log("Params:", event.query.parameters);
|
|
}
|
|
},
|
|
});
|
|
|
|
abstract class Hydrator<T> {
|
|
public db: Kysely<DB>;
|
|
|
|
protected abstract table: string;
|
|
|
|
constructor() {
|
|
this.db = db;
|
|
}
|
|
}
|
|
|
|
export { Hydrator, db };
|