UNPKG

@tmlmobilidade/connectors

Version:

This package provides pre-made database connectors to streamline development and reduce boilerplate. By using these connectors, you can avoid re-implementing controller classes every time, ensuring consistency and saving development time.

24 lines (23 loc) 568 B
/* * */ import { Client } from 'pg'; /* * */ export class PostgresConnector { client; constructor(config) { this.client = new Client({ connectionString: config.uri, ...config.options }); } /** * Connects to the PostgreSQL database. */ async connect() { await this.client.connect(); console.log('Connected to PostgreSQL.'); } /** * Disconnects from the PostgreSQL database. */ async disconnect() { await this.client.end(); console.log('Disconnected from PostgreSQL.'); } }