Turso (turso v0.1.1)

View Source

Elixir client library for Turso Cloud Platform API.

Turso provides a distributed SQLite database platform. This library implements a complete client for the Turso Platform API, allowing you to manage databases, groups, organizations, and more.

Usage

# Initialize a client
client = Turso.init(api_token, organization: "my-org")

# Create a database
{:ok, database} = Turso.create_database(client, "my-app-db", group: "production")

# List databases
{:ok, databases} = Turso.list_databases(client)

See the individual modules for detailed documentation:

Summary

Types

api_result(success_type)

@type api_result(success_type) :: {:ok, success_type} | {:error, Turso.Error.t()}

database()

@type database() :: map()

group()

@type group() :: map()

location()

@type location() :: map()

organization()

@type organization() :: map()

t()

@type t() :: %Turso{
  api_token: String.t(),
  base_url: String.t(),
  organization: String.t() | nil,
  req: Req.Request.t()
}

token()

@type token() :: map()

Functions

create_database(client, name, opts \\ [])

@spec create_database(t(), String.t(), keyword()) :: api_result(map())

Creates a new database. See Turso.Databases.create/3.

create_database_token(client, database_name, opts \\ [])

@spec create_database_token(t(), String.t(), keyword()) :: api_result(map())

Creates a database token. See Turso.Databases.create_token/3.

create_group(client, name, opts \\ [])

@spec create_group(t(), String.t(), keyword()) :: api_result(map())

Creates a new group. See Turso.Groups.create/3.

delete_database(client, name)

@spec delete_database(t(), String.t()) :: api_result(map())

Deletes a database. See Turso.Databases.delete/2.

init(api_token, opts \\ [])

@spec init(
  String.t(),
  keyword()
) :: t()

Initialize a new Turso client.

Creates a client struct with the provided API token and options. The client contains a pre-configured Req HTTP client for making API requests.

Options

  • :organization (String.t/0) - Default organization slug for API calls. Can be overridden per function.

  • :base_url (String.t/0) - Base URL for Turso API requests. The default value is "https://api.turso.tech/v1".

  • :receive_timeout (timeout/0) - HTTP receive timeout in milliseconds. The default value is 30000.

Examples

client = Turso.init("your-api-token")
client = Turso.init("your-api-token", organization: "my-org")

Returns

A Turso.t() client struct ready for API operations.

list_databases(client)

@spec list_databases(t()) :: api_result(map())

Lists all databases for the organization. See Turso.Databases.list/2.

list_groups(client)

@spec list_groups(t()) :: api_result(map())

Lists all groups. See Turso.Groups.list/2.

list_locations(client)

@spec list_locations(t()) :: api_result([map()])

Lists all available locations. See Turso.Locations.list/1.

list_organizations(client)

@spec list_organizations(t()) :: api_result(map())

Lists all organizations. See Turso.Organizations.list/1.

retrieve_database(client, name)

@spec retrieve_database(t(), String.t()) :: api_result(map())

Retrieves a specific database. See Turso.Databases.retrieve/2.