import { PostgreSQLAdapter } from "../base.js"; import type { Controller, TableNames } from "../base.js"; import type { Pool, Client } from "pg"; export class NodePostgresAdapter extends PostgreSQLAdapter { constructor(client: Client | Pool, tableNames: TableNames) { super(new NodePostgresController(client), tableNames); } } class NodePostgresController implements Controller { private client: Client | Pool; constructor(client: Client | Pool) { this.client = client; } public async get(sql: string, args: any[]): Promise { const { rows } = await this.client.query(sql, args); return rows.at(0) ?? null; } public async getAll(sql: string, args: any[]): Promise { const { rows } = await this.client.query(sql, args); return rows; } public async execute(sql: string, args: any[]): Promise { await this.client.query(sql, args); } }