Client Reference
The orm:Client is the database execution boundary in Ballerina ORM.
Type: ClientConfig
ballerina
public type ClientConfig record {|
Engine? provider = ();
string? url = ();
string? host = ();
int? port = ();
string? user = ();
string? password = ();
string? database = ();
mysql:Options? mysqlOptions = ();
postgresql:Options? postgresqlOptions = ();
sql:ConnectionPool? connectionPool = ();
|};provider and URL/host fields are used to normalize connectivity for MySQL and PostgreSQL.
Constructor
ballerina
public function init(ClientConfig config) returns error?Core methods
getConfig()
ballerina
() returns NormalizedClientConfiggetNativeClient()
ballerina
() returns NativeDbClientquery(plan)
ballerina
(QueryPlan) returns stream<record {}, sql:Error?>|SchemaError|ClientError|sql:Errorexecute(plan)
ballerina
(QueryPlan) returns sql:ExecutionResult|SchemaError|ClientError|sql:ErrorrawQuery(text, params)
ballerina
(string, anydata[] = []) returns stream<record {}, sql:Error?>|ClientError|sql:ErrorrawExecute(text, params)
ballerina
(string, anydata[] = []) returns int|ClientError|sql:Errormodel(modelType)and'from(modelType)
ballerina
(typedesc<anydata>) returns ExecutingQueryBuilderclose()
ballerina
() returns error?Error shape
ClientError uses the following detail payload:
ballerina
public type ClientErrorDetail record {|
string code;
string message;
string? fieldName = ();
|};Example
ballerina
orm:Client db = check new ({
provider: orm:POSTGRESQL,
host: "localhost",
user: "postgres",
password: "password",
database: "myapp"
});
var rows = check db.'from(User).findMany();
check db.close();