rp-supabase-client

Crates.iorp-supabase-client
lib.rsrp-supabase-client
version
sourcesrc
created_at2024-10-26 10:25:18.216114
updated_at2024-10-26 11:51:30.947496
descriptionSupabase PostgREST client wrapper with auth capabilities
homepagehttps://github.com/roberts-pumpurs/supabase-rs-utils
repositoryhttps://github.com/roberts-pumpurs/supabase-rs-utils
max_upload_size
id1423729
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Roberts Pumpurs (roberts-pumpurs)

documentation

README

rp-supabase-client

A Rust client for interacting with Supabase’s PostgREST API using authenticated requests.

Overview

rp-supabase-client simplifies making authenticated requests to Supabase’s PostgREST API. It handles authentication, token refresh, and provides a straightforward API for querying data.

Features

  • Easy authentication with Supabase.
  • Automatic token refresh using rp-supabase-auth.
  • Simple methods for querying and manipulating data.
use std::time::Duration;
use clap::Parser;
use futures::StreamExt;
use rp_supabase_auth::jwt_stream::SupabaseAuthConfig;
use rp_supabase_auth::types::LoginCredentials;
use rp_supabase_client::{new_authenticated, PostgrestResponse};
use tracing_subscriber::EnvFilter;

#[derive(Parser, Debug)]
struct Args {
    supabase_api_url: url::Url,
    anon_key: String,
    email: String,
    password: String,
    table: String,
}

#[tokio::main]
async fn main() {
    tracing_subscriber::fmt()
        .with_env_filter(EnvFilter::from_default_env())
        .init();

    let args = Args::parse();

    let config = SupabaseAuthConfig {
        api_key: args.anon_key,
        url: args.supabase_api_url,
        max_reconnect_attempts: 5,
        reconnect_interval: Duration::from_secs(3),
    };

    let login_credentials = LoginCredentials::builder()
        .email(args.email)
        .password(args.password)
        .build();

    let mut client_stream = new_authenticated(config, login_credentials).unwrap();

    while let Some(client_result) = client_stream.next().await {
        if let Ok((client, _token_response)) = client_result {
            let res = client
                .from(&args.table)
                .select("*")
                .build()
                .send()
                .await
                .map(PostgrestResponse::new)
                .unwrap()
                .json::<serde_json::Value>()
                .await;

            println!("Response: {:?}", res);
        }
    }
}
Commit count: 95

cargo fmt