orm 使用Sequelize

Adservice

数据库使用mysql

orm 使用Sequelize

表映射使用 sequelize-auto

  npm install -g sequelize-auto
  npm install -g mysql

  [node] sequelize-auto -h <host> -d <database> -u <user> -x [password] -p [port]  --dialect [dialect] -c [/path/to/config] -o [/path/to/models] -t [tableName] -C

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
  -T, --skip-tables Comma-separated names of tables to skip
  -C, --camel       Use camel case to name models and fields
  -n, --no-write    Prevent writing the models to disk.
  -s, --schema      Database schema from which to retrieve tables

例如:

sequelize-auto -o "./models" -d ad -h localhost -u root -p 3306 -x doter1995 -e mysql

由于sequelize默认情况下回自动创建两个列 creatAt和updateAt

所以需要提前在表中创建 ,或者需要配置取消creatAt和updateAt

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1. 简介 1.1 什么是 MyBatis ? MyBatis 是支持定制化 SQL、存储过程以及高级映射的优秀的...
    笨鸟慢飞阅读 11,112评论 0 4
  • ·错误:1000 SQLSTATE: HY000 (ER_HASHCHK)消息:hashchk·错误:1001 S...
    Catke阅读 5,532评论 0 2
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 31,899评论 18 399
  • 什么是数据库? 数据库是存储数据的集合的单独的应用程序。每个数据库具有一个或多个不同的API,用于创建,访问,管理...
    chen_000阅读 9,459评论 0 19
  • 当阳光把学生们的影子 都扑倒在绿茵茵的操场上 我抬头看看包裹着大地的蓝天 想着 这或许 就是我人生中 最灿烂最耀眼...
    岁末selma阅读 1,183评论 0 0