Turso.Databases (turso v0.1.1)
View SourceDatabase operations for Turso Cloud Platform.
This module provides functions for managing databases within Turso organizations, including creating, listing, retrieving, deleting databases, and managing database access tokens.
Summary
Functions
Creates a new database in the specified group.
Creates a database token for libSQL connections.
Deletes a database.
Invalidates all database tokens for a database.
Lists all databases for the organization.
Retrieves details of a specific database.
Updates database configuration.
Types
@type api_result(success_type) :: Turso.api_result(success_type)
@type database() :: Turso.database()
@type token() :: Turso.token()
Functions
@spec create(Turso.t(), String.t(), keyword()) :: api_result(database())
Creates a new database in the specified group.
Ensures the group exists before creating the database. If the group doesn't exist, it will be created automatically.
Options
:group(String.t/0) - The group to create the database in. The default value is"default".:seed(map/0) - Seed configuration for database initialization.:size_limit(String.t/0) - Maximum database size (e.g., '500mb', '1gb').:is_schema(boolean/0) - Whether this database is a schema database. The default value isfalse.:organization(String.t/0) - Organization slug. Overrides client default.
Examples
# Basic database creation
{:ok, database} = Turso.Databases.create(client, "my-app-db")
# Database with specific group and options
{:ok, database} = Turso.Databases.create(client, "my-app-db",
group: "production",
size_limit: "500mb",
is_schema: false
)Returns
{:ok, database()}- Created database object{:error, map()}- Error details
@spec create_token(Turso.t(), String.t(), keyword()) :: api_result(token())
Creates a database token for libSQL connections.
Database tokens are used to authenticate connections to individual databases using libSQL clients.
Options
:expiration(String.t/0) - Token expiration (e.g., '1w', '30d', 'never').:authorization(String.t/0) - Authorization level for the token.:organization(String.t/0) - Organization slug. Overrides client default.
Examples
# Basic token creation
{:ok, token} = Turso.Databases.create_token(client, "my-app-db")
# Token with expiration and authorization
{:ok, token} = Turso.Databases.create_token(client, "my-app-db",
expiration: "1w",
authorization: "read-only"
)Returns
{:ok, token()}- Token details including the JWT{:error, map()}- Error details
@spec delete(Turso.t(), String.t(), keyword()) :: api_result(map())
Deletes a database.
Warning: This operation is irreversible. All data in the database will be permanently lost.
Options
:organization(String.t/0) - Organization slug. Overrides client default.
Examples
{:ok, _} = Turso.Databases.delete(client, "my-app-db")Returns
{:ok, map()}- Deletion confirmation{:error, map()}- Error details
@spec invalidate_tokens(Turso.t(), String.t(), keyword()) :: api_result(map())
Invalidates all database tokens for a database.
This will immediately revoke all existing tokens for the database, requiring new tokens to be created for future connections.
Options
:organization(String.t/0) - Organization slug. Overrides client default.
Examples
{:ok, _} = Turso.Databases.invalidate_tokens(client, "my-app-db")Returns
{:ok, map()}- Invalidation confirmation{:error, map()}- Error details
@spec list( Turso.t(), keyword() ) :: api_result([database()])
Lists all databases for the organization.
Options
:organization(String.t/0) - Organization slug. Overrides client default.
Examples
# List databases using client's default organization
{:ok, databases} = Turso.Databases.list(client)
# List databases for a specific organization
{:ok, databases} = Turso.Databases.list(client, organization: "other-org")Returns
{:ok, list(database())}- List of database objects{:error, map()}- Error details
@spec retrieve(Turso.t(), String.t(), keyword()) :: api_result(database())
Retrieves details of a specific database.
Options
:organization(String.t/0) - Organization slug. Overrides client default.
Examples
{:ok, database} = Turso.Databases.retrieve(client, "my-app-db")
{:ok, database} = Turso.Databases.retrieve(client, "my-app-db",
organization: "other-org"
)Returns
{:ok, database()}- Database details{:error, map()}- Error details
@spec update(Turso.t(), String.t(), keyword()) :: api_result(database())
Updates database configuration.
Options
:allow_attach(boolean/0) - Whether to allow ATTACH statements.:size_limit(String.t/0) - Maximum database size (e.g., '500mb', '1gb').:organization(String.t/0) - Organization slug. Overrides client default.
Examples
{:ok, database} = Turso.Databases.update(client, "my-app-db",
allow_attach: false,
size_limit: "1gb"
)Returns
{:ok, database()}- Updated database object{:error, map()}- Error details