Skip to content

Instantly share code, notes, and snippets.

@giacomorebonato
Created April 25, 2016 12:21
Show Gist options
  • Save giacomorebonato/579ea349417bdd3c03829457619ac6b5 to your computer and use it in GitHub Desktop.
Save giacomorebonato/579ea349417bdd3c03829457619ac6b5 to your computer and use it in GitHub Desktop.
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'),
}
'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
@Mr-emeka
Copy link

@v-vashchenko LOL thanks,this post is a year plus now.i know that know thanks alot.

@giacomorebonato
Copy link
Author

I wasn't following this thread! Thanks for answering!

@RaveHunter05
Copy link

didn't find another example of .sequelizerc, thank you very much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment