Annotations Reference
Entity-level annotations
| Annotation | Payload | Description |
|---|---|---|
@orm:Entity | EntityConfig | Maps record to table, schema, and engine |
@orm:Index | IndexConfig (repeatable) | Adds single/composite index metadata |
EntityConfig
| Field | Type | Default |
|---|---|---|
tableName | string? | inferred from model name |
schema | string? | none |
engine | orm:Engine? | inherited from client context |
IndexConfig
| Field | Type | Default |
|---|---|---|
name | string? | auto-generated |
columns | string[] | required |
unique | boolean | false |
Field-level annotations
| Annotation | Payload | Description |
|---|---|---|
@orm:Id | Marker | Primary key marker |
@orm:AutoIncrement | Marker | Auto-increment marker |
@orm:Column | ColumnConfig | Column mapping options |
@orm:Relation | RelationConfig | Relation metadata |
@orm:CreatedAt | Marker | Creation timestamp marker |
@orm:UpdatedAt | Marker | Update timestamp marker |
@orm:Ignore | Marker | Exclude field from persistence |
ColumnConfig
| Field | Type | Default |
|---|---|---|
name | string? | field name |
'type | string? | inferred from field type |
length | int? | none |
nullable | boolean | true |
unique | boolean | false |
'default | anydata? | none |
RelationConfig
| Field | Type | Default |
|---|---|---|
'type | orm:RelationType? | required in practice |
model | string? | inferred |
references | string[]? | none |
foreignKey | string[]? | none |
joinTable | string? | none |
Example
ballerina
@orm:Entity {tableName: "users"}
@orm:Index {columns: ["email"], unique: true}
public type User record {|
@orm:Id @orm:AutoIncrement
int id;
@orm:Column {nullable: false, length: 255}
string email;
@orm:Relation {'type: orm:ONE_TO_MANY}
Post[]? posts;
|};