How to convert Existing database to sequelize models using sequelize-auto

If you have existing tables in the database you want to convert into sequelize models then use sequelize auto library.

Install Sequelize Auto using CLI

npm install -g sequelize-auto

Prerequisites: 

Are you using MYSQL? Run Below command. (ignore if already installed)

npm install -g mysql

Are you using Postgres? Run Below command. (ignore if already installed)

npm install -g pg pg-hstore

Keep your database server on.

Use the below command for converting to models.

sequelize-auto -h <host> -d <database> -u <user> -x [password] -p [port]  --dialect [dialect] -c [/path/to/config] -o [/path/to/models] -t [tableName] -C

Example:

sequelize-auto -h 127.0.0.1 -d sequelize -u root -x root@123 -p 3306  --dialect mysql -c c:\users\models -o c:\users\models

Have a fun with models..

Referance : https://github.com/sequelize/sequelize-auto

 

Create your website with WordPress.com
Get started
%d bloggers like this: