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.jsonzmcy.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