Model Definitions

Learn about defining data models, fields, and relationships.

To define and use data models in your project, create a directory named "πŸ“¦" in the root of your project. This directory will contain .yaml files that define the model names and fields, as well as the structure of container relationships.

The file name indicates both the name of the model as well as the model's type. The model's type is denoted with a specific emoji prefix.

Containers

To define model types that are in a container, place them into a directory named after the container type.

/πŸ“¦/🌐List.yaml
/πŸ“¦/List/🌐Note.yaml
/πŸ“¦/List/🌐Task.yaml

Fields

Field names must follow camel case, e.g. "camel" or "camelCase". All defined fields are indexed and required by default. Field definitions have a short form and long form, which may be mixed and matched as needed in the same file. .yaml files use spaces, not tabs, for indentation.

Short Form

To compactly use all defaults for a field, simply assign a field type immediately following the field name (all fields are required by default).

fieldName: string
otherField: boolean

Short form field definitions may be configured as optional with the '?' postfix:

optionalNumber?: integer

Long Form

To define additional field properties use the long form:

fieldName:
  type: string
  optional: true
  unique: true

otherField:
  type: boolean

Embedded Values

Global embedded values may be referenced as any other field type:

/πŸ“¦/🌐Order.yaml
contact: Contact

Local embedded values have field definitions inlined beneath the type:

/πŸ“¦/🌐Order.yaml
contact:
  type:
    first: string
    last: string
    email: string

This local embedded model type is ultimately accessed as:

order.contact = new Order.Contact().email('a@b.com')

Custom ID Prefixes

Models always have an automatically generated unique id field. A custom prefix may be added to all generated IDs for a particular model type. This prefix may be between 1-3 lowercase alpha characters (a-z), and optionally end with an underscore.

/πŸ“¦/🌐Product.yaml
πŸŽ›:
  prefix: prd_

# Field definitions

This will produce IDs for the Product model such as prd_QpvhSS8U34k