forked from pawelmalak/flame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
32 lines (27 loc) · 723 Bytes
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 = true;
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
};