这是我的 managedb.js
var Sequelize = require('sequelize-postgres').sequelize;
var postgres = require('sequelize-postgres').postgres;
var pg = require('pg');
var db = new Sequelize('tesf3', 'postgres', 'postgres', {
dialect: 'postgres',
port: '5432',
omitNull: true
});
module.exports.db = db;
var Link = db.import(__dirname + '/lib/link/models').Link;
var LinkUser = db.import(__dirname + '/lib/link/models').LinkUser;
module.exports.Link = Link;
module.exports.LinkUser = LinkUser;
这是我在库中的 models.js:
var sequelize = require('../../managedb').db;
var DataTypes = require('sequelize-postgres').sequelize;
var Link = sequelize.define('Link', {
url: {
type: DataTypes.STRING,
validate:{
isUrl: true,
notEmpty: true,
notNull: true
}
},
context: {
type: DataTypes.STRING,
defaultValue: " "
},
previewImage: {
type: DataTypes.STRING
},
source:{
type: DataTypes.STRING
},
shortUrl:{
type: DataTypes.STRING
},
viewed:{
type: DataTypes.STRING
},
image:{
type: DataTypes.STRING
},
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
}
},
{
instanceMethods: {
countTasks: function() {
// how to implement this method ?
}
}
});
var LinkUser = sequelize.define('LinkUser', {
linkId: {
type: DataTypes.INTEGER
},
userId: {
type: DataTypes.INTEGER
},
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
}
},
{
instanceMethods: {
countTasks: function() {
// how to implement this method ?
}
}
});
module.exports.Link = Link;
module.exports.LinkUser = LinkUser;
我哪里错了?我不能在一个 js 文件中定义多个模型吗?