-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmysql_connect.js
More file actions
executable file
·42 lines (34 loc) · 1.09 KB
/
mysql_connect.js
File metadata and controls
executable file
·42 lines (34 loc) · 1.09 KB
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
32
33
34
35
36
37
38
39
40
41
42
'use strict';
var Sequelize = require('sequelize');
var sqlizr = require('sqlizr');
var config = require('./config/config');
exports.register = (plugin, options, next) => {
// default directory for models
options.models = options.models || './models/*.js';
const sequelize = new Sequelize(config.db_schema, config.db_user, config.db_pass, {
host: config.db_host,
dialect: 'mysql',
logging: false,
pool: { max: 50, min: 0, idle: 10000 },
define: {
freezeTableName: true,
timestamps: false // true by default
}
});
// test the database connection
sequelize.authenticate()
.then(function() {
console.log('DB ' + config.db_schema + ' connected');
})
.catch(function(err) {
console.log(err);
})
sqlizr(sequelize, options.models);
const db = { sequelize: sequelize, Sequelize: Sequelize };
// make available in hapi application
plugin.expose('db', db);
next();
};
exports.register.attributes = {
name: 'mysql_connect'
};