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