mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-11-18 13:00:58 -05:00
26 lines
870 B
TypeScript
26 lines
870 B
TypeScript
|
import {Sequelize} from 'sequelize';
|
||
|
import Logger from '../helpers/Logger.js';
|
||
|
import TSClient from '../helpers/TSClient.js';
|
||
|
|
||
|
const postgresUri = (await TSClient()).postgres_uri;
|
||
|
export default class DatabaseServer {
|
||
|
public static seq:Sequelize = new Sequelize(postgresUri, {dialect: 'postgres', logging: false, ssl: false})
|
||
|
public static async init() {
|
||
|
try {
|
||
|
await this.seq.authenticate();
|
||
|
this.healthCheck();
|
||
|
} catch {
|
||
|
Logger.console('error', 'Database', 'Cannot initialize Sequelize -- is PostgreSQL running?');
|
||
|
process.exit(1);
|
||
|
}
|
||
|
}
|
||
|
private static async healthCheck() {
|
||
|
try {
|
||
|
await this.seq.query('SELECT 1');
|
||
|
Logger.console('log', 'Database', 'Connection to PostgreSQL has been established');
|
||
|
} catch {
|
||
|
Logger.console('error', 'Database', 'Connection to PostgreSQL has been lost');
|
||
|
}
|
||
|
}
|
||
|
}
|