Quick Start
This guide walks through a minimal model and common query operations.
1. Define your model
ballerina
import thambaru/bal_orm.orm;
import ballerina/time;
@orm:Entity {tableName: "users"}
public type User record {|
@orm:Id @orm:AutoIncrement
int id;
@orm:Column {length: 255, nullable: false}
string email;
string name;
@orm:CreatedAt
time:Utc createdAt;
@orm:UpdatedAt
time:Utc updatedAt;
|};2. Initialize the ORM client
ballerina
orm:Client db = check new ({
provider: orm:MYSQL,
host: "localhost",
port: 3306,
user: "root",
password: "password",
database: "myapp"
});3. Create data
ballerina
var created = check db.'from(User).create({
email: "alice@example.com",
name: "Alice"
});4. Read data
ballerina
var rows = check db.'from(User)
.'where({email: {contains: "@example.com"}})
.orderBy({createdAt: orm:DESC})
.take(5)
.findMany();5. Update and delete
ballerina
check db.'from(User)
.'where({id: {equals: 1}})
.update({name: "Alice Smith"});
check db.'from(User)
.'where({id: {equals: 1}})
.delete();6. Close the client
ballerina
check db.close();