5 releases

new 0.2.3 Oct 25, 2024
0.2.2 Oct 19, 2024
0.2.1 Oct 18, 2024
0.2.0 Oct 17, 2024
0.1.0 Oct 16, 2024

#770 in Web programming

Download history 232/week @ 2024-10-12 244/week @ 2024-10-19

478 downloads per month

Apache-2.0 OR MIT

90KB
1.5K SLoC

Suparust

This is a library for interfacing with projects hosted using Supabase.

The library is in early development, so expect breaking API changes to occur.

Features

The goal is to support as much of the Supabase API as possible. Currently, the following features are supported:

  • Auth
    • Login with email and password
    • Logout
    • ... more to come
  • Postgrest
  • Storage
    • Delete object
    • Get object
    • Update object
    • Upload object
    • List objects
    • ... more to come
  • GraphQL
  • ...

Platform compatibility

The project supports both the stable-x86_64-unknown-linux-gnu and wasm32-unknown-unknown targets. More targets might also work, but WASM is actively targeted for this crate.

Installation

cargo add suparust

Usage examples

let client = suparust::Supabase::new(
    "https://your.postgrest.endpoint",
    "your_api_key",
    None,
    suparust::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

use suparust::storage::object::*;
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);
}

More examples will come as the library matures.

Contributing

Contributions are welcome. Please try to add tests for any new features or bug fixes.

As the library is in early development, please feel free to suggest refactorings or improvements to the API.

Some goals for the project:

  • To be as standards- and guidelines-compliant as possible
  • To use other crates for features where there is a good fit (e.g. the postgrest crate for PostgREST)

License

SPDX-License-Identifier: Apache-2.0 OR MIT

Dependencies

~6–17MB
~238K SLoC