我有这个代码...
var Sequelize = require('sequelize');
var sequelize = null;
if (process.env.HEROKU_POSTGRESQL_BROWN_URL) {
// the application is executed on Heroku ... use the postgres database
sequelize = new Sequelize(process.env.HEROKU_POSTGRESQL_BROWN_URL, {
dialect: 'postgres',
protocol: 'postgres',
port: match[4],
host: match[3],
logging: true //false
})
} else {
// the application is executed on the local machine ... use mysql
sequelize = new Sequelize('ticketing', 'root',null,{
dialect: 'mysql'
});
console.log(typeof sequelize);
}
var db = {};
db.Sequelize = Sequelize;
db.sequelize = sequelize;
db.User = sequelize.import(__dirname + '/User');
console.log(typeof db.sequelize);
module.exports = db;
通常此代码应在控制台中显示两个对象,对吗?但是控制台中只有一个对象,第二个对象却奇怪地不显示任何内容,无论是null还是未定义。这里发生了什么?另外,当我尝试db.sequelize.define(某些代码)时,会抛出一个错误,即未定义define。