1.0.3 • Published 6 years ago

microdsl v1.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

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

VariableDescriptionContent structure
TABLENAMEName of the tablestring type - 'person'
COLUMNSColumns of the current tablearray type - [{ "Type": "varchar(64)","Null": "NO", "Key": "", "Default": null, "Extra": "", "name": "nombre" }, ...]
RELSRelations of the current table (foreign keys)['role.id', ...]

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

Functions

FunctionDescriptionExample
to_sequelizereturns the equivalent MySQL object type in Sequelize ORM<%= to_sequelize('VARCHAR') %>
to_waterlinereturns the equivalent MySQL object type in Waterline ORM<%= to_waterline('VARCHAR') %>
is_requiredreturns a boolean, true if the MySQL attribute is required<%= is_required(COLUMNS[i]) %>
tagrender 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

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago