Documentation for the "fields" JSON key.

Fields are a required JSONArray for each table that is defined. Field definitions are the basis for the interactions throughout the h2zero generated code. The type, length, nullability, uniqueness and other attributes determine how the various helper classes are generated.

Throughout the code generation, the field definitions are linked through lookups to ensure that the maximum amount of integration is met and to ensure that the naming and lookup of fields is consitent throughout the code.

"tables": [
	{
		"fields": [
			...
		]
	}
]
Please see the database naming conventions page for information recommended naming patterns for h2zero,

Allowable key/value pairs on the field JSON Object

JSON keyusageallowable valuesnotes
namemandatoryany valid MySQL field name valueEach field MUST have a name. It is recommended to use snake_case for field naming.
typemandatoryAny valid MySQL field type, the currently supported types are:
  • bigint
  • blob
  • boolean
  • bool
  • date
  • datetime
  • dec
  • decimal
  • double
  • float
  • int
  • longtext
  • mediumblob
  • mediumtext
  • timestamp
  • tinyint
  • varchar
The field types will automatically be mapped to the appropriate java type by h2zero.
lengthoptionalAny integer valueLengths are only required certain fields, varchar, tinyint(1) for example.
decimalLengthoptionalAny integer valueUsed in conjunction with decimal and float types, the number of decimal places for the field.
nullableoptionalAny boolean valueBy default, fields are always nullable, unless otherwise specified.
primaryoptionalAny boolean valueThis may occur only once on any table.
uniqueoptionalAny boolean valueWhether this field should be unique throughout the table - this will automatically generate a unique index on the field for the table.
indexoptionalany boolean valueWhether an index is created on the table in the SQL createion script.
defaultoptionalAny String value in single quotation marks (')This sets the default value on the field
foreignoptional (deprecated)A JSON ObjectThis allows the current key to reference a foreign key on another table, see the example below.
onUpdateoptionalOne of RESTRICT, CASCADE, SET NULL, NO ACTIONThe action to take for the mysql ON UPDATE, only valid if this field has a foreign key reference.
onDeleteoptionalOne of RESTRICT, CASCADE, SET NULL, NO ACTIONThe action to take for the mysql ON DELETE, only valid if this field has a foreign key reference.

Primary Key Field

Each table MUST have one, and only one primary key definition

"fields": [
	{ "name": "id_user", "type": "bigint", "nullable": false, "primary": true },
	{ "name": "id_user_type", "type": "bigint", "nullable": false, "index": true, "foreignKey": { "user_type.id_user_type" } },
	...
]

In the above example, the primary key definition in longer format is as follows:

{
	"name": "id_user", 
	"type": "bigint", 
	"nullable": false, 
	"primary": true
}
name
The name if the field - as a primary key, it is recommended that it be named thusly: id_<table_name>
type
For a primary key, the type MUST be a bigint
nullable
The primary key should never be null
primary
Indicating that the field is primary - this leads to indexes being placed automatically on this field

Foreign Key Reference

{
	"name": "id_user_type", 
	"type": "bigint", 
	"nullable": false, 
	"index": true, 
	"foreignKey": { "user_type.id_user_type" }
}
name
The name if the field
type
Since the foreign key references a primary key, the type MUST be a bigint
nullable
The foreign key may be null
index
Whether to create an index on the field.
foreignKey
This is a JSON Object that references the table and field of the referenced primary key.