#shuttle-service #turso

shuttle-turso

Plugin to obtain a client connected to a Turso database

15 breaking releases

new 0.35.0 Dec 7, 2023
0.34.1 Nov 29, 2023
0.33.0 Nov 16, 2023
0.22.0 Jul 31, 2023

#815 in Database interfaces

Download history 8/week @ 2023-08-19 26/week @ 2023-08-26 5/week @ 2023-09-02 16/week @ 2023-09-09 79/week @ 2023-09-16 32/week @ 2023-09-23 37/week @ 2023-09-30 37/week @ 2023-10-07 23/week @ 2023-10-14 70/week @ 2023-10-21 56/week @ 2023-10-28 47/week @ 2023-11-04 30/week @ 2023-11-11 74/week @ 2023-11-18 135/week @ 2023-11-25 87/week @ 2023-12-02

336 downloads per month

Apache-2.0

12KB
204 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_client::Client. 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_client::client::Client;
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: Client,
) -> ShuttleAxum {}

Parameters

Parameter Type Default Description
addr str "" URL of the database to connect to. If libsql:// is missing at the beginning, it will be automatically added.
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

~12–24MB
~377K SLoC