flame/db.js
2021-06-22 14:49:00 +02:00

32 lines
No EOL
728 B
JavaScript

const { Sequelize } = require('sequelize');
const Logger = require('./utils/Logger');
const logger = new Logger();
const sequelize = new Sequelize({
dialect: 'sqlite',
storage: './data/db.sqlite',
logging: false
})
const connectDB = async () => {
try {
await sequelize.authenticate();
logger.log('Connected to database');
const syncModels = false;
if (syncModels) {
logger.log('Starting model synchronization');
await sequelize.sync({ alter: true });
logger.log('All models were synchronized');
}
} catch (error) {
logger.log(`Unable to connect to the database: ${error.message}`, 'ERROR');
process.exit(1);
}
}
module.exports = {
connectDB,
sequelize
}