Skip to content

kevinresol/exp-db

Repository files navigation

Experimental Game Database

Custom Types

Custom types are edited in Haxe enum syntax.

Editor output

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 database
  • content.json contains that actual data for each table

How to use the generated json files

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):

foo.bar.Database

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)

foo.bar.tables.Tables

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 generated enum abstract(String)
  • SubTable -> Array<ReferencedTable> (no Identifier field) or Map<String, ReferencedTable> (has Identifier field)
  • Ref -> tink.core.Lazy<ReferencedTable>
  • Custom -> See Types below

foo.bar.types.Types

This module contains all the generated Custom types, as enum

About

Experimental Game Database

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages