Field Modifiers

Optional Fields

An optional field is one that can be missing. It represents a NULL-able SQL column.

   type Customer struct {
    firstName string optional
    lastName string
   } end

A field that is not optional is called a mandatory field. Mandatory fields must be given a value in insert statements.

Optional fields can be omitted, or be null. The following two lines are equivalent.

   insert Customer { lastName: 'smith'}
   insert Customer { firstName: null, lastName: 'smith'}

Unique Fields

A unique field is one whose value is unique across all the rows in the table. It represents SQL UNIQUE.

   type Product struct {
    serialNumber int unique
    name string
   } end

An error will occur if you try to insert the same value twice.

   insert Product {serialNumber:1001, name: 'Argos'}
   insert Product {serialNumber:1001, name: 'Betos'} //this statement will fail

Delia ensures that the rules you define for your type are followed. The database will never contain duplicate values for a unique field.

The optional and unique modifiers interact. See more …

Primary Key

Most struct types have a primary key. Use the primaryKey modifier to designate the primary key field. It is equivalent to PRIMARY KEY in SQL.

   type Product struct {
    serialNumber int primaryKey
    name string
   } end

Composite primary keys are not yet supported in Delia.


The serial modifiers creates an “auto-number” primary key (also called a ‘sequence’ in some databases)

   type Product struct {
    serialNumber int primaryKey serial
    name string
   } end

Only int and long fields can be serial. TBD how to define the serial starting number and range