24 breaking releases

new 0.44.0 Apr 23, 2024
0.42.1 Mar 25, 2024
0.35.2 Dec 21, 2023
0.34.1 Nov 29, 2023
0.22.0 Jul 31, 2023

#957 in Database interfaces

Download history 40/week @ 2024-01-04 7/week @ 2024-01-11 16/week @ 2024-01-18 9/week @ 2024-01-25 8/week @ 2024-02-01 85/week @ 2024-02-08 63/week @ 2024-02-15 32/week @ 2024-02-22 142/week @ 2024-02-29 300/week @ 2024-03-07 624/week @ 2024-03-14 164/week @ 2024-03-21 159/week @ 2024-03-28 60/week @ 2024-04-04 4/week @ 2024-04-11 107/week @ 2024-04-18

339 downloads per month

Apache-2.0

29KB
525 lines

Shuttle Turso

This plugin allows services to connect to a Turso database. Turso is an edge-hosted distributed database based on libSQL, a SQLite fork.

Usage

IMPORTANT: Currently Shuttle isn't able to provision a database for you (yet). This means you will have to create an account on their website and follow the few steps required to create a database and create a token to access it.

Add shuttle-turso to the dependencies for your service by running cargo add shuttle-turso. This resource will be provided by adding the shuttle_turso::Turso attribute to your Shuttle main decorated function.

It returns a libsql::Connection. When running locally it will instantiate a local SQLite database of the name of your service instead of connecting to your edge database.

If you want to connect to a remote database when running locally, you can specify the local_addr parameter. In that case, the token will be read from your Secrets.dev.toml file.

Example

In the case of an Axum server, your main function will look like this:

use libsql::Connection;
use shuttle_axum::ShuttleAxum;

#[shuttle_runtime::main]
async fn app(
    #[shuttle_turso::Turso(
        addr="libsql://my-turso-db-name.turso.io",
        token="{secrets.DB_TURSO_TOKEN}"
    )] client: Connection,
) -> ShuttleAxum {}

Parameters

Parameter Type Default Description
addr str "" URL of the database to connect to. Should begin with either libsql:// or https://.
token str "" The value of the token to authenticate against the Turso database. You can use string interpolation to read a secret from your Secret.toml file.
local_addr Option<str> None The URL to use when running your service locally. If not provided, this will default to a local file named <service name>.db

Dependencies

~48MB
~1M SLoC