1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-19 03:29:37 +02:00
flame/db.js

33 lines
725 B
JavaScript
Raw Normal View History

const { Sequelize } = require('sequelize');
2021-06-22 14:49:00 +02:00
const Logger = require('./utils/Logger');
const logger = new Logger();
const sequelize = new Sequelize({
dialect: 'sqlite',
2021-06-05 15:48:43 +02:00
storage: './data/db.sqlite',
2021-09-06 13:22:47 +02:00
logging: false,
2021-08-06 15:15:54 +02:00
});
const connectDB = async () => {
try {
await sequelize.authenticate();
2021-06-22 14:49:00 +02:00
logger.log('Connected to database');
2021-08-06 15:15:54 +02:00
2021-06-24 12:53:45 +02:00
const syncModels = true;
2021-08-06 15:15:54 +02:00
if (syncModels) {
2021-06-22 14:49:00 +02:00
logger.log('Starting model synchronization');
await sequelize.sync({ alter: true });
2021-06-22 14:49:00 +02:00
logger.log('All models were synchronized');
}
} catch (error) {
2021-06-22 14:49:00 +02:00
logger.log(`Unable to connect to the database: ${error.message}`, 'ERROR');
process.exit(1);
}
2021-08-06 15:15:54 +02:00
};
module.exports = {
connectDB,
2021-09-06 13:22:47 +02:00
sequelize,
2021-08-06 15:15:54 +02:00
};