sequelize

sequelize 是Node.js中应用最广泛的orm开源库,github:https://github.com/sequelize/sequelize
中文文档:https://github.com/demopark/sequelize-docs-Zh-CN
Sequelize 是一个基于 promise 的 Node.js ORM, 目前支持 Postgres, MySQL, SQLite 和 Microsoft SQL Server. 它具有强大的事务支持, 关联关系, 读取和复制等功能.
按照官方文档做,总是觉得不对劲,做的非常累,总有劳动力没有解放的感觉。后来发现这个库还有两个关键的配套工具sequelize-cli,和sequelize-auto。
sequelize-cli用来通过命令产生对应的代码模型和数据库迁移。
sequelize-auto 用来通过已有的数据库结构生成代码模型和数据库迁移。
常用命令

sequelize-auto -h localhost -d login_demo -u root -x root -p 3306 -t user

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

node_modules/.bin/sequelize model:generate --name User --attributes firstName:string,lastName:string,email:string
node_modules/.bin/sequelize db:migrate
node_modules/.bin/sequelize db:migrate:undo

经过测试 这两命令不能看做互逆操作。如何处理自己看着办吧。

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

推荐阅读更多精彩内容

  • 用到的组件 1、通过CocoaPods安装 2、第三方类库安装 3、第三方服务 友盟社会化分享组件 友盟用户反馈 ...
    SunnyLeong阅读 14,947评论 1 180
  • 22:00 北京 夏添以北京瘫的姿势跟闺蜜打电话的时候,手机进来一条短信, “尊敬的用户,您在工商银行办理的个人贷...
    寂静欢喜阅读 2,299评论 0 0
  • 去年看了刘慈欣的《三体》深受打击,因为他写的内容和人物不但常跨越上百光年的空间还要叠加上百亿年的时间,在他...
    鲁希阅读 5,133评论 0 1
  • 一直以来都在被哈桑的真挚所感动 关于忠诚关于友谊 每当读到这样的片段 都会无法抑制的感到震撼 被哈桑的坚持和无...
    Venchin_阅读 2,615评论 0 0