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

  • Node.js 6.x Blueprints
  • Fernando Monteiro
  • 248字
  • 2021-07-14 10:35:05

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.

主站蜘蛛池模板: 永宁县| 海盐县| 仁怀市| 临江市| 华安县| 新余市| 道孚县| 芷江| 浪卡子县| 沙田区| 高陵县| 延津县| 青阳县| 湘潭市| 济南市| 连山| 南澳县| 香港| 镇平县| 孝感市| 太原市| 石门县| 类乌齐县| 安塞县| 宝坻区| 彰武县| 南京市| 凌云县| 华宁县| 汝州市| 滨州市| 睢宁县| 大宁县| 乌拉特中旗| 大悟县| 铜陵市| 岳西县| 鲁甸县| 元阳县| 罗源县| 惠东县|