floris-xlx / supabase_rs

Supabase SDK for Rust
MIT License
11 stars 5 forks source link

Unable to insert row using SupabaseClient #1

Closed JosiahParry closed 2 months ago

JosiahParry commented 4 months ago

Hey! Thank you so much for your work on this. I'd love to start using it. However, I am unable to insert a row into my supabase table using:

    let client = supabase_rs::SupabaseClient::new(
        std::env::var("SUPABASE_URL").unwrap(),
        std::env::var("SUPABASE_KEY").unwrap(),
    );

    client.insert("contact-us", json!(contact)).await;

I can insert it into the table using reqwest manually, though. I think you are missing a header or two.

    let url = std::env::var("SUPABASE_URL").unwrap();
    let key = std::env::var("SUPABASE_KEY").unwrap();
    let c = reqwest::Client::new();

    let req = c
        .post(url)
        .bearer_auth(key.clone())
        .header("apiKey", key)
        .header("Prefer", "return=minimal")
        .json(&contact)
        .send()
        .await?;
floris-xlx commented 3 months ago

i cannot see the contact json Value,

look at the examples on docs.rs

floris-xlx commented 3 months ago
use serde_json::json;
use supabase_rs::SupabaseClient;

let client = SupabaseClient::new(
    "your_supabase_url",
    "your_supabase_key"
);

async fn insert_example(
   client: SupabaseClient,
   email: &str
) -> Result<(), String> {
       let insert_result = client
            .insert(
            "contact-us", 
            json!({
                "email": email
           })
).await;