Turso.Locations (turso v0.1.1)

View Source

Location discovery for Turso Cloud Platform.

This module provides functions for discovering available locations where databases and groups can be placed, as well as finding the optimal location for your use case.

Summary

Functions

Lists available locations grouped by region.

Finds the closest location to the client.

Gets detailed information about a specific location.

Lists all available locations for database and group placement.

Types

api_result(success_type)

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

location()

@type location() :: Turso.location()

Functions

by_region(client)

@spec by_region(Turso.t()) :: api_result(map())

Lists available locations grouped by region.

This is a convenience function that organizes locations by their geographic region (e.g., "North America", "Europe", "Asia-Pacific").

Examples

{:ok, regions} = Turso.Locations.by_region(client)

Returns

  • {:ok, map()} - Locations grouped by region
  • {:error, map()} - Error details

Example Return Value

%{
  "North America" => [
    %{"code" => "iad", "name" => "Washington, D.C. (IAD)"},
    %{"code" => "ord", "name" => "Chicago, IL (ORD)"}
  ],
  "Europe" => [
    %{"code" => "lhr", "name" => "London (LHR)"},
    %{"code" => "ams", "name" => "Amsterdam (AMS)"}
  ]
}

closest(client)

@spec closest(Turso.t()) :: api_result(String.t() | map())

Finds the closest location to the client.

This function queries the Turso region service to determine the optimal location based on network latency from the client's current position.

Examples

{:ok, closest} = Turso.Locations.closest(client)

Returns

  • {:ok, String.t() | map()} - Closest location code or details

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

Notes

This function uses a different endpoint (region.turso.io) that doesn't require authentication and determines the closest region based on the request's origin.

get(client, location_code)

@spec get(Turso.t(), String.t()) :: api_result(location())

Gets detailed information about a specific location.

Examples

{:ok, location} = Turso.Locations.get(client, "iad")

Parameters

  • client - The Turso client
  • location_code - The location code (e.g., "iad", "lhr")

Returns

  • {:ok, location()} - Location details
  • {:error, map()} - Error details

list(client)

@spec list(Turso.t()) :: api_result([map()])

Lists all available locations for database and group placement.

Examples

{:ok, locations} = Turso.Locations.list(client)

Returns

  • {:ok, list(location())} - List of available locations with details
  • {:error, map()} - Error details

Location Object

Each location object typically contains:

  • code - Location code (e.g., "iad", "lhr", "nrt")
  • name - Human-readable name (e.g., "Washington, D.C. (IAD)")
  • type - Location type (e.g., "primary", "edge")