Tutorial
The imagine compiler generates code from spec files where the user can indicate different project settings and datamodel specifications. Each spec file can contain a first section with project settings and a second section with datamodel spec.
Project settingsProject settings are written in yaml format:
A default project settings is created when the user runs
imagine create
command, with default values for the specified
framework.
Datamodel spec
Datamodel specification is written according to the following syntax, where
each model is specified indicating an identifier (a string starting with a leter,
followed by any number of letters, numbers or '
), a primary key and a list
of fields:
Each field must have a <fieldtype>
,
which can be either Int
, Str
or Datetime
. Each field must have a list
(possibly empty) of options and constraints.
The supported options are: - default <val>
where <val>
is the default value for the field.
The supported constraints are - unique
- nullable
- maxlength <int>
- range <int> <int>
- choice [x_1, ..., x_n]
Many-to-one and many-to-many relations are specified in this way:
the references (as <identifier>
) are the names of the relation in each model.
For instance, Relation ManyToOne Model0 as ref0 Model1 as ref1
means that the
model Model0
has a field ref0
which is an instance of Model1
, and Model0
has a filed ref1
which is a collection of instances of Model0
. Reference
identifiers can't clash with model fields. In the second example, we specify
the foreign key for the relation, and the identifier must reference a
unique
field.