-
-
Save AntonyOnScript/d6dc53d106e4bee5de726a5d1895ab40 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = require('path') | |
module.exports = { | |
'config': path.resolve('server', 'config', 'database.json'), | |
'migrations-path': path.resolve('server', 'migrations'), | |
'models-path': path.resolve('server', 'models'), | |
'seeders-path': path.resolve('server', 'seeders'), | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
import fs from 'fs' | |
import path from 'path' | |
import Sequelize from 'sequelize' | |
var basename = path.basename(module.filename) | |
var env = process.env.NODE_ENV || 'development' | |
var config = require(path.join(__dirname, '/../config/database.json'))[env] | |
var db = {} | |
var sequelize | |
if (config.use_env_variable) { | |
sequelize = new Sequelize(process.env[config.use_env_variable]); | |
} else { | |
sequelize = new Sequelize(config.database, config.username, config.password, config); | |
} | |
fs | |
.readdirSync(__dirname) | |
.filter((file) => { | |
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js'); | |
}) | |
.forEach((file) => { | |
var model = sequelize['import'](path.join(__dirname, file)); | |
db[model.name] = model | |
}) | |
Object.keys(db).forEach((modelName) => { | |
if (db[modelName].associate) { | |
db[modelName].associate(db) | |
} | |
}) | |
db.sequelize = sequelize | |
db.Sequelize = Sequelize | |
export default db |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment