NODE.JS ORM之sequelize 框架

1、安装:

npm install sequelize   //ORM 主框架

npm install -g sequelize-auto // 已有数据库表生成modle工具



2、已有的数据库生成modle

npm 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);
})



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值