UNPKG

longcelot-sheet-db

Version:

Google Sheets-backed staging database adapter for Node.js with schema-first design

37 lines 1.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createPostgresAdapter = createPostgresAdapter; const dialect_1 = require("./dialect"); const sqlAdapterBase_1 = require("./sqlAdapterBase"); const lazyRequireDriver_1 = require("./lazyRequireDriver"); const resolvePostgresSSL_1 = require("./resolvePostgresSSL"); class PgConnection { constructor(pool) { this.pool = pool; } async query(text, params) { const result = await this.pool.query(text, params); return { rows: result.rows }; } } /** * `pg` is an optional peer dependency, lazy-required only here so `import { createSheetAdapter } * from 'longcelot-sheet-db'` never pulls it in transitively for consumers who only use Sheets * (Phase 16.2). Throws a clear SchemaError — not a raw module-not-found — when it's missing. */ function createPostgresAdapter(config) { let pool; if (config.pool) { pool = config.pool; } else { const pgModule = (0, lazyRequireDriver_1.lazyRequireDriver)('pg', 'pg', 'createPostgresAdapter()'); const connectionString = config.connectionString ?? process.env.DATABASE_URL; pool = new pgModule.Pool({ connectionString, ssl: (0, resolvePostgresSSL_1.resolvePostgresSSL)(connectionString, config.ssl) }); } return new sqlAdapterBase_1.SQLAdapterBase(new PgConnection(pool), dialect_1.PostgresDialect, { tenantColumn: config.tenantColumn, permissions: config.permissions, }); } //# sourceMappingURL=postgresAdapter.js.map