Add DB Back

This commit is contained in:
Daniel Odendahl Jr
2017-09-04 20:25:06 +00:00
parent e4eb697373
commit 82a978390b
5 changed files with 288 additions and 6 deletions
+26
View File
@@ -0,0 +1,26 @@
const Sequelize = require('sequelize');
const { DB_URL } = process.env;
const database = new Sequelize(DB_URL, { logging: false });
class Database {
static get db() {
return database;
}
static start() {
database.authenticate()
.then(() => console.log('[DATABASE] Connection established successfully.'))
.then(() => console.log('[DATABASE] Synchronizing...'))
.then(() => database.sync()
.then(() => console.log('[DATABASE] Done Synchronizing!'))
.catch(err => console.error(`[DATABASE] Error synchronizing: ${err}`))
)
.catch(err => {
console.error(`[DATABASE] Unable to connect: ${err}`);
console.error(`[DATABASE] Reconnecting in 5 seconds...`);
setTimeout(() => Database.start(), 5000);
});
}
}
module.exports = Database;