Skip to content

CLI tool to generate sequelize models based on simple JSON config

License

Notifications You must be signed in to change notification settings

joaogsleite/sequelizator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sequelize generator

node npm version dependencies Status devDependencies Status PRs Welcome GitHub

CLI tool to generate sequelize models based on simple JS config

Install

  • inside your project
npm install --save-dev sequelizator
  • globally
npm install -g sequelizator

Using

sequelizator <folder>
  • Sequelize models will be created inside <folder>
  • <folder> must contains a config.js file like this example/config.js
  • You can create a script in your project's package.json to run this way: npm run sequelizator
...
"scripts": {
  ...
  "sequelizator": "sequelizator ./src/models/",
  ...
},
...

Example config.js

[
  {
    "table": "users",
    "model": "User",
    "columns": [
      {
        "name": "name",
        "type": "STRING",
        "allowNull": false,
      },
      {
        "name": "email",
        "type": "STRING",
      },
      {
        "name": "password",
        "type": "STRING",
      },
    ],
    "relations": [
      { "type": "1:n", "model": "Post" }
    ]
  },
  {
    "table": "posts",
    "model": "Post",
    "columns": [
      {
        "name": "title",
        "type": "STRING",
      },
      {
        "name": "published",
        "type": "BOOLEAN",
        "defaultValue": true,
        "allowNull": false,
      },
    ],
    "relations": [
      { "type": "n:n", "model": "Tag" }
    ]
  },
  {
    "table": "tags",
    "model": "Tag",
    "columns": [
      {
        "name": "name",
        "type": "STRING",
      },
      {
        "name": "order",
        "type": "INTEGER",
        "defaultValue": 1,
        "allowNull": false,
      },
    ],
    "relations": [
      { "type": "n:n", "model": "Post" }
    ]
  }
]

About

CLI tool to generate sequelize models based on simple JSON config

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published