Created
November 28, 2013 15:40
-
-
Save mjason/7693863 to your computer and use it in GitHub Desktop.
sequelize for express 配置
This file contains 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 config = require('./config.json') | |
var environment = process.env.NODE_ENV || 'development' | |
var databaseConfig = config[environment] | |
var Sequelize = require('sequelize') | |
var sequelize = new Sequelize(databaseConfig.database, | |
databaseConfig.username, databaseConfig.password, { | |
host: databaseConfig.host, | |
dialect: databaseConfig.dialect, | |
logging: false | |
}) | |
global.models = { | |
Sequelize: Sequelize, | |
sequelize: sequelize, | |
} | |
require("fs").readdirSync("./models").forEach(function(file) { | |
if (file != 'associations.js') { | |
file = file.split('.')[0] | |
models[file] = sequelize.import(__dirname + '/../models/' + file) | |
} | |
}) | |
require('../models/associations') | |
if (environment == 'development') { | |
sequelize.sync().complete(function(err) { | |
if (err) { | |
throw err | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment