Crates.io | supabase_rs |
lib.rs | supabase_rs |
version | 0.2.7 |
source | src |
created_at | 2024-01-26 03:44:39.856833 |
updated_at | 2024-05-06 03:41:22.762925 |
description | Lightweight Rust client for Supabase |
homepage | |
repository | |
max_upload_size | |
id | 1115184 |
size | 111,666 |
supabase_rs
is an extremely light weight Supabase SDK for interacting with it's database.
I'm actively covering the entire Supabase API including Auth, Realtime, Storage etc
storage
: Enables the Storage
module to interact with Supabase Storage.
select()
Downloading a file from a public bucket
Saving a file
Saving a file to a private bucket
Uploading a file
Generating a signed url
Deleting a file
// coming soon //
// coming soon //
This is an unofficial Rust SDK for Supabase, since there is no official SDK for Rust yet.
Insert
: Add new rows to a table.
Insert if unique
: Add a new row only if it does not violate a UNIQUE constraint.
Update
: Modify existing rows in a table based on a unique identifier.
Select
: Insert a new row into a table if it does not exist, or update it if it does.
Select with count
: Select rows from a table and count the number of rows that match the filter criteria.
Select with filter
: Select rows from a table based on a filter criteria.
Select with filter and count
: Select rows from a table based on a filter criteria and count the number of rows that match the filter criteria.
Delete
: Delete a row from a table based on a unique identifier.
storage
: Enables the Storage
module to interact with Supabase Storage.[dependencies]
supabase-rs = "0.2.7"
// With the [storage] feature
supabase-rs = { version = "0.2.7", features = ["storage"] }
//!
First make sure you have initialized the Supabase Client Initalizing the SupabaseClient //!
The Supabase Client is initialized with the Supabase URL and the Supabase Key.
Which are environment variables that can be set in a .env
file under the following names or any other
SUPABASE_URL=
SUPABASE_KEY=
use supabase_rs::SupabaseClient;
use dotenv::dotenv;
use std::env::var;
async fn initialize_supabase_client() -> SupabaseClient {
dotenv().ok(); // Load the .env file
let supabase_client: SupabaseClient = SupabaseClient::new(
var("SUPABASE_URL").unwrap(),
var("SUPABASE_KEY").unwrap()
);
supabase_client
}
This will initialize the Supabase Client with the Supabase URL and the Supabase Key, and return the Supabase Client to be passed to other methods.
This will insert a new row into the test
table with the value value_test
in the dog
column.
// i know the imports are self explanatory but it makes it easier for beginners:)
use serde_json::json;
use supabase_rs::SupabaseClient;
// always pass an initialized SupabaseClient to the method
let client = SupabaseClient::new(
"your_supabase_url", "your_supabase_key"
);
async fn insert_example(
client: SupabaseClient
) -> Result<(), String> {
let insert_result = client
.insert(
"test",
json!({
"dog": "value_test"
}),
).await;
This will insert a new row into the test
table with the value value_test
in the dog
column if the value is unique.
It's a drop-in replacement for insert
without relying on Supabase's unique constraints on the database.
use serde_json::json;
use supabase_rs::SupabaseClient;
// always pass an initialized SupabaseClient to the method
let client = SupabaseClient::new(
"your_supabase_url", "your_supabase_key"
);
async fn insert_example(
client: SupabaseClient
) -> Result<(), String> {
let insert_result = client
.insert_if_unique(
"test",
json!({
"dog": "value_test"
}),
).await;
This will update the row in the test
table with the value value_test
in the dog
column where the id
is 1
.
// i know the imports are self explanatory but it makes it easier for beginners:)
use serde_json::json;
use supabase_rs::SupabaseClient;
// always pass an initialized SupabaseClient to the method
let client = SupabaseClient::new(
"your_supabase_url", "your_supabase_key"
);
async fn update_example(
client: SupabaseClient
) -> Result<(), String> {
let update_result = client
.update(
"test", // the table name
"1", // the id of the row to update
json!({
"dog": "value_test" // the new value
}),
).await;
This will return all dog
rows where the value is scooby
in the animals
table
use supabase_rs::SupabaseClient;
// always pass an initialized SupabaseClient to the method
let client = SupabaseClient::new(
"your_supabase_url", "your_supabase_key"
);
async fn select_scooby(
supabase_client: SupabaseClient
) -> Result<(), String> {
let data: Result<Vec<Value>, String> = supabase_client
.select("animals")
.eq("dog", "scooby")
.execute()
.await;
This will return all dog
rows where the value is scooby
in the animals
table and count the number of rows that match the filter criteria.
use supabase_rs::SupabaseClient;
// always pass an initialized SupabaseClient to the method
let client = SupabaseClient::new(
"your_supabase_url", "your_supabase_key"
);
async fn select_scooby_with_count(
supabase_client: SupabaseClient
) -> Result<(), String> {
let data: Result<Vec<Value>, String> = supabase_client
.select("animals")
.count()
.execute()
.await;
This will return all dog
rows where the value is scooby
in the animals
table
use supabase_rs::SupabaseClient;
// always pass an initialized SupabaseClient to the method
let client = SupabaseClient::new(
"your_supabase_url", "your_supabase_key"
);
async fn select_scooby_with_filter(
supabase_client: SupabaseClient
) -> Result<(), String> {
let data: Result<Vec<Value>, String> = supabase_client
.select("animals")
.eq("dog", "scooby")
.execute()
.await;
This will return all dog
rows where the value is scooby
in the animals
table and count the number of rows that match the filter criteria.
use supabase_rs::SupabaseClient;
// always pass an initialized SupabaseClient to the method
let client = SupabaseClient::new(
"your_supabase_url", "your_supabase_key"
);
async fn select_scooby_with_filter_and_count(
supabase_client: SupabaseClient
) -> Result<(), String> {
let data: Result<Vec<Value>, String> = supabase_client
.select("animals")
.eq("dog", "scooby")
.count()
.execute()
.await;
This will delete the row in the test
table where the id
is 1
.
// i know the imports are self explanatory but it makes it easier for beginners:)
use supabase_rs::SupabaseClient;
// always pass an initialized SupabaseClient to the method
let client = SupabaseClient::new(
"your_supabase_url", "your_supabase_key"
);
async fn delete_example(
client: SupabaseClient
) -> Result<(), String> {
let delete_result = client
.delete("test", "1")