所以我刚刚使用 sequelize.js 为节点创建了一个数据库,并拥有以下代码:
var sequelize = new Sequelize('database', 'sheta', 'mysqlroot', {
host: 'localhost',
port: 3000,
timestamps: false
});
var User = sequelize.define('User', {
userID: Sequelize.INTEGER,
userName: Sequelize.TEXT,
password: Sequelize.TEXT
}, {
instanceMethods: {
getUserId: function() {
return this.userID;
}
}
});
var Post = sequelize.define('Post', {
userID: Sequelize.INTEGER,
postText: Sequelize.TEXT,
date: Sequelize.DATE,
postID: Sequelize.INTEGER
}, {
instanceMethods: {
getPost: function() {
return this.postText;
}
}
});
var Comment = sequelize.define('Comment', {
postID: Sequelize.INTEGER,
commentText: Sequelize.TEXT,
date: Sequelize.DATE,
commentID: Sequelize.INTEGER
} , {
instanceMethods: {
getComment: function() {
return this.commentText;
}
}
});
var Tag = sequelize.define('Tag', {
tagID: Sequelize.INTEGER,
tagText: Sequelize.TEXT,
postID: Sequelize.INTEGER
});
//Associations
Post.belongsTo(User);
Post.hasOne(User);
User.hasMany(Post);
Post.hasMany(Comment);
Comment.belongsTo(User);
Comment.hasOne(User);
User.hasMany(Comment);
Post.hasMany(Tag);
Tag.hasMany(Post);
sequelize.sync();
但是当我尝试使用以下方法添加元组时:
User.create({ userID: 1, userName: 'sam', password: 'th'}).success(function(task) {
console.log("inserted");
// you can now access the newly created task via the variable task
});
“插入”从不打印。难道我做错了什么?主要看sequelize js上的代码。我在这里缺少什么吗?