Introduction
Dash uses the JSON format to describe the domain models. Each JSON file is called a (Dash) Model File.
Model Files are written according to Dash's own JSON specification which, throughout this documentation, is referred to as Dash JSON.
Warning
If you are not familiar with JSON, we recommend you to first learn the basics of JSON before proceeding. You need to be at least familiar with the JSON syntax and the supported data types.
Basic Rules of Dash JSON
- In Dash JSON, key/value pairs are used to define:
- The order in which the key/value pairs are defined in the Model File do not matter.
- Always use singular nouns for naming Entities.
- Dash uses Convention Over Configuration.
- Dash is case-insensitive.
Sections
At its root level, Dash JSON requires sections to be defined.
Only two sections are supported: the optional Configuration and the required Model object:
{
"Configuration": {
},
"Model": {
}
}
The Configuration object contains key/value pairs that allows you to configure the code generation.
The Model object contains the key/value pairs that represent Entities.
Entities
Entities are defined using key/value pairs directly under the Model object, like this:
{
"Model": {
"Person": {
}
}
}
In the above example, we defined the entity Person with 0 attributes.
Attributes
An attribute consists of a Name and a Data Type Declaration, and is defined using a key/value pair placed directly under an Entity object, like this:
{
"Model": {
"Person": {
"Name": "string",
"Age": "int"
}
}
}
In the above example, we have added the 2 attributes to the Person entity:
Nameof the data typestringAgeof the data typeint
Note
You can add constraints to the Data Type Declaration to limit the length, or enforce a regular expression. Please visit the Data Type Declaration to read more about this subject.
Important
Dash will automatically add an Id attribute for every Entity.
Please visit the Attributes documentation for more information.
Relationships
Dash supports 3 types of relationships:
| Relationship type | Dash Key/Value Pair |
|---|---|
| 1 to 1 | @@Has |
| 1 to Many | @@Has Many |
| Many to Many | @@Has Many And Belongs To |
1 to 1
To define a 1:1 relationship, simply add a @@Has object to your Entity.
Reference the Entity using an Array of Strings
This is the most concise way of defining a relationship. However, its limitation is that you cannot have multiple references to the same Entity.
{
"Model": {
"Person": {
"@@Has": ["Address"]
},
"Address": {
},
}
}
Reference the Entity using an Object and Key/Value pairs.
This is a bit more verbose but lets you define multiple relationships with the same Entity, and also naming the relationship.
{
"Model": {
"Person": {
"@@Has": {
"BillingAddress": "Address",
"ShippingAddress": "Address"
}
},
"Address": {
}
}
}
1 to Many
To define a 1 to Many relationship, add a @@Has Many object to your Entity.
Reference the Entity using an Array of Strings
{
"Model": {
"Person": {
"@@Has Many": ["Address"]
},
"Address": {
}
}
}
Reference the Entity using an Object and Key/Value pairs.
{
"Model": {
"Person": {
"@@Has Many": {
"Address": "Address"
}
},
"Address": {
}
}
}
Many to Many
To define a Many to Many relationship, add a @@Has Many And Belongs To object to your Entity.
Reference the Entity using an Array of Strings
{
"Model": {
"Person": {
"@@Has Many And Belongs To": {
"Address": "Address"
}
},
"Address": {
}
}
}
Reference the Entity using an Object and Key/Value pairs.
{
"Model": {
"Person": {
"@@Has Many And Belongs To": {
"Address": "Address"
}
},
"Address": {
}
}
}