Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

auto-generate models for sequelize

Tags:

I'm wanting to start using Sequelize, a module that allows ORM for mysql in node.js. I was wondering if it's possible to auto-generate the models like CakePHP does. In CakePHP, it will read the table's info, and automatically create the associations and fields with their types in the model. i'd really hate to have to completely map out all my tables by hand, as some are relatively large. Is there something out there that will do this for me? Or am I on my own to hand-type all the models out?

like image 299
LordZardeck Avatar asked Nov 21 '12 20:11

LordZardeck


People also ask

Does Sequelize automatically CREATE TABLE?

Automatically creates tables in MySQL database if they don't exist by calling await sequelize.

How do I create a model in Sequelize node JS?

Sequelize set up Install Sequelize database driver for the database you would like to use by running one of the commands below. Install npm package Sequelize-CLI. Create a project folder. In your project folder path, run the command below to initialize Sequelize in the folder.


Video Answer


2 Answers

You can auto generate models through sequelize-auto. Just Follow the following link https://github.com/sequelize/sequelize-auto

It will generate models of your table.

like image 194
puneet gupta Avatar answered Sep 23 '22 17:09

puneet gupta


Now you can use sequelize-automate to generate models automatically. sequelize-auto seems to be unmaintained for a long time, and the package is out-of-date.

$ npm install sequelize-automate $ ./node_modules/.bin/sequelize-automate --help 

For example:

$ ./node_modules/.bin/sequelize-automate -t js -h localhost -d test -u root -p root -o models 
like image 29
nodejh Avatar answered Sep 23 '22 17:09

nodejh