A modal mapper processor by rust
this tool combine with three parts: the executable, the modal design file and the processor templates. you can store the modal file where ever you want, either the templates.
The executable usage:
USAGE:
rmmp [OPTIONS]
OPTIONS:
-h, --help Print help information
-m, --modal <FILE> the file path of modal design file
-p, --processor <STRING> the processor name
-t, --template <DICTIONARY> the directory path of template file
-V, --version Print version information
The modal file comes with several sections, each starts with a line
Entity_Name:
next with Field definition:
field_name: Field description
Before the Field definition, you can use @ to start a Processor data type mapping definition.
For example:
@postgres VARCHAR(32)
name: the name of user
and you can use a line starts with # to define the description for the entity.
next is a full example modal definition:
User :
# User infomation table
@pg varchar(32) PRIMARY KEY
@rust String
@typescript string
name: name of user
@pg int
@rust i32
@typescript number
age: age of user
The template file is all most same as Jinja2
next is a example for generate PostgreSQL CREATE TABLE SQLs:
{% for entity in entities %}CREATE TABLE {{ entity.name }} (
{% for fd in entity.fields %}{{fd.name}} {{ fd.types.pg.name }}{{ fd.ending }}
{% endfor %}
);
{% endfor %}
save the file in templates dir, with name same as the Processor.
Here if you use file name: db_sql.txt
You can use next command:
rmmp -m path_to_modal_file -t path_to_template_dir -p db_sql
this will print the output content:
CREATE TABLE User (
name varchar(32) PRIMARY KEY,
age int
);
CREATE TABLE Content (
title varchar(64),
poster varchar(32)
);
If you want save the output, use output redirection operator.
rmmp -m path_to_modal_file -t path_to_template_dir -p db_sql > db.sql
My write a template in template_sample/dot_graph.txt. It can generate a dot file for Graphivz
Your must install it first. In Mac:
brew install graphviz
You can download this file and put it in template folder.
First run with next command:
rmmp -m path_to_modal_file -t path_to_template_dir -p dot_graph > uml_pic.dot
then generate graphics:
dot -Tpng -o uml.png uml_pic.dot
then you get the PNG file