模型与测试
安装 password-hash 与测试
npm i password-hash -Simport * as Sequelize from 'sequelize';
import * as ph from 'password-hash';
import { resolve } from 'path';
const sq = new Sequelize('db', null, null,{
dialect: 'sqlite',
storage: resolve(__dirname, '../storage/db.sqlite3')
});
var User = sq.define('user', {
id:{
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
username: {
type: Sequelize.STRING,
},
email: {
type: Sequelize.STRING
},
password: {
type: Sequelize.STRING
}
}, {
timestamps: false,
freezeTableName: true // Model tableName will be the same as the model name
});
User.create({
username: 'yugo',
email: 'belovedyogurt@gmail.com',
password: ph.generate('123456')
}).then(console.log)编写 Model 与 ava 测试文件
Last updated