Golang POGO domain model generator with DB CRUD support
Specify your domain model in XML, run it through the model generator and it will spit out a go definition plus a DB Crud layer (using MYSQL).
Example:
<imports>
<package no_persistence="true">uuid github.com/satori/go.uuid</package>
<package>time</package>
</imports>
<define type="class" name="Resource">
<guid name="ResourceID" />
<guid name="UserID" />
<guid name="EntityID" />
<string name="Filename" />
<string name="Path" />
<string name="MimeType" />
<bool name="IsEntityResource" />
<bool name="External" />
<time name="CreateDate" />
<time name="LastUpdateDate" />
<list type="byte" name="Data" />
</define>
You can specify additional imports in the 'imports' section. These will be placed on top of your GO datamodel file.
An XML document can hold many classes - each document will generate on GO file (there is an experimental option to split per class but - but I never use it).
Use the tool like:
ModelGenerator 2.2 - XML Data Model to Language structure converter
Usage: modelgenerator [-sv] [-p <class>] [-f <num>] [-o <file/dir>] <inputfile>
General Options
-f : From Version, generates any class/field matching >= specified version (0 means as virgin)
-p : Generate persistence (use optional 'class' to specifiy which class for persistence, or '-' for all - default)
-s : split each type in separate file
-l : specify output language (go/cpp/ts)
-m : override model member prefix (use '!' to drop it)
Domain Model Options
-c : generate convertes (to/from XML/JSON)
-g : disable getters/setters
-o : specify output model file or '-' for stdout (default)
-M : generate marshalling code (defaults: CPP: off, GO: on, Typescript: on)
DB Layer Options
-P : Table name prefix (default is 'nagini_se_')
-d : Generate drop statements before create (default = false)
-O : specify output database go file or dir (if split in multiple files is true), default is 'db.go'
-v : increase verbose output (default 0 - none)
-h : this page
inputfile : XML Data Model definition file
modelgenerator -v -g file.xml
modelgenerator -v -p - -c file.xml -o file.go
When using '-p -' (for all classes) the generator will bail if it can't generate the class. This typically happens for classes with a single item (like list definitions). Such classes should have the 'nopersist="true"' attribute.
It is advisable to run GOIMPORTS on the generated file - that way you can have a common set of imports in your domain and GOIMPORTS will strip what's not used. The tool support type-mapping from the XML definition to GO and MYSQL types. Like:
<gotypemappings>
<map from="guid" to="uuid.UUID" />
<map from="time" to="time.Time" />
</gotypemappings>
This allows the 'type' declaration to be transformed properly when generating the GO code. The tool allows for language extensions but so far only GO is supported.
Following ROOT tags are supported:
- include - allow include of other documents to this document (this is a simple 'add' from the included document)
- dbtypemappings - type mapping control for DB CRUD generator
- gotypemappings - type mapping controil for GO language
- dbcontrol - specification of common attributes for the DB layer (user, schema, etc..)
- imports - GO language imports
- define - definintion of a data type (enum or class)
The current CPP marshalling code depends on a unreleased marshalling library. Therefore the marshalling code generator is switched off at the moment. You can switch generation of this code with '-M' if you want. I will try to release the marshalling code once it's in a stable state.