1 unstable release

0.1.0 Mar 9, 2024

#1719 in Database interfaces

Download history 127/week @ 2024-03-04 28/week @ 2024-03-11 18/week @ 2024-04-01 61/week @ 2024-04-15

79 downloads per month

MIT license

20KB
499 lines

Turso Platform API

A turso client for the platform api endpoints

Example

use turso::{
    DatabasesPlatform, TursoClient
};

async fn get_db_url(
    client: &TursoClient<DatabasesPlatform>,
) -> String {
    let default_name = "awesome-db";
    let databases = client.list("my-organization").await.unwrap();
    let default_db = databases.databases.iter().find(|g| g.name == default_name);
    let mut remote = String::from("libsql://");
    if default_db.is_some() {
        remote.push_str(&default_db.unwrap().hostname.to_owned());
    } else {
        let new_db = client
            .create(&self.organization, default_name, &self.group)
            .await
            .unwrap();
        remote.push_str(&new_db.database.hostname.to_owned());
    }
    remote
}

async fn init() {
    let client = TursoClient::new().databases();
    get_db_url(&client).await;
}

Dependencies

~10–26MB
~371K SLoC