Module insert

Source
Expand description

§Insert Operations

This module provides functionalities to insert new rows into a Supabase table. It leverages the Supabase REST API for performing these operations.

§Features

  • Insert: Add new rows to a table.
  • Insert if Unique: Add a new row only if it does not violate a UNIQUE constraint.

§Usage

Before using these operations, ensure you have a valid SupabaseClient instance. You can then use the insert or insert_if_unique methods provided by the client to perform the desired operation.

§Insert Example

#[tokio::main]
async fn main() {
    let client = SupabaseClient::new(
        "your_supabase_url".to_string(), "your_supabase_key".to_string()
    ).unwrap();
    let insert_result = client.insert(
        "your_table_name", json!({"column_name": "value"})
    ).await;
}

§Insert if Unique Example

#[tokio::main]
async fn main() {
    let client = SupabaseClient::new(
        "your_supabase_url".to_string(), "your_supabase_key".to_string()
    ).unwrap();
    let unique_insert_result = client.insert_if_unique(
        "your_table_name", json!({"unique_column_name": "unique_value"})
    ).await;
}

§Error Handling

Both insert and insert_if_unique methods return a Result<String, String>, where Ok(String) contains the ID of the inserted row, and Err(String) contains an error message in case of failure.