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

Arguments are the arguments to a query, either anonymous or named. Only one of the types may be used per statement.

pub type Argument {
  AnonymousArgument(value: Value)
  NamedArgument(name: String, value: Value)
}

Constructors

  • AnonymousArgument(value: Value)

    AnonymousArguments are the anonymous arguments to a query specified using the ? syntax.

  • NamedArgument(name: String, value: Value)

    NamedArguments are the named arguments to a query specified using either the :name, the @name, or the $name syntax.

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.

See new_statement() to construct this record.

pub type Statement {
  ExecuteStatement(
    query: String,
    arguments: Option(List(Argument)),
  )
  CloseStatement
}

Constructors

  • ExecuteStatement(
      query: String,
      arguments: Option(List(Argument)),
    )

    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 actual column values.

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 integer values.

  • Real(value: Float)

    Reals are float values.

  • Boolean(value: Bool)

    Booleans are boolean values.

  • Text(value: String)

    Texts are text values.

  • Datetime(value: String)

    Datetimes are datetime values.

  • Blob(value: String)

    Blobs are blob values.

  • Null

    Nulls are null values.

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_arguments(statement: Statement) -> Statement

Clear all arguments from the ExecuteStatement.

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 new_statement() -> Statement

Create a new ExecuteStatement.

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

pub fn with_argument(
  statement: Statement,
  argument: Argument,
) -> Statement

Set an argument on the ExecuteStatement. This function may be called multiple times, additional arguments will be applied in order.

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_query(
  statement: Statement,
  query: String,
) -> Statement

Set a query on the ExecuteStatement. 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