sequelize

2006 ワード

sequelizeはNodeです.jsで最も広く応用されているormオープンソースライブラリ、github:https://github.com/sequelize/sequelize. 中国語ドキュメント:https://github.com/demopark/sequelize-docs-Zh-CNSequelizeはpromiseベースのノードです.js ORM、現在Postgres、MySQL、SQLite、Microsoft SQL Serverをサポートしています.強力なトランザクションサポート、関連関係、読み取り、コピーなどの機能を備えています.公式文書に従って作ると、いつも変な感じがして、とても疲れて、いつも労働力が解放されていない感じがします.その後、このライブラリには2つの重要なツール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

この2つのコマンドは、相互逆操作とはみなされません.どう処理すればいいか自分で見てみましょう.