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端口测试成功
sequelize 测试的更多相关文章
- node压力测试
压力测试 ab测试(ApacheBench); 介绍: 这是apache提供的压测工具; 使用: 启动node服务; 我用的XAMPP,进入bin文件夹,打开命令行,执行下面命令: // -n: 总请 ...
- Sequelize 基本操作
Sequelize 是 Node 的一个 ORM(Object-Relational Mapping) 框架,用来方便数据库操作. 配置 sequelize 以 mysql 为例 首先我们要引入npm ...
- node.js应用脚手架:koa2、sequelize、mysql
自制了一个 nodejs 应用的脚手架. 基于 koa2 的,所以需要保证 node 环境至少为 7.6.0 吸取了以前的踩坑教训,添加了守护进程,确保应用不会因为异常导致网站直接挂掉(使用了 for ...
- nodejs操作 mongoose(mongodb)和Sequelize(mysql)查询数据后添加新属性未生效
最近在着手koa时候,发现mongoose(mongodb)查询数据库后添加新属性,前端拿不到新属性问题, 然后测试了一下Sequelize(mysql),发现也有同样的问题存在.此时着手干! 1.1 ...
- node+pm2+express+mysql+sequelize来搭建网站和写接口
前面的话:在这里已经提到了安装node的方法,node是自带npm的.我在技术中会用es6去编写,然后下面会分别介绍node.pm2.express.mysql.sequelize.有少部分是摘抄大佬 ...
- koa2+log4js+sequelize搭建的nodejs服务
主要参考http://www.jianshu.com/p/6b816c609669这篇文章 npm安装使用国内taobao镜像,速度更快些 npm --registry https://registr ...
- 搭建项目vue + vue-router + vuex + vue-i18n + element-ui + egg + sequelize
vue + vue-router + vuex + vue-i18n + element-ui + egg + sequelize https://www.cnblogs.com/wuguanglin ...
- nodejs使用sequelize操作mysql实例
sequelize是node操作mysql的一款npm包,包含很多特性:数据库模型映射.事务处理.模型属性校验.关联映射等,花了两天时间学习了下基本的一些操作,特别是关联映射部分的操作,包含1:1.1 ...
- node.js使用Sequelize 操作mysql
Sequelize就是Node上的ORM框架 ,相当于java端的Hibernate 是一个基于 promise 的 Node.js ORM, 目前支持 Postgres, MySQL, SQLite ...
随机推荐
- pandas 中文快速查询手册
本文翻译自文章: Pandas Cheat Sheet - Python for Data Science ,同时添加了部分注解. 对于数据科学家,无论是数据分析还是数据挖掘来说,Pandas是一个非 ...
- C++循环链表实现约瑟夫退圈(类封装)
node.h #pragma once #include <iostream> #include <iomanip> using namespace std; struct n ...
- LeetCode OJ:Binary Tree Inorder Traversal(中序遍历二叉树)
Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary tre ...
- LeetCode OJ:Maximum Depth of Binary Tree(二叉树最大深度)
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- git公私钥的拷贝
1.场景 由于我换了一台电脑,为了能访问远程仓库,我就把原来电脑上的私钥和config文件拷贝过来 2.出现问题及解决方案 git clone server:xxx_service_express 报 ...
- Object 的一个问题
var s1 = 'abc'; s1 instanceof String //false var s2 = new String('abc'); s2 instanceof Strin ...
- C语言中time函数获取系统时间
可以通过time()函数来获得计算机系统当前的日历时间(Calendar Time),处理日期时间的函数都是以本函数的返回值为基础进行运算.其原型为: time_t time(time_t * t); ...
- ACM学习历程—SNNUOJ1215 矩阵2(二分 && dfs)
http://219.244.176.199/JudgeOnline/problem.php?id=1215 这是这次微软和百度实习面试的一道题,题目大意就是:有一个n*m的矩阵,已知它每一行都是不严 ...
- Why getting this error “django.db.utils.OperationalError: (1050, ”Table 'someTable' already exists“)”
0down votefavorite I am getting error like django.db.utils.OperationalError: (1050, "Table 's ...
- 【ASP.NET Web API2】初识Web API
Web Api 是什么? MSDN:ASP.NET Web API 是一种框架,用于轻松构建可以访问多种客户端(包括浏览器和移动设备)的 HTTP 服务 百度百科:Web API是网络应用程序接口. ...