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

29 lines
No EOL
630 B
JavaScript

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