/sequelizator

CLI tool to generate sequelize models based on simple JSON config

Primary LanguageJavaScriptMIT LicenseMIT

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" }
    ]
  }
]