sequelize 测试

1.在根目录新建module文件,在文件下新建文件modelhead.js

代码如下:

var Sequelize=require("sequelize")
var sequelize = new Sequelize('kameng', 'root', '228151', {
  host: '127.0.0.1',
  dialect: 'mysql',

  pool: {
    max: 5,
    min: 0,
    idle: 10000
   },

});
console.log("链接成功");
module.exports = sequelize;

2.在router路由下面的index.js 文件下添加如下代码:

var express = require('express');
var router = express.Router();
var Sequelize=require("sequelize")
var sequelize = require("../module/modelhead")
/* GET home page. */
router.get('/', function(req, res, next) {
var User = sequelize.define('users', {
	"id": {type:Sequelize.BIGINT, allowNull: false,primaryKey: true},
    "email": {type: Sequelize.STRING, allowNull: false, primaryKey: true}, //代理商代码
	"pwd": {type: Sequelize.STRING, allowNull: false}, //代理商名称
	"nicheng": {type: Sequelize.STRING, allowNull: false}, //代理商二级域名
	"createtime":{type:Sequelize.DATE, allowNull: true},
    "updtime":{type:Sequelize.DATE, allowNull: true}
},{
		timestamps: false,
		//paranoid: true  //获取不到id的返回值
	});
 User.findAll({attributes: ["email","nicheng"],where: {id: 1},raw: true }).then(function(users) {
  console.log(users)
})
  res.render('index', { title: 'Express' });
});

module.exports = router;

访问3000端口测试成功

 

posted @ 2018-03-07 16:46  开始战斗  阅读(204)  评论(0编辑  收藏  举报