Overview DSL Reference
- 1 High Level Constructs
- 1.1 unit
- 1.2 object
- 1.3 persistent
- 1.4 enum
- 1.5 validator
- 2 Flow control
- 3 Primitive types
- 4 Annotations
- 4.1 @Role
- 4.2 @RoleName
- 4.3 @Restrict
- 4.4 @RolesAllowed
- 4.5 @Scheduled
- 4.6 @ReceiveSms
- 4.7 @Test
- 4.8 @{ID} eg. @FirstnameValidator
- 4.9 @OneToOne @ManyToOne @ManyToMany @OneToMany
- 4.10 @NotTracked
- 4.11 @OnSmsResultUpdate
- 4.12 @OnScheduledFunctionResultUpdate
- 5 Built In Objects
- 6 Date Built-in Functions
- 6.1 Date:addSeconds
- 6.2 Date:addDays
- 6.3 Date:addMonths
- 6.4 Date:daysBetween
- 6.5 Date:extract
- 6.6 Date:monthsBetween
- 6.7 Date:fromString
- 6.8 Date:fromTimeString
- 6.9 Date:secondsBetween
- 6.10 Date:now()
- 6.11 Date:today()
- 7 Integer Built-in Functions
- 8 Decimal Built-in Functions
- 9 Uuid Built-in Functions
- 9.1 Uuid:fromString
- 10 Mez (System) BIFs
- 11 Helium BIFs
- 11.1 platform
- 12 Math BIFs
- 13 String Built-in Functions
- 13.1 String:concat
- 13.2 String:split
- 13.3 String:length
- 13.4 String:substring
- 13.5 String:lower
- 13.6 String:upper
- 13.7 String:startsWith
- 13.8 String:endsWith
- 13.9 String:indexOf
- 13.10 String:join
- 14 Assert Built-in Functions
- 14.1 isEqual
- 14.2 isTrue
- 14.3 isFalse
- 14.4 isNull
- 14.5 isNotNull
- 14.6 isGreaterOrEqual
- 14.7 isLessOrEqual
- 14.8 isLess
- 14.9 isBoth
- 14.10 isEither
- 14.11 isNotEqual
- 15 Collections
- 16 Persistence BIFs
- 17 Trigger Function
- 17.1 beforeCreate
- 17.2 afterCreate
- 17.3 beforeDelete
- 17.4 afterDelete
- 17.5 beforeUpdate
- 17.6 afterUpdate
- 17.7 before
- 17.8 after
- 18 Atomic validators
- 19 Punctuation
- 20 Emails and SMS
- 21 CSV
- 22 Detailed Examples
High Level Constructs
unit
Units are groupings of functions and also variables.
They can be thought of as modules or namespaces. A Mezzanine script must have at least one unit.Unit must be followed with a unique unit name. Units are defined as follows.
unit MyUnit;
// Other code follows
string myVar;
int factorial(int x) {
if(x == 0 || x == 1) {
return 1;
} else if (x > 1) {
return factorial(x - 1);
}
return 0;
}
Heads Up Objects, enums and validators are global, so they can optionally be in a separate source code file without a unit.
object
Indicates the start of an object declaration. Must be followed by a unique object name and attribute block
object Person
{
string fname;
string sname;
int age;
}
persistent
Used to indicate that an object is persistent, must precede the object definition
persistent object Person
{
string fname;
string sname;
int age;
}
The _id attribute is also available from any persistent object. It is a uuid type.
enum
Used to declare an enumeration. Must be followed by an enumID (all caps and underscores)
enum GENDER
{
Male, Female
}
validator
Used to declare a field validator
validator FirstnameValidator
{
minlen(2); maxlen(250);
}
validator AgeValidator
{
minval(0);
}
Flow control
return
Returns the value of the expression that follows from a function
string getGreeting(string name)
{
return Strings:concat("Hello, ", name);
}
if / else
If statement
if(name == "Tom")
{
Mez:log("Hello Tom!");
}
else if (name == "Frank")
{
Mez:log("Hello Frank!");
}
else
{
Mez:log("Hi! Who are you?");
}
for
For loop
for(;;)
{
// Technically not possible, as iterations
// have a limit.
Mez:log("Infinite loop!");
}
for(int i = 1; i <= 10; i++)
{
Mez:log(i);
}
int i = 0;
for(; i < 10;)
{
Mez:log("While style loop!");
}
Primitive types
Type | Description |
|---|---|
| Integers |
| Strings |
| Numeric type e.g. 3.14 or 123 |
| Boolean values e.g. true or false |
| Date |
| Date and time |
| UUID type 4 (36 characters) |
| Void type |
| Binary values e.g. photos |
Annotations
@Role
Indicates that the persistent object is associated with a user role (using this annotation on an object automatically makes it persistent, so you don’t have to explicitly use the persistent keyword)
@Role("Manager")
object ManagerProfile
{
string fname;
string sname;
string title;
}
Heads UpAny persistent object that is annotated with @Role has these implicit attributes:
_firstNames
_nickName
_surname
@RoleName
Allows a custom role name to be displayed in the app that differs from role name specified in the data model and can be determined at runtime.
@RoleName
string getGymEmployeeRoleName(GymEmployee employee){
EN_GYM_EMPLOYEE_ROLE_TYPE employeeRoleType = employee.employeeType;
if(employeeRoleType == EN_GYM_EMPLOYEE_ROLE_TYPE.Gym_Trainer){
return "Trainer";
}
else if(employeeRoleType == EN_GYM_EMPLOYEE_ROLE_TYPE.Gym_Admin){
return "Gym Admin";
}
else{
return "Gym Employee";
}
}
@Restrict
Use this for users of Helium Android to be able to access specific types. The selector defines which objects of the requested type are accessible to the specified role. Objects that have relationships to objects included by an @Restrict are not automatically synchronized, they must have their own @Restrict annotations in order for the relationship to remain valid across the network. This technique is especially useful with many-to-many relationships, which can be used to reduce the amount of data synchronized to Helium Android users, and improve the user-experience of the application.
"Manager" indicates for which roles(s) it applies and all() is the selector.
@Restrict("Manager", all())
object EmployeeRecord
{
string fname;
string sname;
}
Types without an @Restrict annotation will not be synchronized to Helium Android users, and may cause null-pointer errors in your application.
@RolesAllowed
Specifies the access rights for a specific role on an object (like the previous annotation, this annotation implicitly makes the object persistent)
@RolesAllowed("Manager", "rw")
object EmployeeRecord
{
string fname;
string sname;
}
@Scheduled
Specifies a scheduled task to run at a certain interval
// Run at 2:15 AM every day
@Scheduled("15 2 * * *")
void foobar() { ... }
// Run at 06:00 every week-day (days 1 to 5)
@Scheduled("0 6 * * 1-5")
void foobar() { ... }
// Run every ten minutes
@Scheduled("*/10 * * * *")
void foobar() { ... }
To summarize the schedule string format:
"minute hour day-of-month month day-of-week"
@ReceiveSms
Indicates that a function can receive an SMS.
@ReceiveSms("Test description")
void receiveSmsNumberText(string number, string text) { ... }
@ReceiveSms("Test description")
void receiveSmsObjectText(Nurse nurse, string text) { ... }
@ReceiveSms("Test description")
void receiveSmsObjectNumberText(Nurse nurse, string number, string text) { ... }
@Test
Indicates that a function is a unit test.
@Test
void testIncrement(){
int i = 5;
i++;
Assert:isEqual(6, i, "Increment failed");
}
@{ID} eg. @FirstnameValidator
Annotations that start with @ followed by an ID, and that are used on object attributes are validator annotations. The ID value must be the same as any validator that is defined in the application:
object Person
{
@FirstnameValidator("validr.msg.fname")
string fname;
@SurnameValidator("validr.msg.sname")
string sname;
}