Skip to content

Commit

Permalink
fix: ignore or modify some doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
izyuumi committed Jul 9, 2024
1 parent d7f20e6 commit e6a2e03
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 197 deletions.
40 changes: 16 additions & 24 deletions src/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@
//!
//! It leverages the Supabase REST API to send delete requests. The main functionality is encapsulated
//! in the `SupabaseClient` struct, which provides the `delete` method to perform the deletion.
//!
//!
//! ## Usage
//!
use crate::SupabaseClient;
use reqwest::{Client, Response};
use serde_json::json;
use reqwest::{
Client,
Response
};


impl SupabaseClient {
/// Deletes a row in the specified table based on the provided ID.
Expand All @@ -33,8 +29,11 @@ impl SupabaseClient {
///
/// #[tokio::main]
/// async fn main() {
/// let client = SupabaseClient::new("your_supabase_url", "your_supabase_key");
/// let result = client.delete("your_table_name", "row_id", json!({})).await;
/// let client = SupabaseClient::new(
/// "your_supabase_url".to_string(),
/// "your_supabase_key".to_string()
/// );
/// let result = client.delete("your_table_name", "row_id").await;
/// match result {
/// Ok(_) => println!("Row deleted successfully"),
/// Err(e) => println!("Failed to delete row: {}", e),
Expand All @@ -47,26 +46,20 @@ impl SupabaseClient {
id: &str,
//body: Value
) -> Result<(), String> {

// Construct the endpoint URL for the delete operation
let endpoint: String = format!(
"{}/rest/v1/{}?id=eq.{}",
self.url, table_name, id
);

let endpoint: String = format!("{}/rest/v1/{}?id=eq.{}", self.url, table_name, id);

#[cfg(feature = "rustls")]
let client = Client::builder().use_rustls_tls().build().unwrap();

#[cfg(not(feature = "rustls"))]
let client = Client::new();


#[cfg(feature = "nightly")]
use crate::nightly::print_nightly_warning;
#[cfg(feature = "nightly")]
print_nightly_warning();


let body: serde_json::Value = json!({}); // this is temporary, will be used for more complex queries

// Send the delete request and handle the response
Expand All @@ -77,11 +70,11 @@ impl SupabaseClient {
.header("Content-Type", "application/json")
.body(body.to_string())
.send()
.await {
Ok(response) => response,
Err(error) => return Err(error.to_string())
};

.await
{
Ok(response) => response,
Err(error) => return Err(error.to_string()),
};

// Check the HTTP status code of the response
if response.status().is_success() {
Expand All @@ -90,5 +83,4 @@ impl SupabaseClient {
Err(response.status().to_string())
}
}

}
}
21 changes: 10 additions & 11 deletions src/graphql/utils/headers.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
use crate::SupabaseClient;
use std::collections::HashMap;


/// ### Headers for GraphQL requests
/// This will populate a headers HashMap with the required headers for a GraphQL request
///
///
/// #### Arguments
/// * `client` - The Supabase client
///
///
///
///
/// #### Example
/// ```rust
/// ```rust,ignore
/// use supabase::SupabaseClient;
/// use supabase::graphql::utils::headers::headers;
///
///
/// let client = SupabaseClient::new("https://myapp.supabase.co", "anonkey");
///
///
/// let headers = headers(&client);
///
///
/// println!("{:#?}", headers);
///
///
/// >> {
/// >> "apiKey": "YOUR_SUPABASE_KEY",
/// >> "apiKey": "YOUR_SUPABASE_KEY",
/// >> "Content-Type": "application/json"
/// >> }
/// ```
///
///
pub fn headers(client: &SupabaseClient) -> HashMap<String, String> {
// init the header hashmap
let mut headers: HashMap<String, String> = HashMap::new();
Expand Down
Loading

0 comments on commit e6a2e03

Please sign in to comment.