Data Types
- Former user (Deleted)
- Jacques Marais
- Former user (Deleted)
- Charl Viljoen
Primitive Types
Type | Description |
---|---|
int | Integers |
string | Strings |
decimal | Numeric type e.g. 3.14 or 123 |
bigint | long integer |
bool | Boolean values e.g. true or false |
date | Date |
datetime | Date and time |
uuid | UUID type 4 (36 characters) |
void | Void type |
blob | Binary values e.g. photos |
json | Native type representing JSON objects. See here for more details. |
jsonarray | Native type representing JSON arrays. See here for more details. |
Variables of all primitive types are null after declaration, until assigned a value.
NOTE: Caveat to decimals
Note that there is some unexpected behaviour when working with decimals, that can cause issues in Helium Rapid applications. Take a look at this page to understand them a bit better: Understanding Decimals
Custom Objects
The object
keyword indicates the start of an object declaration. This must be followed by a unique object name and attribute block. Objects in the Helium DSL can be likened to structs in C.
object Person { string fname; string sname; int age; }
The persistent
keyword indicates that an object will be saved to the database. It appears before 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.
You will typically use this object as follows:
// this creates a new instance of Person Person person = Person:new(); // assign values to the fname and sname attributes person.fname = "Anon"; person.sname = "Incognito"; // pass it to a function sendWelcomeMessage(person);
Please note that a custom object instantiated and saved won't automatically update when another process changes its properties in the database, or when a relationship/link with another object is created but updated only on the other object and/or the database. In this case the aforementioned custom object needs to be refreshed/reinitialised to reflect the change.
Object Relationship Attributes
References (links) to other objects require one of the following attribute annotations:
@OneToOne
@ManyToOne
@ManyToMany
@OneToMany
For example, if one Person
record can be linked to many other Person
records via its children
attribute, and many Person
s can be linked to one House
via the home
attribute, the object is defined as:
object Person { string name; @OneToMany Person children; @ManyToOne House home; }
@NotTracked
By default, all changes to persistent objects will be logged in the change log. This is in turn used for syncing to the Journey mobile client. If there is not need for change tracking of a specific object, this logging can be turned of for the object in question by adding the @
NotTracked
object annotation:
@NotTracked persistent object Person { string name; int age; }
Enumerated Types
Declare an enumeration with the enum
keyword, followed by the enum's name (in all caps and underscores).
enum GENDER { Male, Female }
Blob attributes
When a blob attribute is added to an object, Helium also allows some implicit attributes that represent meta data for the blob to be queried. These are added internally to the model and can be queried from the app schema as well as the DSL.
persistent object MyObject { blob myBlob; }
The following fields can then be accessed from the DSL:
string fileName = myObject.myBlob_fname__; //This will return the string name of the file that was uploaded. string mimeType = myObject.myBlob_mtype__; //This will return the string MIME type of the file that was uploaded. int fileSize = myObject.myBlob_size__; //This will return the bigint value for the size of the file tha
Similarly, these implicit attributes can be queried from the app schema:
select myblob_fname__, myblob_mtype__, myblob_size__ from myobject;
Additional Mentions and References
- Sections Objects, Built-in Data Types, and Object Attribute Annotations in the Quick Reference.
- Basic objects appear in Lesson 1, and enums and primitives in Lesson 5 of the Tutorial.