Skip to content

cadrogui/sails-generator-automodel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sails Mysql AutoGen

Generate models automatically for Sails Js or Waterline for Mysql connections

Version 2.0.0

One bad thing when you work with sails js is do all the models by hand... until now, this generator helps to do this task in a very simple way.

The usage of this generator is a bite simple.

#npm i sails-mysql-autogen -g

Usage

Go to the directory that will models be loaded, and run

#sails-mysql-autogen

Sails Mysql AutoGen will prompt connection data for usage.... and thats all, it will generate all files for represent you database, in the current directory.

Data Types

Automodel support all data types present in waterline:

  • string
  • text
  • integer
  • float
  • date
  • time
  • datetime
  • boolean
  • binary
  • array
  • json

Associations

At this version AutoModel can detect all foreign keys only as model attribute, if in your associations you need the virtual attribute collections you must create by your self, but half way is taken by AutoModel, in the next releases i will try to give the power to AutoModel to handle complete associations.

AutoModel in action

Example model

Models generated by AutoModel

Model Pets
module.exports = {
    "identity": "Pets",
    "connection": "sails_test",
    "autoCreatedAt": false,
    "autoUpdatedAt": false,
    "attributes": {
        "id": {
            "type": "INTEGER",
            "primaryKey": "TRUE",
            "autoIncrement": "TRUE"
        },
        "name": "STRING",
        "Owners": {
            "model": "Owners",
            "columnName": "owner_id"
        }
    }
}
Model Owners
module.exports = {
    "identity": "Owners",
    "connection": "sails_test",
    "autoCreatedAt": false,
    "autoUpdatedAt": false,
    "attributes": {
        "id": {
            "type": "INTEGER",
            "primaryKey": "TRUE",
            "autoIncrement": "TRUE"
        },
        "name": "STRING",
        "lastname": "STRING",
        "email": "STRING"
    }
}

As you can see automodel helps a lot with the tedious task of creating the models.

I hope AutoModel helps to make all of your models as an easy task, as well for me.

To-do

  • Detect Sails connections automatically

About

Generate models for Sails Js or Waterline from a mysql connection

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published