Crate suparust

Crate suparust 

Source
Expand description

§suparust

A crate for interacting with Supabase. Also supports WASM targets.

§Usage

Create your Supabase client with Supabase::new and start using it. The client will automatically handle authentication for you after you have logged in with the client.

§Postgrest

Use the functions from and rpc to get a postgrest::Builder that you can use to build your queries. The builder will automatically have authentication (if it’s available) when it’s first created.

§Storage

Use the function storage to get a one-time-use storage::Storage client for interacting with the storage part of Supabase. The client will automatically have authentication (if it’s available) when it’s first created.

§Auth

Auth functions are available directly on the Supabase client. Use the functions login_with_email, and logout for basic authentication. The client will automatically handle refreshing if needed when making requests.

The session refresh happens if it is less than auth::SESSION_REFRESH_GRACE_PERIOD_SECONDS seconds from expiring. This means that you should not keep authenticated builders/temporary clients for too long before using them, as they might time out.

Don't keep authenticated builders/clients from postgrest and storage too long, as they might time out after some time. See details in Auth description above.

§Examples

§Simple postgrest example

let client = suparust::Supabase::new(
    "https://your.postgrest.endpoint",
    "your_api_key",
    None,
    suparust::auth::SessionChangeListener::Ignore);

client.login_with_email(
    "myemail@example.com",
    "mypassword").await?;

#[derive(serde::Deserialize)]
struct MyStruct {
    id: i64,
    field: String
}

// Postgrest example (see postgrest crate for more details on API)
let table_contents = client
    .from("your_table")
    .await?
    .select("*")
    .execute()
    .await?
    .json::<Vec<MyStruct>>();

§Storage example

let client = suparust::Supabase::new(
    "https://your.postgrest.endpoint",
    "your_api_key",
    None,
    suparust::auth::SessionChangeListener::Ignore);

// Login here

let list_request = ListRequest::new("my_folder".to_string())
    .limit(10)
    .sort_by("my_column", SortOrder::Ascending);
let objects = client
    .storage()
    .await?
    .object()
    .list("my_bucket", list_request)
    .await?;

let object_names = objects
    .iter()
    .map(|object| object.name.clone());

let mut downloaded_objects = vec![];

for object in objects {
    let downloaded = client
        .storage()
        .await?
        .object()
        .get_one("my_bucket", &object.name)
        .await?;
    downloaded_objects.push(downloaded);
}

Modules§

auth
postgrest
Holds some types that you will get from using the Supabase client. These types are not meant to be used directly.
storage

Structs§

Supabase
The main Supabase client. This is safely cloneable.

Enums§

SupabaseError

Type Aliases§

Result