import { PostgreSQLAdapter } from "../base.js"; import type { Controller, TableNames } from "../base.js"; import type { NeonQueryFunction } from "@neondatabase/serverless"; export class NeonHTTPAdapter extends PostgreSQLAdapter { constructor(neon: NeonQueryFunction, tableNames: TableNames) { super(new NeonHTTPController(neon), tableNames); } } class NeonHTTPController implements Controller { private neon: NeonQueryFunction; constructor(neon: NeonQueryFunction) { this.neon = neon; } public async get(sql: string, args: any[]): Promise { const result = await this.neon(sql, args); if (Array.isArray(result)) { return (result.at(0) as T) ?? null; } return (result.rows.at(0) as T) ?? null; } public async getAll(sql: string, args: any[]): Promise { const result = await this.neon(sql, args); if (Array.isArray(result)) { return result as T[]; } return result.rows as T[]; } public async execute(sql: string, args: any[]): Promise { await this.neon(sql, args); } }