Files
publisher-dashboard/packages/db/src/client.ts
RevIQ 2c2556a5ea Add e2e tests for me.* procedures and fix code review issues
- Add comprehensive e2e tests for me.get, me.authStatus, me.setupProfile,
  me.updateProfile, me.setPassword, and me.delete (21 tests)
- Make createDb require explicit connection string (no default env lookup)
- Add database name validation to prevent SQL injection in CREATE DATABASE
- Fix getTestDatabaseUrl to throw instead of returning empty string
- Replace brittle relative path with findRepoRoot() function
- Extract magic numbers (SESSION_EXPIRY_MS, API_TOKEN_EXPIRY_MS, ONE_DAY_MS)
- Consolidate duplicate createAPIContext functions
- Add hasPassword field to meAuthStatus and toUserResponse

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 15:24:42 +08:00

35 lines
729 B
TypeScript

/**
* Kysely database client
*
* @module @reviq/db
*/
import type { Database } from "@reviq/db-schema";
import { Kysely, PostgresDialect } from "kysely";
import pg from "pg";
const { Pool } = pg;
/**
* Creates a new Kysely database client
*
* @param connectionString - PostgreSQL connection string (required)
* @returns Kysely database instance
* @throws Error if connectionString is empty
*/
export const createDb = (connectionString: string): Kysely<Database> => {
if (!connectionString) {
throw new Error("Database connection string is required");
}
const dialect = new PostgresDialect({
pool: new Pool({
connectionString,
}),
});
return new Kysely<Database>({
dialect,
});
};