25 lines
561 B
JavaScript
25 lines
561 B
JavaScript
import pg from 'pg';
|
|
import { readFile } from 'fs/promises';
|
|
import { fileURLToPath } from 'url';
|
|
import { dirname, join } from 'path';
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
|
const pool = new pg.Pool({
|
|
connectionString: process.env.KUA_CASHIER_DB_URL,
|
|
max: 10,
|
|
});
|
|
|
|
export async function migrate() {
|
|
const sql = await readFile(join(__dirname, 'migrations/001_initial.sql'), 'utf-8');
|
|
await pool.query(sql);
|
|
}
|
|
|
|
export function query(text, params) {
|
|
return pool.query(text, params);
|
|
}
|
|
|
|
export function getPool() {
|
|
return pool;
|
|
}
|