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(
|
2024-10-27 04:45:13 +03:00
|
|
|
`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
|
|
|
|
});
|
|
|
|
|
2024-10-27 04:45:13 +03:00
|
|
|
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;
|