官术网_书友最值得收藏!

Installing and configuring Sequelize-cli

Sequelize-cli is a very useful command-line interface for creating models, configurations and migration files to databases. It's integrated with Sequelize middleware and operates with many relational databases such as PostgreSQL, MySQL, MSSQL, Sqlite.

Tip

You can find more information about Sequelize middleware implementation at: http://docs.sequelizejs.com/en/latest/ and full documentation of Sequelize-Cli at: https://github.com/sequelize/cli.

  1. Open terminal/shell and type:
     npm install -g sequelize-cli
    
  2. Install sequelize with the following command:
     npm install sequelize -save
    

    Tip

    Remember we always use the -save flag to add the module to our package.json file.

  3. Create a file called .sequelizerc on the  root folder and place the following code:
          var path = require('path'); 
          module.exports = { 
            'config': path.resolve('./config', 'config.json'), 
            'migrations-path': path.resolve('./config', 'migrations'), 
            'models-path': path.resolve('./', 'models'), 
            'seeders-path': path.resolve('./config', 'seeders') 
          } 
    
  4. On terminal/shell, type the following command:
    sequelize init
    
  5. After the init command, the terminal will show the following output message:
     Sequelize [Node: 6.3.0, CLI: 2.3.1, ORM: 3.19.3] Using gulpfile /usr/local/lib/node_modules/sequelize -cli/lib/gulpfile.js Starting 'init:config'... Created "config/config.json" Finished 'init:config' after 4.05 ms Successfully created migrations folder at "/chapter-02/config /migrations". Finished 'init:migrations' after 1.42 ms Successfully created seeders folder at "/chapter-02/config /seeders". Finished 'init:seeders' after 712 ??s Successfully created models folder at "/chapter-02/models". Loaded configuration file "config/config.json". Using environment "development". Finished 'init:models' after 18 msStarting 'init'...
    

This command also creates the models directory to store application schema, a configuration file, and folders to hold seeders and the  migrations script. Don't worry about this now, we will look at migrations in the next section.

主站蜘蛛池模板: 武平县| 潼关县| 宜川县| 永春县| 青神县| 金昌市| 杭锦后旗| 东阳市| 印江| 河东区| 馆陶县| 都匀市| 安顺市| 冷水江市| 上犹县| 宽城| 嵩明县| 中方县| 汤原县| 澎湖县| 南丰县| 临高县| 屏东市| 洞口县| 邢台县| 奉新县| 资源县| 渭源县| 乌兰察布市| 武乡县| 临邑县| 岗巴县| 鸡西市| 扎鲁特旗| 德兴市| 大宁县| 濮阳市| 潢川县| 珠海市| 德州市| 诏安县|