UNPKG

npxbase

Version:

A professional and modular database management library for Node.js with support for MySQL, PostgreSQL, and MongoDB.

28 lines (22 loc) 594 B
const { Pool } = require("pg"); class PostgresAdapter { constructor() { this.pool = null; } async connect(config) { this.pool = new Pool(config); console.log("Connected to PostgreSQL"); } async disconnect() { if (this.pool) { await this.pool.end(); console.log("Disconnected from PostgreSQL"); } } async query(sql, params) { if (!this.pool) throw new Error("No active PostgreSQL connection"); const result = await this.pool.query(sql, params); return result.rows; } } module.exports = PostgresAdapter;