npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sails-inverse-model

v2.0.7

Published

Sails Inverse Model helps you build models, controllers and views JS Sails from any database. In addition, you can quickly and individually generate each model, view, controller or all three at the same time.

Downloads

525

Readme

enter image description here

Automated generator models, views and controllers for SailsJS & WaterLine

Build Status

Sails Inverse Model helps you build models, controllers and views JS Sails from any database. In addition, you can quickly and individually generate each model, view, controller or all three at the same time.

Available for PostgreSQL, MySQL and MongoDB


Installation

Linux or MacOS

$ sudo npm install sails-inverse-model@next -g

Microsoft Windows

$ npm install sails-inverse-model@next -g

Individual generation

You can quickly generate a model, a controller, a view or these three at the same time simply define the attributes of your model. Let's look at an example:

# Generate model
$ sails-inverse-model -g model --name Pet -a "name:string:r:u owner:string"

# Generate Controller
$ sails-inverse-model -g controller --name Pet -a ""

# Generate View
$ sails-inverse-model -g view --name Pet -a "name:string:r owner:string"

# Generate all (Model, View and Controller)
$ sails-inverse-model -g all --name Pet -a "name:string:r:k owner:string"

Detail

|Param | Description | |------------------:|:------------------------------------| |g | Generate view, model, controller | |name | Name: model, driver, and view folder| |a | Content of the element to generate | |name:string:params | Attribute name: data type: params |

Specifies the type of data that will be stored in this attribute. Here

Params

|Param | Description | Example | |------:|:--------------|:------------------| |r | Required | catname:string:r | |u | Unique | catname:string:u | |a | Autoincrement | index:integer:a | |k | Primary Key | index:integer:k |

You can also set all three parameters at the same time, for example: index:integer:a:u:r

Example

sails-inverse-model -g model --name Pet -a "index:integer:r:u:a name:string:r:u owner:string:r"

=>
  module.exports = {
      attributes: {
          index: {                -> index
              type: 'integer',    -> :integer 
              required: true,     -> :r
              unique: true,       -> :u 
              autoincrement: true -> :a
          },
          name: {
              type: 'string',
              required: true,
              unique: true
          },
          owner: {
              type: 'string',
              required: true
          }
      }
  };

Generator (from Database)

$ sails-inverse-model --help

  Sails Inverse Model helps you build models, controllers and views JS Sails from any database. In addition, you can quickly and individually generate each model, view, controller or all three at the same time.

                  .-..-.														      
																	
  Sails-inverse-model<|    .-..-.	2.x.x
                      |										
      ~    ~   ~     /|. 									
         ~  ~       / || 									
           ~  ~   ,'  |'  									
               .-'.-==|/_--'								
               `--'-------' 								
     _--__--_---__---___--__---__--___      
   __---__--__---___--__---___--_-_---___    
   ----------------------------------------------------------
   :: Sat Feb 04 2017 22:43:52 GMT-0500 (COT)
   ----------------------------------------------------------
  Example:
    $ mkdir sails-output
    $ cd sails-output
    $ sails-inverse-model -u postgres -p root -d almacen -t pg -m -v -c

  User         : postgres
  Password     : root
  Database     : almacen
  Host         : localhost
  Models       : /home/julian/Documents/sails-output/models
  Views        : /home/julian/Documents/sails-output/views
  Controllers  : /home/julian/Documents/sails-output/controllers
  DB           : pg
  Schema (pg)  : public
  =====================================
  Views [OK]
  =====================================
  Models [OK]
  =====================================
  Controllers [OK]

      Note: Copy models      => your/project_sails/api
            Copy controllers => your/project_sails/api
            Copy views/*     => your/project_sails/views/
   Then: 
   $ cd your/project_sails/
   $ sails lift

   More info: https://github.com/juliandavidmr/sails-inverse-model
   ---------------------------------------------------------------
  Options:
   -u, --user        User of database
   -p, --pass        Password of database
   -d, --database    Database name
   -h, --host        Host server               Default: localhost
   -m, --models      Folder output models      Default: Folder actual
   -c, --controllers Folder output controllers Default: Folder actual
   -v, --views       Folder output views       Default: Folder actual (Experimental)
   -t, --type        Type gestor database: mysql|postgres|mongodb  Default: mysql
   -s, --schema      (Only PostgreSQL) Schema database postgres: Default: public
   -f, --file        (Only MySQL) .sql file path entry (Experimental)


  ====================== Individual generation ==================
  You can quickly generate a model, a controller, a view or these three at the same time.
  # Generate model
  $ sails-inverse-model -g model --name Pet -a "name:string:r:u owner:string"

  # Generate Controller
  $ sails-inverse-model -g controller --name Pet -a "name:string:r:u owner:string"

  # Generate View
  $ sails-inverse-model -g view --name Pet -a "name:string:r owner:string"

  # Generate all (Model, View and Controller)
  $ sails-inverse-model -g all --name Pet -a "name:string:r:k owner:string"

  Where:
  --------------------------------------------
  |Param | Description   |     Example       |
  |------|---------------|-------------------|
  |   r  | Required      | catname:string:r  |
  |   u  | Unique        | catname:string:u  |
  |   a  | Autoincrement | index:integer:a   |
  |   k  | Primary Key   | index:integer:k   |
  --------------------------------------------
  You can also set all three parameters at the same time, for example: index:integer:a:u:r

MySQL

sails-inverse-model -u root -p root -d mydbmysql -m -v -c

MySQL from file .sql

sails-inverse-model -f /your/path/to/script.sql -m -v -c

PostgreSQL

sails-inverse-model -u postgres -p root -d almacen -t pg -m -v -c

MongoDB

sails-inverse-model -d blog_db -t mg -m -v -c

Import

Install package

npm install sails-inverse-model --save

Generate from MySQL

var sim = require('sails-inverse-model');

var config = {
  host: "localhost",
  database: "almacen",
  user: "root",
  pass: "root",
  port: 3306
}

var folder_controllers = "/your/project/sails/api/"; //if folder_models == "" then: no generate controllers
var folder_models = "/your/project/sails/api/"; //if folder_models == "" then: no generate models
var folder_views = "/your/project/sails/"; //if folder_models == "" then: no generate views

sim.generatemy(config, folder_models, folder_controllers, folder_views, plurallang);

Generate from PostgreSQL

var sim = require('sails-inverse-model');

var config = {
  host: "localhost",
  database: "example",
  user: "postgres",
  pass: "root",
  port: 5432,
  schema: "public"
}

var folder_controllers = "/your/project/sails/api/"; //if folder_models == "" then: no generate controllers
var folder_models = "/your/project/sails/api/"; //if folder_models == "" then: no generate models
var folder_views = "/your/project/sails/"; //if folder_models == "" then: no generate views

sim.generatepg(config, folder_models, folder_controllers, folder_views, plurallang);

Generate from MongoDB

var sim = require('sails-inverse-model');

var folder_controllers = "/your/project/sails/api/"; //if folder_models == "" then: no generate controllers
var folder_models = "/your/project/sails/api/"; //if folder_models == "" then: no generate models
var folder_views = "/your/project/sails/"; //if folder_models == "" then: no generate views

//                host       port         database           views         models        controllers
sim.generatemg('localhost', 27017, 'my_name_collection', folder_views, folder_models, folder_controllers);

Then navigate to the output folder and can find the js generated.

Contributions