glibsql

Glibsql is a library for interacting with a hosted libSQL database such as Turso.

Glibsql helps construct a gleam/http/request for use with the Hrana over HTTP variant of libSQL, simply pass the constructed HTTP request into your http client of choice.

Types

HttpRequest encapsulates everything needed to execute a Hrana over HTTP libSQL request.

see new_http_request() to construct this record.

pub opaque type HttpRequest

Statement wraps the supported types of requests. A series of ExecuteStatement(String)s can be applied and be conditionally followed with a CloseStatement to close a connection when you are done with it.

pub type Statement {
  ExecuteStatement(sql: String)
  CloseStatement
}

Constructors

  • ExecuteStatement(sql: String)

    ExecuteStatement contains a query that will be executed as written. There is no SQL-injection protection provided, this type of statement should be used with a query builder that can render the built query to a prepared string.

  • CloseStatement

    CloseStatment will either close the connection used in the current pipeline or will close the connection referenced by the request baton. Note: connections will be automatically closed by Turso after a 10s timeout.

Functions

pub fn build(request: HttpRequest) -> Request(String)

Build the request using the previously provided values. Returns a gleam/http request suitable to be used in your HTTP client of choice.

pub fn clear_statements(request: HttpRequest) -> HttpRequest

Clear all statements from the request.

pub fn new_http_request() -> HttpRequest

Create a new Hrana over HTTP libSQL request.

Uses the builder pattern to construct everything necessary to send a request.

pub fn with_baton(
  request: HttpRequest,
  baton: String,
) -> HttpRequest

Set the baton from a previous connection to be reused.

pub fn with_database(
  request: HttpRequest,
  database: String,
) -> HttpRequest

Set the target database name. Calling this function multiple times will override the previous value.

Given a Turso databse URL like libsql://example-database-myorganization.turso.io The database name is “example-database”

pub fn with_host(
  request: HttpRequest,
  host: String,
) -> HttpRequest

Set the target database host. NOTE: this defaults to Turso’s turso.io Calling this function multiple times will override the previous value.

Given a Turso databse URL like libsql://example-database-myorganization.turso.io The host name is “turso.io”

pub fn with_organization(
  request: HttpRequest,
  organization: String,
) -> HttpRequest

Set the target database organization. Calling this function multiple times will override the previous value.

Given a Turso databse URL like libsql://example-database-myorganization.turso.io The database name is “myorganization”

pub fn with_path(
  request: HttpRequest,
  path: String,
) -> HttpRequest

Set the target database path on the host. NOTE: this defaults to Turso’s /v2/pipeline Calling this function multiple times will override the previous value.

pub fn with_statement(
  request: HttpRequest,
  statement: Statement,
) -> HttpRequest

Set a statement on the request. This function may be called multiple times, additional statements will be executed in order.

pub fn with_token(
  request: HttpRequest,
  token: String,
) -> HttpRequest

Set the Bearer token to access the database. Do not include Bearer . Calling this function multiple times will override the previous value.

Search Document