Files
xiao/structures/PostgreSQL.js
T
2017-04-27 15:17:41 +00:00

24 lines
697 B
JavaScript

const Sequelize = require('sequelize');
const database = new Sequelize(process.env.DATABASE_URL, { logging: false });
class Database {
static get db() {
return database;
}
start() {
database.authenticate()
.then(() => console.log('Connection to database has been established successfully.'))
.then(() => console.log('Synchronizing database...'))
.then(() => database.sync()
.then(() => console.log('Synchronizing database done!'))
.catch(error => console.error(`Error synchronizing the database: ${error}`))
)
.then(() => console.log('Ready to rock!'))
.catch(err => console.error(`Unable to connect to the database: ${err}`));
}
}
module.exports = Database;