ZRM Model Declaration Changes
Abstract
This enhancement proposal removes the Groovy declaration in favor of an equivalent JSON-based declaration.
Rationale
ZRM grew up Groovy oriented. As such, the model declaration is in Groovy which is not the best solution for a fairly language neutral platform. By replacing the Groovy model declaration with a JSON one, we allow the developers from both Java, Groovy, and PHP camps to have a single story that makes sense across all languages.
In addition to simplifying the implementation, moving to JSON will make ZRM better prepared for when model declarations are done over HTTP.
Proposed changes
The proposed changes can be summarized by:
- Change valid
type attribute values and introduce the format attribute
- Change the model syntax to JSON instead of Groovy
- Change the file suffix from *.groovy to *.json
Type and format attributes
The current field names are useful in abstracting higher level of functionality in terms of validation and encapsulating a framework to extend the system. However, in terms of a programming model, they are not necessarily the way developers think about their data.
This proposal changes the
type attributes to more data type approach. For instance, rather than all the *Field strings used at field type values, replace them with boolean, string, date, date-time, time, and number.
The following table illustrates the changes made to the existing
type attribute and how the introduction of the
format attribute achieves the previous functionality of higher level field types:
| Existing type | New type | Format |
| BooleanField | boolean |
| CharField | string |
| DateField | date |
| DateTimeField | date-time |
| DecimalField | number | |
| EmailField | string | email |
| FloatField | number |
| IntegerField | number |
| TextField | string |
| TimeField | time |
| USStateField | string | region |
| USPhoneField | string | phone |
JSON model declaration syntax
Currently, a simple model declaration in Groovy is as follows:
// /app/models/person.groovy
fields = [
first_name: [type: 'CharField'],
birth_date: [type: 'DateField'],
]
This proposal calls to change this Groovy-based data structure to JSON as follows:
// /app/models/person.json
fields = {
"first_name" : {"type": "string"},
"birth_date" : {"type": "date"}
}
Model file suffix
If the declaration syntax is changed to JSON, it only makes sense to change the file suffix to *.json as shown in the previous example.