Skip to content
VerificationWould you notice if your agent drifted in production?Explore the 5-stage harness›
Specification Language

Types, Nullability & Enums

Aegil TypeSpec provides a statically typed schema language that maps primitive scalars, nullability semantics, and enums directly to Dart language types and PostgreSQL column definitions.

Aegil includes built-in primitive types specifically chosen for full-stack Dart and PostgreSQL applications:

TypeSpec Type Dart Type PostgreSQL Column Type Description
string String text UTF-8 variable-length text.
int int bigint 64-bit signed integer.
float double double precision 64-bit IEEE 754 floating-point number.
boolean bool boolean Logical true or false.
uuid UuidValue uuid Canonical 128-bit RFC 4122 Universally Unique Identifier.
utcDateTime DateTime timestamp with time zone Instant in UTC time with microsecond resolution.
namespace Helpdesk;
@entity({ table: "customers" })
model Customer {
@pk
id: uuid;
name: string;
loginCount: int;
satisfactionScore: float;
isActive: boolean;
createdAt: utcDateTime;
}

By default, every field in an Aegil model is non-nullable (required). To declare that a field can be null in Dart and NULL in the database, append a question mark ?:

model UserProfile {
@pk
id: uuid;
// Required field
username: string;
// Optional (nullable) fields
bio?: string;
avatarUrl?: string;
lastLoginAt?: utcDateTime;
}
  • Database constraints: Nullable fields compile to nullable columns (NULL). Non-nullable fields compile with a strict NOT NULL constraint.
  • Dart type promotion: The Serverpod ORM classes and Flutter models generate String?, DateTime?, etc., respecting Dart’s sound null safety.
  • Client validation: Missing non-nullable fields are rejected at the client boundary before any network request is sent.

To declare an array or list of values, use the bracket syntax T[]:

model Article {
@pk
id: uuid;
title: string;
tags: string[];
}

Lists compile to List<T> in Dart. When stored in PostgreSQL, scalar lists map to native PostgreSQL array types or JSONB serialization as managed by Serverpod.


Enums define a closed set of symbolic values. They ensure data integrity by guaranteeing that only recognized enum cases can be saved to the database or transmitted across the wire.

Declare enums at the top level of your spec file:

namespace Helpdesk;
enum TicketStatus {
Open,
InProgress,
Resolved,
Closed,
}
enum Priority {
Low,
Medium,
High,
Urgent,
}

Reference the enum directly as a field type:

@entity({ table: "tickets" })
model Ticket {
@pk
id: uuid;
title: string;
status: TicketStatus;
priority: Priority;
createdAt: utcDateTime;
}
  1. Serverpod Server: Aegil generates an enum in server/lib/src/generated/ with serialized values stored as integers or strings in PostgreSQL.
  2. Flutter Client: Aegil generates matching Dart enums in the client protocol (client/lib/api.dart), giving complete compile-time type safety in Flutter widgets:
// Flutter UI code
final ticket = state.items.first;
switch (ticket.status) {
case TicketStatus.Open:
return const Chip(label: Text('Open'), backgroundColor: Colors.blue);
case TicketStatus.InProgress:
return const Chip(label: Text('In Progress'), backgroundColor: Colors.orange);
case TicketStatus.Resolved:
return const Chip(label: Text('Resolved'), backgroundColor: Colors.green);
case TicketStatus.Closed:
return const Chip(label: Text('Closed'), backgroundColor: Colors.grey);
}