Turso.Groups (turso v0.1.1)

View Source

Group management for Turso Cloud Platform.

Groups are logical containers for databases that share the same primary location and configuration. All databases within a group are replicated across the same set of locations.

Summary

Functions

Adds a location to a group for database replication.

Creates a new group in the organization.

Ensures a group exists, creating it if necessary.

Lists all groups for the organization.

Retrieves details of a specific group.

Types

api_result(success_type)

@type api_result(success_type) :: Turso.api_result(success_type)

group()

@type group() :: Turso.group()

Functions

add_location(client, group_name, location, opts \\ [])

@spec add_location(Turso.t(), String.t(), String.t(), keyword()) ::
  api_result(group())

Adds a location to a group for database replication.

This extends the group to replicate databases to an additional location, improving read performance for users in that region.

Options

  • :organization (String.t/0) - Organization slug. Overrides client default.

Examples

{:ok, group} = Turso.Groups.add_location(client, "production", "lhr")

Returns

  • {:ok, group()} - Updated group object
  • {:error, map()} - Error details

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

@spec create(Turso.t(), String.t(), keyword()) :: api_result(group())

Creates a new group in the organization.

If no location is specified, the API will automatically select the closest available location.

Options

  • :location (String.t/0) - Primary location for the group (e.g., 'iad', 'lhr'). If not specified, uses the closest location.

  • :organization (String.t/0) - Organization slug. Overrides client default.

Examples

# Basic group creation (auto-select location)
{:ok, group} = Turso.Groups.create(client, "production")

# Group with specific location
{:ok, group} = Turso.Groups.create(client, "production", location: "iad")

Returns

  • {:ok, group()} - Created group object
  • {:error, map()} - Error details

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

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

Deletes a group.

Warning: You cannot delete a group that contains databases. All databases in the group must be deleted first.

Options

  • :organization (String.t/0) - Organization slug. Overrides client default.

Examples

{:ok, _} = Turso.Groups.delete(client, "old-group")

Returns

  • {:ok, map()} - Deletion confirmation
  • {:error, map()} - Error details

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

@spec ensure_exists(Turso.t(), String.t(), keyword()) ::
  {:ok, :exists | :created} | {:error, map()}

Ensures a group exists, creating it if necessary.

This is a utility function that checks if a group exists and creates it if it doesn't. This is useful when you want to ensure a group is available before performing other operations.

Options

  • :location (String.t/0) - Primary location for the group if it needs to be created.

  • :organization (String.t/0) - Organization slug. Overrides client default.

Examples

# Ensure group exists (auto-select location if creation needed)
{:ok, :exists} = Turso.Groups.ensure_exists(client, "production")

# Ensure group exists with specific location
{:ok, :created} = Turso.Groups.ensure_exists(client, "production", location: "iad")

Returns

  • {:ok, :exists} - Group already existed
  • {:ok, :created} - Group was created
  • {:error, map()} - Error details

list(client, opts \\ [])

@spec list(
  Turso.t(),
  keyword()
) :: api_result([group()])

Lists all groups for the organization.

Options

  • :organization (String.t/0) - Organization slug. Overrides client default.

Examples

# List groups using client's default organization
{:ok, groups} = Turso.Groups.list(client)

# List groups for a specific organization
{:ok, groups} = Turso.Groups.list(client, organization: "other-org")

Returns

  • {:ok, list(group())} - List of group objects
  • {:error, map()} - Error details

remove_location(client, group_name, location, opts \\ [])

@spec remove_location(Turso.t(), String.t(), String.t(), keyword()) ::
  api_result(group())

Removes a location from a group.

Warning: You cannot remove the primary location of a group. At least one location must remain.

Options

  • :organization (String.t/0) - Organization slug. Overrides client default.

Examples

{:ok, group} = Turso.Groups.remove_location(client, "production", "lhr")

Returns

  • {:ok, group()} - Updated group object
  • {:error, map()} - Error details

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

@spec retrieve(Turso.t(), String.t(), keyword()) :: api_result(group())

Retrieves details of a specific group.

Options

  • :organization (String.t/0) - Organization slug. Overrides client default.

Examples

{:ok, group} = Turso.Groups.retrieve(client, "production")

Returns

  • {:ok, group()} - Group details
  • {:error, map()} - Error details