Configure field and model behavior with powerful attributes and validators.
Field attributes modify individual field behavior, constraints, and mapping.
| Attribute | Description |
|---|---|
@id | Marks field as primary key |
@auto | Auto-increment for integers |
@unique | Unique constraint |
@default(value) | Default value or function |
@updatedAt | Auto-update timestamp on modification |
@map("name") | Map to different column name |
@ignore | Exclude from generated client |
@relation(...) | Configure relation behavior |
@db.Type | Database-specific column type |
Model-level attributes (prefixed with @@) configure table-wide behavior.
| Attribute | Description |
|---|---|
@@map("name") | Map to different table name |
@@id([fields]) | Composite primary key |
@@unique([fields]) | Composite unique constraint |
@@index([fields]) | Create database index |
@@ignore | Exclude model from client |
@@schema("name") | PostgreSQL schema name |
Configure how models relate to each other with referential actions.
| Parameter | Description |
|---|---|
fields | Local foreign key field(s) |
references | Referenced field(s) on related model |
name | Relation name for disambiguation |
onDelete | Action when referenced record deleted |
onUpdate | Action when referenced key updated |
| Action | Behavior |
|---|---|
Cascade | Delete/update related records |
Restrict | Prevent delete/update if references exist |
NoAction | Similar to Restrict (database-dependent) |
SetNull | Set foreign key to NULL |
SetDefault | Set foreign key to default value |
Prax supports multiple ID generation strategies for different use cases. Choose the right one based on your requirements for uniqueness, sortability, and distribution.
Universally Unique Identifier - the industry standard for distributed systems. Generates 128-bit identifiers with extremely low collision probability.
UUID type support550e8400-e29b-41d4-a716-446655440000
Collision-resistant Unique Identifier - designed for horizontal scaling and distributed systems. Includes a timestamp component for rough time-ordering.
cjld2cjxh0000qzrmn831i7rn
Next-generation CUID with improved security. More unpredictable and shorter than the original. Recommended for new projects.
tz4a98xxat96iws9zmbrgj3a
Compact, URL-friendly unique IDs with customizable length. Perfect for short URLs, invite codes, and user-facing identifiers.
V1StGXR8_Z5jdHi6B-myT
nanoid(8): 5fX8pK2m
Universally Unique Lexicographically Sortable Identifier. Encodes creation timestamp, making IDs naturally sortable by time.
01ARZ3NDEKTSV4RRFFQ69G5FAV
| Type | Length | Sortable | URL-Safe | Best For |
|---|---|---|---|---|
uuid() |
36 | No | No (dashes) | Database PKs, APIs |
cuid() |
25 | Roughly | Yes | Distributed systems |
cuid2() |
24 | No | Yes | Security-sensitive apps |
nanoid() |
21* | No | Yes | Short URLs, invite codes |
ulid() |
26 | Yes | Yes | Time-series, logs, events |
* NanoID length is customizable
Validate string field content with built-in rules.
@validate.email - Email format@validate.url - URL format@validate.uuid - UUID format@validate.cuid - CUID format@validate.nanoid - NanoID format@validate.ulid - ULID format@validate.ip - IP address (v4 or v6)@validate.ipv4 - IPv4 only@validate.ipv6 - IPv6 only@validate.alpha - Letters only@validate.alphanumeric - Letters and numbers@validate.lowercase - Lowercase only@validate.uppercase - Uppercase only@validate.slug - URL slug format@validate.hex - Hexadecimal string@validate.base64 - Base64 encoded@validate.json - Valid JSON stringConstrain numeric field values with range and sign validators.
| Validator | Description |
|---|---|
@validate.min(n) | Minimum value (inclusive) |
@validate.max(n) | Maximum value (inclusive) |
@validate.range(min, max) | Value between min and max |
@validate.positive | Greater than zero |
@validate.negative | Less than zero |
@validate.nonNegative | Zero or greater |
@validate.nonPositive | Zero or less |
@validate.integer | Must be whole number |
@validate.multipleOf(n) | Must be multiple of n |
@validate.finite | Not Infinity or NaN |
Validate array fields for length and content constraints.
| Validator | Description |
|---|---|
@validate.minItems(n) | Minimum array length |
@validate.maxItems(n) | Maximum array length |
@validate.items(min, max) | Array length range |
@validate.unique | All items must be unique |
@validate.nonEmpty | At least one item required |
Validate datetime fields with temporal constraints.
| Validator | Description |
|---|---|
@validate.past | Must be in the past |
@validate.future | Must be in the future |
@validate.pastOrPresent | Not in the future |
@validate.futureOrPresent | Not in the past |
@validate.after("date") | After specific date |
@validate.before("date") | Before specific date |
Universal validators that work across different field types.
| Validator | Description |
|---|---|
@validate.required | Field must have a value (even if optional type) |
@validate.notEmpty | Non-empty string/array |
@validate.oneOf(...) | Value must be one of specified options |
@validate.custom("fn") | Custom validation function |
Auto-generate values for fields using built-in functions.
| Function | Description |
|---|---|
now() | Current timestamp |
uuid() | Random UUID v4 |
cuid() | Collision-resistant unique ID |
cuid2() | Next-gen CUID (more secure) |
nanoid() | URL-friendly unique ID |
nanoid(n) | NanoID with custom length |
ulid() | Sortable unique ID |
autoincrement() | Auto-incrementing integer |
dbgenerated("expr") | Database-generated expression |
Map fields to native database column types with @db.* attributes.
@db.Text - Unlimited text@db.JsonB - Binary JSON (indexable)@db.Uuid - Native UUID@db.Xml - XML type@db.Inet - IP address@db.Cidr - Network address@db.MacAddr - MAC address@db.Decimal(p, s) - Precise decimal@db.TinyText - 255 bytes@db.MediumText - 16 MB@db.LongText - 4 GB@db.TinyInt - Tiny integer@db.MediumInt - Medium integer@db.Year - Year type@db.VarChar(n) - Variable char@db.Charset("utf8mb4") - CharsetAdd metadata and documentation to fields using doc comments.
@hidden - Exclude from public API@internal - Admin-only access@sensitive - Mask in logs@readonly - Not settable via API@writeonly - Not in responses@deprecated - Mark as deprecated@since version - Version introduced@example value - Example value@label text - Display label@placeholder text - Input placeholderCreate different types of database indexes for query optimization.
| Type | Use Case | PG | MySQL | SQLite |
|---|---|---|---|---|
| {{ row.type }} | {{ row.use }} | {{ row.pg }} | {{ row.mysql }} | {{ row.sqlite }} |
* Requires pgvector extension
Vector indexes enable fast approximate nearest neighbor (ANN) search for AI/ML embeddings.
Requires the pgvector PostgreSQL extension.
| Operation | Description | Best For |
|---|---|---|
| {{ row.op }} | {{ row.desc }} | {{ row.best }} |