forked from atulmy/crate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.js
More file actions
31 lines (25 loc) · 797 Bytes
/
database.js
File metadata and controls
31 lines (25 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Imports
import { Sequelize } from 'sequelize'
// App Imports
import { NODE_ENV } from '../config/env'
import databaseConfig from '../config/database.json'
// Load database config
const databaseConfigEnv = databaseConfig[NODE_ENV]
// Create new database connection
const connection = new Sequelize(databaseConfigEnv.database, databaseConfigEnv.username, databaseConfigEnv.password, {
host: databaseConfigEnv.host,
dialect: databaseConfigEnv.dialect,
logging: false,
operatorsAliases: Sequelize.Op
})
// Test connection
console.info('SETUP - Connecting database...')
connection
.authenticate()
.then(() => {
console.info('INFO - Database connected.')
})
.catch(err => {
console.error('ERROR - Unable to connect to the database:', err)
})
export default connection