2021-05-10 18:47:26 +03:00
|
|
|
const { Sequelize } = require('sequelize');
|
|
|
|
|
|
|
|
const sequelize = new Sequelize({
|
|
|
|
dialect: 'sqlite',
|
2021-06-05 16:48:43 +03:00
|
|
|
storage: './data/db.sqlite',
|
|
|
|
logging: false
|
2021-05-10 18:47:26 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
const connectDB = async () => {
|
|
|
|
try {
|
|
|
|
await sequelize.authenticate({ logging: false });
|
2021-06-07 14:40:51 +03:00
|
|
|
console.log('Connected to database');
|
2021-06-05 16:48:43 +03:00
|
|
|
|
2021-05-10 18:47:26 +03:00
|
|
|
await sequelize.sync({
|
|
|
|
// alter: true,
|
|
|
|
logging: false
|
|
|
|
});
|
2021-06-07 14:40:51 +03:00
|
|
|
console.log('All models were synced');
|
2021-05-10 18:47:26 +03:00
|
|
|
} catch (error) {
|
|
|
|
console.error('Unable to connect to the database:', error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
connectDB,
|
|
|
|
sequelize
|
|
|
|
};
|