ballerina/h2 package

Package overview

This package provides the functionality required to access and manipulate data stored in an H2 database.

Endpoint

To access a database, you must first create an endpoint, which is a virtual representation of the physical endpoint of the H2 database that you are trying to connect to. Create an endpoint of the H2 client type (i.e., h2:Client) and provide the necessary connection parameters. This will create a pool of connections to the given H2 database. A sample for creating an endpoint with an H2 client can be found below.

Database operations

Once the endpoint is created, database operations can be executed through that endpoint. This package provides support for creating tables and executing stored procedures. It also supports selecting, inserting, deleting, updating, and batch updating data. For more details on the supported actions, refer to the jdbc package. Details of the SQL data types and query parameters relevant to these database operations can be found in the documentation for the sql package.

Samples

Creating an endpoint

endpoint h2:Client testDB {
    path: "/home/ballerina/test/",
    name: "testdb",
    username: "SA",
    password: "",
    poolOptions: { maximumPoolSize: 5 }
};

The full list of endpoint properties can be found in the sql:PoolOptions type.

Records Summary

Record Description
ClientEndpointConfiguration

The Client endpoint configuration for h2 databases.

Objects Summary

Object Description
Client

Represents an H2 client endpoint.

public type ClientEndpointConfiguration

The Client endpoint configuration for h2 databases.

Field Name Data Type Default Value Description
host string

The host name of the database to connect (in case of server baased DB)

path string

The path of the database connection (in case of file baased DB)

port int 0

The port of the database to connect (in case of server baased DB)

name string

The name of the database to connect

username string

Username for the database connection

password string

Password for the database connection

poolOptions ballerina.sql:PoolOptions

Properties for the connection pool configuration

dbOptions map

DB specific properties

public type Client object

Represents an H2 client endpoint.