entity

An entity is similar to a record, but in addition has an associated key. Entities are typically used to model objects that are persisted and queryable.

An entity key can be defined in-place or refer to a declared key definition. When in-line keys are used, ALFA automatically creates a ‘Key’ type by suffixing the name of the entity.

Multiple assert blocks can be specified to perform validation.

entity Flight key( Id : uuid ) {
    Code : string
    Departure : time
}

A reference to an entity can be declared using name of the entity followed by Key, e.g. FlightKey. This can be thought of as a reference/pointer/foreign key to the entity.

entity Booking key( Code : string ) {
    Flight : FlightKey
}

entity declarations can use includes to extend its attributes.

entity Employee key EmployeeKey includes Taxpayer {
    Dept : string
}

key EmployeeKey {
    SSID : string
    Name : string
}

trait Taxpayer {
    TaxRef : string
}

A special case of an entity is when it has no key - a keyless declaration, in terms of persistence, it can be considered a singleton.

entity Countries {
    CapitalCities : map< string, string >
}