Dabacog is the acronym for 'Database Code Generation' and comes as a command line interface (CLI).
____ __
/ __ \____ _/ /_ ____ __________ ____ _
/ / / / __ `/ __ \/ __ `/ ___/ __ \/ __ `/
/ /_/ / /_/ / /_/ / /_/ / /__/ /_/ / /_/ /
/_____/\__,_/_,___/\__,_/\___/\____/\__, /
/____/
Version 0.1.0 - Alpha
Usage: dabacog [-hnvV] -s=<source> [-t=<targets> [<targets> [<targets>]]]...
Example: dabacog --source ./app.dxd --targets sql code --verbose-logging
Dabacog CLI arguments:
-h, --help Show this help message and exit.
-n, --no-logging Disables logging to the console.
-s, --source=<source> Defines the description (Dxd) source file path.
-t, --targets=<targets> [<targets> [<targets>]]
Defines the targets to generate. Use 'd' or
'diagram', 's' or 'sql' and 'c' or 'code' as
values. The values can be combined space separated.
If no target is defined all targets are generated.
-v, --verbose-logging Enables verbose logging. Overrides the no-logging
option.
-V, --version Print version information and exit.
Most software projects have a data storage, and a data access layer where the access layer needs to communicate with the storage layer (typically a database) to perform CRUD operations. These operations, as well as the data access layer designs, are usually simple, repetitive and can be easily derived from a model describing the required data structures and their relations. Software developers often spend up to 30% (and more) of their time within a project with tasks related to CRUD and surrounding problems as testing, setting up the database schema, mapping database tables to entities, mapping entities to DTOs, and more...
All this makes the described problem an optimal candidate to be solved by code generation. And exactly that is what Dabacog is intending to achieve. To stay flexible, as not all problems are generic enough for a code generation approach, there will be an easy option to override or extend the generated code, both in order to use custom code for custom problems.
In the long term the vision is to support all major databases (with different SQL dialects) and all major programming languages, as well as database migration strategies to regard evolving database schema requirements in an application life-cycle.
-
Create a (Dabacog XML Description) Dxd file
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE dxd SYSTEM "dabacog.dtd"> <dxd name="Dabacog - Book Library Demo"> <config> <diagramsConfig diagramDatabaseOutputPath="./generated" diagramDatabaseTitle="Dabacog - Database Diagram - Book Library Demo" diagramDatabasePrimaryKeyFieldPorts="false" diagramDatabaseForeignKeyFieldPorts="true"/> <sqlConfig sqlDatabaseType="postgresql" sqlOutputPath="./generated" sqlGlobalSequence="true" sqlDropSchema="true"/> <codeConfig codeType="java" codeOutputPath="./generated" codePackageName="com.nilsign.dabacog.demo"/> </config> <entities> <class name="Genre"> <field type="string" name="Name" unique="true" /> </class> <class name="Author"> <field type="Book" relation="n..n"/> <field type="string" name="Name" fts="true"/> </class> <class name="Loan"> <field type="Book" relation="1..n"/> <field type="Customer" relation="1..n"/> <field type="date" name="Starts"/> <field type="date" name="Ends" indexed="true"/> <field type="date" name="Returns" nullable="true"/> <field type="boolean" name="DunningLetter" default="false"/> </class> <class name="Book"> <field type="Author" relation="n..n"/> <field type="Genre" relation="n..n"/> <field type="Location" relation="1..n"/> <field type="string" name="Name" fts="true"/> <field type="string" name="Isbn" unique="true"/> <field type="double" name="Price" nullable="true"/> </class> <class name="Customer"> <field type="Address" relation="1..1" nullable="true"/> <field type="Contact" relation="1..1"/> <field type="string" name="FirstName"/> <field type="string" name="LastName"/> </class> <class name="Address"> <field type="string" name="Street"/> <field type="string" name="Zipcode"/> <field type="string" name="City"/> </class> <class name="Location"> <field type="Book" relation="n..1"/> <field type="string" name="Floor" default="'warehouse'"/> <field type="string" name="Shelf" default="''"/> <field type="int" name="Position" default="-1"/> </class> <class name="BookOrder"> <field type="Book" relation="n..1" nullable="true"/> <field type="string" name="Floor" default="'warehouse'"/> <field type="string" name="Shelf" default="''"/> <field type="int" name="Position" default="-1"/> </class> <class name="Employee"> <field type="Employee" relation="1..1" nullable="true"/> <field type="Address" relation="1..1"/> <field type="string" name="FirstName" /> <field type="string" name="LastName"/> </class> <class name="Contact"> <field type="Customer" relation="1..1"/> <field type="string" name="Mobile" nullable="true"/> <field type="string" name="Home" nullable="true"/> <field type="string" name="Email"/> </class> </entities> </dxd>
-
Use the Dabacog CLI to generate the diagram, and the code
java jar dabacog.jar --source [dxd-file-path] --verbose-logging
Note, that Java 14+ needs to be used to run the dabacog.jar.
-
Dabacog generates automatically
-
A graph as png showing all database tables including their relations.
-
The database schema generation Sql script.
-
All Java entity classes, representing all Sql tables and their fields)
-
A Java database connector class [UNDER DEVELOPMENT]
-
All Java repositories containing all CRUD operations of any entity class [PLANNED]
-
Execute the maven 'package' phase to build a Dabacog fat jar including a valid manifest. The build dabacog.jar file can be found in your projects build 'target' folder.
To run the Dabacog fat jar from a command line navigate into the Dabacog project´s root folder and execute:
java -jar target/dabacog.jar --source ./src/main/resources/dev/library.dxd -verbose-logging
Ensure that the Java version is the same as used in the pom file, which is currently Java 14.
As the project started recently and as I am working on it in my spare time, do not expect steady progress. Anyhow, here are the major milestones of my project visions:
- Setup project. [DONE]
- Create a Xml parser and read the Xml model. [DONE]
- Convert the Xml model into the Dxd model. [DONE]
- Generate a relational database schema dot diagram and render it with Graphviz [DONE]
- Generate an entity class (code) dot diagram and render it with Graphviz [SKIPPED]
- Generate a Postgres database schema from the Dxd model. [DONE]
- Generate the Java entity source code from the Dxd model. [DONE]
- Generate the Java postgres database connector class source code for the DEV, QA and PROD environment. [IN PROGRESS]
- Generate the Java code and Sql queries required for all CRUD operations on all entities [PLANNED]
- Generate DTO classes out of many dxd model entity classes. [PLANED]
- Add support for database schema changes within an already running project, including support for data migration strategies, by the use of Flyway and/or Liquibase. [PLANNED]
- Support to migrate to Dabacog from already existing projects. [PLANNED]
- Support for MySQL, MariaDB, Oracle, AWS Aurora, SQLite, and Microsoft SQL Server [PLANNED]
- Support for Kotlin, C#, C++, C, Python, Go, Dart and more. [PLANNED]