Tag: mongoose sequelize.js

mongoose模式序列化模型

我做了一个与MongoDB(mongoose作为ODM)的应用程序,但现在想与MySQL(工作义务),所以我拿了Sequelize模块,但我真的不明白如何将我的userSchema转换为用户模型的所有方法与passportJsauthentication,所以我有一些方法,即时通讯使用例如setpassword …) 在这里我的userSchema(mongoose),完美的作品。 var mongoose = require('mongoose'); var crypto = require('crypto'); var jwt = require('jsonwebtoken'); var validator = require('node-mongoose-validator'); var Schema = mongoose.Schema; var userSchema = new Schema({ name: { type: String, maxlength: 50}, mail: { type: String, required: true, maxlength: 50, index: { unique: true } }, hash: String, salt: String, { collection: "user" […]

在Sequelize中预保存钩子和实例方法?

在Sequelize.js中是否存在钩子和实例方法? 具体而言,我需要将这个Mongoose代码转换成等效的Sequelize代码: 架构 var userSchema = new mongoose.Schema({ username: { type: String, unique: true }, email: { type: String, unique: true }, password: String, token: String }); 预存 userSchema.pre('save', function(next) { var user = this; var hashContent = user.username + user.password + Date.now() + Math.random(); user.token = crypto.createHash('sha1').update(hashContent).digest('hex'); if (!user.isModified('password')) return next(); bcrypt.genSalt(5, function(err, salt) […]