MicroDSL

Content generator, takes the structure of any mysql database and automatically creates web forms, ORM models and many other custom content.

MIT License

Downloads
14
Stars
5
Committers
1

MicroDSL

Content generator, takes the structure of any mysql database and automatically creates web forms, ORM models and many other custom content.

See Examples

Install

Using npm

npm install microdsl --save

Using yarn

yarn add microdsl

Example

Automatically building a simple web form

Step 1: Import package and connect your database

// test.js

var microdsl = require('microdsl')

// Mysql connect config
var config = {
  user: 'root',
  password: 'root',
  host: 'localhost',
  database: 'project'
}

microdsl(config, './form.html.microdsl').then(compiled => {
  console.log(compiled)
  /*
    [
      'here the content of your generated file',
      'here the content of your 2° generated file',
      ...
    ]
  */
})

Step 2: Create file input (form.html.microdsl)

Register <%= TABLENAME %>

<form action="/<%= TABLENAME %>" method="post">
  <% for(var i=0; i< COLUMNS.length; i++) { %>
    <input type="text" name="<%= COLUMNS[i].name %>">
  <% } %>

  <input type="button" value="Send">
</form>

Step 3: Start compilation

node test.js

Example output for a database table:

Register convocatoria
<form action="/convocatoria" method="post">
  <input type="text" name="id">
  <input type="text" name="nombre">
  <input type="text" name="descripcion">
  <input type="text" name="fecha">
  <input type="button" value="Send">
</form>

API

MicroDSL has global variables that can be called from the input files

Variable Description Content structure
TABLENAME Name of the table string type - 'person'
COLUMNS Columns of the current table array type - [{ "Type": "varchar(64)","Null": "NO", "Key": "", "Default": null, "Extra": "", "name": "nombre" }, ...]
RELS Relations of the current table (foreign keys) ['role.id', ...]

If you want to know more about the compilation syntax, see EJS

Functions

Function Description Example
to_sequelize returns the equivalent MySQL object type in Sequelize ORM <%= to_sequelize('VARCHAR') %>
to_waterline returns the equivalent MySQL object type in Waterline ORM <%= to_waterline('VARCHAR') %>
is_required returns a boolean, true if the MySQL attribute is required <%= is_required(COLUMNS[i]) %>
tag render a html tag <%= tag('div', 'Here content', 'class=test') %>

Example of execution of a function:

<% for(var i=0; i< COLUMNS.length; i++) { %>
  '<%= COLUMNS[i].name %>': {
    type: '<%= to_waterline(COLUMNS[i]) %>',
    required: <%= is_required(COLUMNS[i]) %>
  },
<% } %>

TODO


Maintained by juliandavidmr