MicroDSL
Content generator, takes the structure of any mysql database and automatically creates web forms, ORM models and many other custom content.
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 = // Mysql connect configvar config = user: 'root' password: 'root' host: 'localhost' database: 'project'
Step 2: Create file input (form.html.microdsl)
Register <%= TABLENAME %> <% for(var i=0; i< COLUMNS.length; i++) { %> <% } %>
Step 3: Start compilation
node test.js
Example output for a database table:
Register convocatoria
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
- Create CLI (separate project)
- More examples
Maintained by juliandavidmr