Setting constant values in a type


Did you know you can use post default for setting constant values in a type?
For example:

type TargetType {
  // standard atmosphere constant
  atm: Dimension post default "dimensionCreator('DIMENSION', 101,325, 'pascal')"

Note that dimensionCreator is an expression engine function that creates Dimension instances


What does post add to default keyword in that case ? Is post necessary here ? Are there others [KEYWORD] default available ?


I’m not aware of another case where some keyword is combined with default. To understand why you should use this option for default value check this thread:


Default Values

For entity types, “post default” should be used:

entity type X {

active: boolean post default false


For non-entity types, initializers should be used instead:

type X {

active: boolean = false


The initializer provides a default values, set in the object on creation. Post-default values are only set when the entity is saved, and only if there is no value provided.

Initializer Literals

Use JSON syntax for all initializers.

type X {

friend: User = { email: "" }


The type name need not be specified unless a more specific type is being instantiated, in which case it is specified with the “type” field:

type X {

boss: Identity = { type: "User", email: "" }


For map initializers, JSON (JS) syntax is used as well:

type X {

constants: map<string,int> = {pi:3, e:3}


Dates should be initialized with strings:

type X {

when: datetime = '2020-01-01T12:00:00Z'