我用mongodb(猫鼬作为 ODM)制作了一个应用程序,但现在我想使用MySQL(工作义务),所以我Sequelize为此采用了模块,但我真的不明白如何将我的 userSchema 转换为用户模型及其所有方法(我'米,工作passportJs进行身份验证,所以我有一些方法,我使用例如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"
}
);
userSchema.methods.setPassword = function(password) {
this.salt = crypto.randomBytes(16).toString('hex');
this.hash …Run Code Online (Sandbox Code Playgroud)