suparust

Crates.iosuparust
lib.rssuparust
version0.3.0
sourcesrc
created_at2024-10-16 15:42:04.895066
updated_at2024-11-23 11:16:23.702961
descriptionSupabase client for Rust with support for WASM
homepage
repositoryhttps://github.com/strykejern/suparust
max_upload_size
id1411947
size102,222
Anders B. Eie (strykejern)

documentation

README

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

Commit count: 43

cargo fmt