1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-11-18 08:50:59 -05:00
Daggerbot-TS/src/components/DatabaseServer.ts
2023-12-25 02:22:29 +11:00

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');
}
}
}