Add test infrastructure for hydrators using node:test
- Add docker-compose.test.yml with isolated PostgreSQL on port 5433 - Add environment variable support for database connection config - Add test setup utilities and initial user hydrator tests - Add test and test:watch scripts to package.json Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
29
express/framework/hydrators/hydrator.ts
Normal file
29
express/framework/hydrators/hydrator.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Kysely, PostgresDialect } from "kysely";
|
||||
import { Pool } from "pg";
|
||||
import { connectionConfig } from "../../database";
|
||||
import type { DB } from "../../generated/db";
|
||||
|
||||
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 };
|
||||
Reference in New Issue
Block a user