Installation

This page covers package setup and database configuration options.

Add the package

Use the Ballerina CLI:

bash
bal add thambaru:bal_orm

Or add it manually to Ballerina.toml:

toml
[dependencies]
thambaru.bal_orm = "0.1.0"

Choose a database

Ballerina ORM supports:

  • MySQL (orm:MYSQL)
  • PostgreSQL (orm:POSTGRESQL)

Configure the client

You can configure orm:Client with explicit fields:

ballerina
import thambaru/bal_orm.orm;

orm:Client db = check new ({
    provider: orm:MYSQL,
    host: "localhost",
    port: 3306,
    user: "root",
    password: "password",
    database: "myapp"
});

Or use a connection URL:

ballerina
orm:Client db = check new ({
    url: "postgresql://postgres:password@localhost:5432/myapp"
});

Connection pooling

ballerina
orm:Client db = check new ({
    provider: orm:POSTGRESQL,
    host: "localhost",
    user: "postgres",
    password: "password",
    database: "myapp",
    connectionPool: {
        maxPoolSize: 10,
        maxLifeTime: 1800
    }
});

Local database with Docker (example)

bash
# MySQL

docker run --name bal-orm-mysql \
  -e MYSQL_ROOT_PASSWORD=password \
  -e MYSQL_DATABASE=myapp \
  -p 3306:3306 \
  -d mysql:8

# PostgreSQL

docker run --name bal-orm-pg \
  -e POSTGRES_PASSWORD=password \
  -e POSTGRES_DB=myapp \
  -p 5432:5432 \
  -d postgres:16

Next step

Continue with Quick Start.