bsfe_server/src/db.js

28 lines
668 B
JavaScript
Raw Normal View History

2024-10-26 05:31:22 +03:00
import pg from 'pg';
import log from './utils/log.js'
import fs from 'fs'
import config from '../config.json' with {type: "json"};
const { Pool } = pg;
log.debug(
`Connecting to PG database ${config.dbname}@${config.dbhost}:${config.dbport} with credentials:
2024-10-26 05:31:22 +03:00
username: ${config.dbuser}
password: <hidden>`
);
const pool = new Pool({
user: config.dbuser,
host: config.dbhost,
port: config.dbport,
database: config.dbname,
password: config.dbpassword
});
log.debug("Database connection successfull. Creating tables");
2024-10-26 05:31:22 +03:00
pool.query(fs.readFileSync('./db_schema.psql').toString());
log.debug("Tables succesfully created");
export default pool;