supabase-client-rs
A unified Rust client for Supabase, the open-source Firebase alternative.
Overview
This crate provides a unified interface to Supabase services by composing existing community crates:
| Service | Status | Crate |
|---|---|---|
| Database (PostgREST) | ✅ Ready | postgrest-rs |
| Realtime | ✅ Ready | supabase-realtime-rs |
| Auth | 📦 Trait defined | Community: TBD |
| Storage | 📦 Trait defined | Community: TBD |
| Edge Functions | 📦 Trait defined | Community: TBD |
Installation
Quick Start
use create_client;
async
Database Queries
The client wraps postgrest-rs for all database operations:
// Select with filters
let users = client
.from
.select
.eq
.order
.limit
.execute
.await?;
// Insert
let new_user = client
.from
.insert
.execute
.await?;
// Update
let updated = client
.from
.update
.eq
.execute
.await?;
// Delete
let deleted = client
.from
.delete
.eq
.execute
.await?;
// RPC (stored procedures)
let result = client
.rpc
.execute
.await?;
Configuration
use ;
use Duration;
let config = new
.schema
.timeout
.header;
let client = with_config?;
Authenticated Requests
After a user signs in, set their JWT for Row Level Security:
// Get JWT from your auth flow
let user_jwt = "eyJhbGciOiJIUzI1NiIs...";
// Create an authenticated client
let auth_client = client.with_jwt?;
// Requests now include the user's JWT
// RLS policies will apply based on the user
Realtime Integration
Enable the realtime feature to use Supabase Realtime:
Then use the realtime client:
use ;
// Get the realtime client
let realtime = client.realtime;
// Connect to realtime
realtime.connect.await?;
// Subscribe to a channel
let channel = realtime.channel.await;
let mut rx = channel.on.await;
channel.subscribe.await?;
// Send a message
channel.send.await?;
// Listen for messages
spawn;
See examples/realtime.rs for a complete example including presence tracking and database changes.
Features
- Database Operations: Full PostgREST integration with select, insert, update, delete, and RPC support
- Realtime: Subscribe to database changes, broadcast messages, and presence tracking
- Type-safe: Leverage Rust's type system for reliable code
- Async/Await: Built on Tokio for efficient async operations
- Flexible Configuration: Custom headers, schemas, and timeouts
- JWT Authentication: Row Level Security support with JWT tokens
Contributing
Contributions are welcome! Areas that need work:
- Realtime - ✅ Integrated with
supabase-realtime-rs - Auth client - Implement
AuthProvidertrait - Storage client - Implement
StorageProvidertrait - Functions client - Implement
FunctionsProvidertrait
See the traits module for the interfaces to implement.
License
- MIT license (LICENSE-MIT)
Acknowledgments
This project builds on the excellent work of:
- postgrest-rs - PostgREST client
- supabase-realtime-rs - Realtime client