Custom types are edited in Haxe enum syntax.
Default editor: https://github.com/kevinresol/exp-db-editor
The editor will export 2 files: schema.json
& content.json
schema.json
contains the table (columns) and custom type definitions of the databasecontent.json
contains that actual data for each table
Add an init macro to build the types at compile time:
--macro exp.db.util.TypeBuilder.build('schema.json', 'foo.bar')
The first argument is the path to the schema.json
file generated by the editor. It should be relative to project class paths as it is resolved by Context.resolvePath()
.
The second argument is the package of the generated types.
This macro will generate 3 modules (using foo.bar
as example package):
This type has a static function parse(content:String):Outcome<Database, Error>
which parses the content of content.json
into a Database
instance.
Instance fields of this type are the table names defined in the editor, typed as Array<ReferencedTable>
(no Identifier field) or Map<String, ReferencedTable>
(has Identifier field)
This module contains all the generate Table types.
They are generated as:
typedef TableNameWithFirstCharacterCapitalized = {
columnName1:ColumnType1,
// ...
}
ColumnType
is generated as follow:
Identifier
->String
Integer
->Int
Text
->String
Boolean
->Bool
Enumeration
-> A generatedenum abstract(String)
SubTable
->Array<ReferencedTable>
(no Identifier field) orMap<String, ReferencedTable>
(has Identifier field)Ref
->tink.core.Lazy<ReferencedTable>
Custom
-> See Types below
This module contains all the generated Custom types, as enum