glibsql/http

glibsql/http 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

Columns are the columns returned from a query, specifying the name and type.

pub type Column {
  Column(name: String, type_: String)
}

Constructors

  • Column(name: String, type_: String)

Error type for all possible errors returned by glibsql/http.

pub opaque type GlibsqlError

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

see new_request() to construct this record.

pub opaque type HttpRequest

HttpResponses are the response from a query, containing the columns, rows, and other metadata.

pub type HttpResponse {
  HttpResponse(baton: Option(String), results: List(Response))
}

Constructors

  • HttpResponse(baton: Option(String), results: List(Response))
pub type Response {
  ExecuteResponse(columns: List(Column), rows: List(Row))
  CloseResponse
}

Constructors

  • ExecuteResponse(columns: List(Column), rows: List(Row))
  • CloseResponse

Rows are the rows returned from a query, containing the values as a list.

pub type Row {
  Row(values: List(Value))
}

Constructors

  • Row(values: List(Value))

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.

Values are the actual column values within a row.

pub type Value {
  Integer(value: Int)
  Real(value: Float)
  Boolean(value: Bool)
  Text(value: String)
  Datetime(value: String)
  Blob(value: String)
  Null
}

Constructors

  • Integer(value: Int)

    Integers are the integer values returned from a query.

  • Real(value: Float)

    Reals are the float values returned from a query.

  • Boolean(value: Bool)

    Booleans are the boolean values returned from a query.

  • Text(value: String)

    Texts are the text values returned from a query.

  • Datetime(value: String)

    Datetimes are the datetime values returned from a query (as Strings).

  • Blob(value: String)

    Blobs are the blob values returned from a query (as Strings).

  • Null

    Nulls are the null values returned from a query.

Functions

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

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 decode_response(
  response: String,
) -> Result(HttpResponse, Nil)
pub fn new_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