bsfe_server/src/db.js

28 lines
669 B
JavaScript
Raw Normal View History

2024-10-26 05:31:22 +03:00
import pg from 'pg';
import log from './utils/log.js'
2024-10-28 17:17:47 +03:00
import fs from 'fs';
2024-10-26 05:31:22 +03:00
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;