NODE.JS ORM之sequelize 框架
2018-02-05 09:11
351 查看
npm install sequelize //ORM 主框架
npm install -g sequelize-auto // 已有数据库表生成modle工具 2、已有的数据库生成modlenpm install -g tedious //安装MSSQL数据库驱动。sequelize-auto -o "./models" -d zmcs -h localhost -u sa_ -p 1433 -x 422426362227001 -e mssql -c zmcy.json
zmcy.json 文件内容 { "dialect": "mssql", "dialectOptions": { "tdsVersion": "7_1" //默认是7_4,对应的是sql2012以上版本, 7_1对应的是sql2000 ,需要定义驱动程序版本。 } }
Options: -h, --host IP/Hostname for the database. [required] -d, --database Database name. [required] -u, --user Username for database. -x, --pass Password for database. -p, --port Port number for database. -c, --config JSON file for Sequelize's constructor "options" flag object as defined here: https://sequelize.readthedocs.org/en/latest/api/sequelize/ -o, --output What directory to place the models. -e, --dialect The dialect/engine that you're using: postgres, mysql, sqlite -a, --additional Path to a json file containing model definitions (for all tables) which are to be defined within a model's configuration parameter. For more info: https://sequelize.readthedocs.org/en/latest/docs/models-definition/#configuration -t, --tables Comma-separated names of tables to import -C, --camel Use camel case to name models and fields -n, --no-write Prevent writing the models to disk.
3、使用生成的modle
var fsl = sequelize.import(__dirname + "/models/frontlog")
sequelize.query('SELECT top 3 int_flowid,vch_logtype,vch_operID,dt_operdate from front_sys_log where vch_operID = ? and int_flowid > ? ', {
replacements: ['1001',1],
type: sequelize.QueryTypes.SELECT
}).then((data) => {
console.log(data);
});
fsl.create({
id:3,
vch_logtype: '系统管理日志',
vch_operID: '1002',
dt_operdate: '2017-05-02 17:42:42.950',
vch_computer: 'ZM-HEHM',
vch_function: '登录',
vch_functype: '系统管理',
vch_description: '登录后台管理系统!'
}, {
returning: false
}).then(function (task) {
console.log(task);
})
相关文章推荐
- Node.js ORM 框架 sequelize 实践
- NODE.JS ORM之sequelize 框架
- Node.js ORM 框架 sequelize 实践
- 在node.js中,使用基于ORM架构的Sequelize,操作mysql数据库之增删改查
- ORM DB for nodejs--sequelize
- NODEJS ORM sequelizejs 常见用法
- Node.js中的express框架获取http参数
- node.js express框架跨域设置
- node.js 压力测试框架.01
- node.js框架 服务器express的使用 及 route路由的使用
- Node.js 框架比较: Express vs. Koa vs. Hapi
- Node.js web框架Clouda初接触
- HowToNodejs - fly-js-wbean - 在线游戏平台网络传输框架 - Google Project Hosting
- Node.js Sequelize如何实现数据库的读写分离
- Vue框架下的node.js安装教程
- Node.js 制作实时多人游戏框架
- 第7章-使用ORM类库Mongoose提升你的Node.js数据-7.2.Mongoose的原型
- node.js Sequelize实现单实例字段或批量自增、自减
- 最受欢迎的 5 款 Node.js 端到端测试框架
- Node.js Bones框架学习