我正在尝试使用Sequelize ORM创建到远程数据库的连接。但是出现错误:
> var eventName = msg.name === 'error' ? 'errorMessage' : msg.name
> ^
>
> at Socket.<anonymous> (node_modules\pg\lib\connection.js:120:27) at
> emitOne (events.js:116:13) at Socket.emit (events.js:211:7) at
> addChunk (_stream_readable.js:263:12) at readableAddChunk
> (_stream_readable.js:250:11) at Socket.Readable.push
> (_stream_readable.js:208:10) at TCP.onread (net.js:597:20)
我正在同步server.js中的Sequelize模型,提供端口并传递控制器和功能。
models.sequelize.sync().then(() => {
app.listen(1234);
app.use('/check', check);
check.testCheck(() => {
io.emit('testCheck');
});
})
在models / index.js中,这里是Sequelize选项(所有参数均为qorrect含义:用户名密码db等),在这里我也定义了模型(在这种情况下,我只有一个称为“ orders”的模型)
const Sequelize = require('sequelize');
const sequelize = new Sequelize('db', "username", 'password', {
host: 'host',
dialect: 'postgres',
port: 1234,
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
},
});
var models = {
orders: sequelize['import']("./iSOMessagesModel"),
};
Object.keys(models).forEach(modelName => {
if (models[modelName].associate) {
models[modelName].associate(models);
}
});
models.sequelize = sequelize;
models.Sequelize = Sequelize;
module.exports = models;
模型如下:
module.exports = function(sequelize, DataTypes) {
var Orders = sequelize.define('ISOMessages', {
id: {
type: DataTypes.STRING,
primaryKey: true
},
message: {
type: DataTypes.STRING
},
createdAt: {
type: DataTypes.DATE,
},
updatedAt: {
type: DataTypes.DATE,
},
status: {
type: DataTypes.STRING
},
sResponse: {
type: DataTypes.STRING
},
userId: {
type: DataTypes.INTEGER
},
cardId: {
type: DataTypes.STRING
},
amount: {
type: DataTypes.INTEGER
},
commission: {
type: DataTypes.INTEGER
},
location: {
type: DataTypes.STRING
},
provider: {
type: DataTypes.STRING
},
}, {
tableName: 'ISOMessages'
});
return Orders;
}
Thnx