Query Builder
The ORM provides a fluent chain API through db.'from(ModelType).
Entry point
ballerina
var query = db.'from(User);From there, compose with modifiers before calling terminal operations.
Modifiers
| Method | Purpose |
|---|---|
'where(WhereInput) | Add filter conditions |
orderBy(OrderByInput) | Sort result sets |
skip(int) | Offset for pagination |
take(int) | Limit for pagination |
'select(SelectInput) | Select specific fields |
include(IncludeInput) | Eager-load relations |
'table(string) | Override inferred table name |
Terminal operations
| Method | Returns |
|---|---|
findMany() | `record [] |
findFirst() | `record ? |
findUnique() | `record ? |
count() | `int |
create(data) | `record |
createMany(dataList) | `record [] |
update(data) | `record |
updateMany(data) | `int |
upsert(createData, updateData) | `sql:ExecutionResult |
delete() | `record |
deleteMany() | `int |
Example chain
ballerina
var rows = check db.'from(User)
.'where({status: {equals: "ACTIVE"}})
.orderBy({createdAt: orm:DESC})
.skip(20)
.take(10)
.findMany();Why this style works
- query intent stays readable
- filters and pagination are composable
- same API surface applies to MySQL and PostgreSQL