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,711評論 1 180
  • 22:00 北京 夏添以北京癱的姿勢跟閨蜜打電話的時候,手機進來一條短信, “尊敬的用戶,您在工商銀行辦理的個人貸...
    寂靜歡喜閱讀 302評論 0 0
  • 去年看了劉慈欣的《三體》深受打擊,因為他寫的內容和人物不但常跨越上百光年的空間還要疊加上百億年的時間,在他...
    魯希閱讀 1,292評論 0 1
  • 一直以來都在被哈桑的真摯所感動 關于忠誠關于友誼 每當讀到這樣的片段 都會無法抑制的感到震撼 被哈桑的堅持和無...
    Venchin_閱讀 340評論 0 0