forked from PluralFlux/PluralFlux
refactored database to not use then/catch
This commit is contained in:
@@ -59,26 +59,28 @@ db.systems = sequelize.define('System', {
|
|||||||
/**
|
/**
|
||||||
* Checks Sequelize database connection.
|
* Checks Sequelize database connection.
|
||||||
*/
|
*/
|
||||||
db.check_connection = async function() {
|
db.check_connection = async function () {
|
||||||
await sequelize.authenticate().then(async () => {
|
try {
|
||||||
|
await sequelize.authenticate();
|
||||||
console.log('Connection has been established successfully.');
|
console.log('Connection has been established successfully.');
|
||||||
await syncModels();
|
await syncModels();
|
||||||
}).catch(err => {
|
} catch (err) {
|
||||||
console.error('Unable to connect to the database:', err);
|
console.error('Unable to connect to the database:', err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Syncs Sequelize models.
|
* Syncs Sequelize models.
|
||||||
*/
|
*/
|
||||||
async function syncModels() {
|
async function syncModels() {
|
||||||
await sequelize.sync().then(() => {
|
try {
|
||||||
|
await sequelize.sync()
|
||||||
console.log('Models synced successfully.');
|
console.log('Models synced successfully.');
|
||||||
}).catch((err) => {
|
} catch(err) {
|
||||||
console.error('Syncing models did not work', err);
|
console.error('Syncing models did not work', err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const database = db;
|
export const database = db;
|
||||||
Reference in New Issue
Block a user