diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9fd45e0..b97cb16 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -2,9 +2,6 @@ name: Rust on: push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] env: CARGO_TERM_COLOR: always @@ -20,3 +17,10 @@ jobs: run: cargo build --verbose - name: Run tests run: cargo test --verbose + + format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Run rustfmt + run: cargo fmt --check diff --git a/src/errors.rs b/src/errors.rs index ae55000..8ffc681 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,5 +1,5 @@ //! ## Error handling -//! +//! //! This module provides error handling utilities for the Supabase client. use anyhow::Error; @@ -53,4 +53,4 @@ pub async fn authorization_failed_error() -> Result<(), Error> { pub async fn invalid_query_error() -> Result<(), Error> { Err(Error::msg("SUPABASE_RS: Invalid query")) -} \ No newline at end of file +} diff --git a/src/graphql/client.rs b/src/graphql/client.rs index bc6bebb..a1d9b02 100644 --- a/src/graphql/client.rs +++ b/src/graphql/client.rs @@ -1,10 +1,10 @@ -//! # GraphQL Client -//! +//! # GraphQL Client +//! //! The GraphQL client is used to send GraphQL queries to the Supabase API. use crate::SupabaseClient; // local imports +use crate::graphql::utils::format_endpoint::endpoint; use crate::graphql::Query; use crate::graphql::RootTypes; -use crate::graphql::utils::format_endpoint::endpoint; diff --git a/src/graphql/error_types.rs b/src/graphql/error_types.rs index d5af3d8..456a066 100644 --- a/src/graphql/error_types.rs +++ b/src/graphql/error_types.rs @@ -1,7 +1,7 @@ //! # Error Types -//! +//! //! This module contains functions that generate error messages for various error types. -//! +//! //! ## Functions //! - `illegal_table_name`: Generates an error message for an illegal table name. //! - `illegal_field_name`: Generates an error message for an illegal field name. @@ -11,9 +11,9 @@ //! - `failed_to_parse_json`: Generates an error message indicating that JSON parsing failed. //! - `print_red`: Prints a message in red color for errors. //! -//! +//! -use anyhow::{Result, Error as AnyError}; +use anyhow::{Error as AnyError, Result}; use serde_json::Value; /// Generates an error message for an illegal table name. @@ -28,10 +28,7 @@ use serde_json::Value; /// /// A `String` containing the error message. pub fn illegal_table_name(table_name: &str) -> String { - let amount_of_numbers: usize = table_name - .chars() - .take_while(|c| c.is_numeric()) - .count(); + let amount_of_numbers: usize = table_name.chars().take_while(|c| c.is_numeric()).count(); let arrow_amount: String = "^".repeat(amount_of_numbers); let is_plural: &str = if amount_of_numbers > 1 { "s" } else { "" }; @@ -60,10 +57,7 @@ pub fn illegal_table_name(table_name: &str) -> String { /// /// A `String` containing the error message. pub fn illegal_field_name(field_name: &str) -> String { - let amount_of_numbers: usize = field_name - .chars() - .take_while(|c| c.is_numeric()) - .count(); + let amount_of_numbers: usize = field_name.chars().take_while(|c| c.is_numeric()).count(); let arrow_amount: String = "^".repeat(amount_of_numbers); let is_plural: &str = if amount_of_numbers > 1 { "s" } else { "" }; @@ -109,9 +103,9 @@ pub fn table_does_not_exist(name: &str) -> String { pub fn field_does_not_exist_on_table(field: &str, table: &str) -> String { let error: String = format!( "\x1b[1;31mField does not exist on table: \n {} -> {}\x1b[0m", - table, - field - ).to_string(); + table, field + ) + .to_string(); print_red(&error); @@ -128,8 +122,11 @@ pub fn field_does_not_exist_on_table(field: &str, table: &str) -> String { /// /// A `String` containing the error message. pub fn table_name_does_not_end_with_collection(table_name: &str) -> String { - let error: String = - format!("\x1b[1;31mTable name does not end with \x1b[1;34m`Collection`\x1b[1;31m: {}\x1b[0m", table_name).to_string(); + let error: String = format!( + "\x1b[1;31mTable name does not end with \x1b[1;34m`Collection`\x1b[1;31m: {}\x1b[0m", + table_name + ) + .to_string(); let arrow_amount: String = "^".repeat(table_name.len()); print_red(&error); @@ -164,4 +161,4 @@ pub fn failed_to_parse_json(error: String) -> AnyError { /// * `error` - A string slice that holds the error message. pub fn print_red(error: &str) { println!("\x1b[1;31m{}\x1b[0m", error); -} \ No newline at end of file +} diff --git a/src/graphql/mod.rs b/src/graphql/mod.rs index 70bcb08..7d616d1 100644 --- a/src/graphql/mod.rs +++ b/src/graphql/mod.rs @@ -2,17 +2,17 @@ //! # GraphQL for Supabase //! This module provides a GraphQL client for interacting with the Supabase API. -//! +//! //! ## Features //! - **Query**: Send queries to the Supabase API. -//! +//! //! ## Usage //! Before using the GraphQL client, ensure you have a valid `SupabaseClient` instance. -//! +//! //! ### Example: Authenticate with Supabase //! ```ignore //! use supabase_rs::SupabaseClient; -//! +//! //! #[tokio::main] //! async fn main() { //! let supabase_client: SupabaseClient = SupabaseClient::new( @@ -20,42 +20,42 @@ //! std::env::var("SUPABASE_KEY").unwrap() //! ); //! ``` -//! +//! //! ### Example: Send a GraphQL query //! ```ignore //! let request_graphql: Request = Request::new( //! supabase_client, //! json!({ //! "query": r#" -//! { -//! usersCollection(first: 1) { -//! edges { -//! node { +//! { +//! usersCollection(first: 1) { +//! edges { +//! node { //! user_id, //! username, //! email -//! } -//! } -//! } +//! } +//! } +//! } //! } //! "#, //! }), //! supabase_rs::graphql::RootTypes::Query //! ); -//! +//! //! let response: Result = request_graphql.send().await; -//! +//! //! match response { //! Ok(response) => println!("{:#?}", response), //! Err(error) => println!("{:#?}", error), //! }} //! ``` //! -//! -//! +//! +//! //! ## Error Handling //! The GraphQL client returns a `Result` where `Value` is the response from the Supabase API and `Error` is an error message in case of failure. -//! +//! //! ## GraphQL Query //! The GraphQL query should be in the following format: //! ```ignore @@ -71,61 +71,59 @@ //! } //! ``` //! *Note*: All tables in Supabase end with `Collection`. Ensure you append `Collection` to the table name. -//! +//! //! ## GraphQL Mutation -//! +//! //! The GraphQL mutation should be in the following format: -//! +//! pub mod client; -pub mod request; -pub mod parse; -pub mod utils; -pub mod query; pub mod error_types; +pub mod parse; pub mod parsing; +pub mod query; +pub mod request; +pub mod utils; use crate::SupabaseClient; use serde_json::Value; /// #### Query -/// +/// /// Represents a GraphQL query. #[derive(Debug)] pub struct Query { pub query: Value, } - /// #### RootTypes -/// +/// /// The root types for GraphQL operations. -/// +/// /// - `Query`: Represents a query operation. /// - `Mutation`: Represents a mutation operation. /// - `Subscription`: Represents a subscription operation. /// - `Fragment`: Represents a fragment operation. -/// +/// /// *Note*: Only `Query` is supported at the moment. -/// +/// /// ## Example -/// +/// /// ```ignore /// use supabase_rs::graphql::RootTypes; -/// +/// /// let root_type: RootTypes = RootTypes::Query; -/// +/// /// println!("{:?}", root_type); /// ``` -/// +/// #[derive(Debug)] pub enum RootTypes { Query, Mutation, Subscription, - Fragment + Fragment, } - #[derive(Debug)] pub enum GraphQLOperators { First, @@ -133,5 +131,5 @@ pub enum GraphQLOperators { Before, After, Filter, - OrderBy -} \ No newline at end of file + OrderBy, +} diff --git a/src/graphql/parse.rs b/src/graphql/parse.rs index 187ce8f..0d23965 100644 --- a/src/graphql/parse.rs +++ b/src/graphql/parse.rs @@ -1,11 +1,9 @@ -use anyhow::{ Result, Error }; -use serde_json::Value; use crate::graphql::error_types::{ - illegal_table_name, - table_does_not_exist, - field_does_not_exist_on_table, + field_does_not_exist_on_table, illegal_table_name, table_does_not_exist, table_name_does_not_end_with_collection, }; +use anyhow::{Error, Result}; +use serde_json::Value; pub fn parse_outer(query: &Value) -> bool { if let Some(query_str) = query.as_str() { @@ -21,13 +19,13 @@ pub fn parse_outer(query: &Value) -> bool { } /// Get the table name from the query -/// +/// /// # Arguments /// - `query` - A JSON Value containing the query -/// +/// /// # Returns /// A `Result` containing the table name as a `String` if successful, or an `Error` if the outer structure is invalid -/// +/// pub fn get_table_name(query: &Value) -> Result { if parse_outer(query) { let query_str: &str = query["query"].as_str().unwrap_or(""); diff --git a/src/graphql/parsing/mod.rs b/src/graphql/parsing/mod.rs index 82d0bc6..48cd958 100644 --- a/src/graphql/parsing/mod.rs +++ b/src/graphql/parsing/mod.rs @@ -1,2 +1,2 @@ +pub mod node_fields; pub mod operators; -pub mod node_fields; \ No newline at end of file diff --git a/src/graphql/parsing/node_fields.rs b/src/graphql/parsing/node_fields.rs index e69de29..8b13789 100644 --- a/src/graphql/parsing/node_fields.rs +++ b/src/graphql/parsing/node_fields.rs @@ -0,0 +1 @@ + diff --git a/src/graphql/parsing/operators.rs b/src/graphql/parsing/operators.rs index e69de29..8b13789 100644 --- a/src/graphql/parsing/operators.rs +++ b/src/graphql/parsing/operators.rs @@ -0,0 +1 @@ + diff --git a/src/graphql/query.rs b/src/graphql/query.rs index 71ef906..123fce9 100644 --- a/src/graphql/query.rs +++ b/src/graphql/query.rs @@ -1,19 +1,19 @@ -use anyhow::{ Result, Error as AnyError }; +use anyhow::{Error as AnyError, Result}; use serde_json::Value; -use crate::graphql::{ RootTypes, Query }; +use crate::graphql::parse::parse_outer; use crate::graphql::utils::format_endpoint::endpoint; use crate::graphql::utils::headers::headers; -use crate::graphql::parse::parse_outer; +use crate::graphql::{Query, RootTypes}; use crate::SupabaseClient; // FIX ME: This is a temporary fix to suppress the warning impl Query { /// # Verify the query - /// + /// /// This method verifies the query to ensure it is in the correct format. - /// - /// + /// + /// pub async fn verify(&self) -> Result { Ok(parse_outer(&self.query)) } diff --git a/src/graphql/utils/mod.rs b/src/graphql/utils/mod.rs index fb0ef5a..86761da 100644 --- a/src/graphql/utils/mod.rs +++ b/src/graphql/utils/mod.rs @@ -1,2 +1,2 @@ pub mod format_endpoint; -pub mod headers; \ No newline at end of file +pub mod headers; diff --git a/src/insert.rs b/src/insert.rs index 2341bdb..ff373ce 100644 --- a/src/insert.rs +++ b/src/insert.rs @@ -21,7 +21,7 @@ //! #[tokio::main] //! async fn main() { //! let client = SupabaseClient::new( -//! "your_supabase_url", "your_supabase_key" +//! "your_supabase_url".to_string(), "your_supabase_key".to_string() //! ); //! let insert_result = client.insert( //! "your_table_name", json!({"column_name": "value"}) @@ -37,7 +37,7 @@ //! #[tokio::main] //! async fn main() { //! let client = SupabaseClient::new( -//! "your_supabase_url", "your_supabase_key" +//! "your_supabase_url".to_string(), "your_supabase_key".to_string() //! ); //! let unique_insert_result = client.insert_if_unique( //! "your_table_name", json!({"unique_column_name": "unique_value"}) @@ -206,7 +206,7 @@ impl SupabaseClient { /// #[tokio::main] /// async fn main() { /// // Initialize the Supabase client - /// let client = SupabaseClient::new("your_supabase_url", "your_supabase_key"); + /// let client = SupabaseClient::new("your_supabase_url".to_string(), "your_supabase_key".to_string()); /// /// // This will insert a new row into the table if the value is unique /// let unique_insert_result = client.insert_if_unique( diff --git a/src/lib.rs b/src/lib.rs index 3099918..0e43e05 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -339,13 +339,13 @@ pub mod delete; pub mod errors; pub mod insert; pub mod query; +pub mod query_builder; +pub mod request; pub mod routing; pub mod select; pub mod success; pub mod tests; pub mod update; -pub mod request; -pub mod query_builder; pub mod graphql; pub mod nightly; diff --git a/src/main.rs b/src/main.rs index 46a77b6..b60a84a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,26 +23,26 @@ async fn main() { let supabase_client: SupabaseClient = SupabaseClient::new( std::env::var("SUPABASE_URL").unwrap(), - std::env::var("SUPABASE_KEY").unwrap() + std::env::var("SUPABASE_KEY").unwrap(), ); let user_id = "xx-xx-xx-xx-xx"; - + // let request_graphql: Request = Request::new( // supabase_client, // json!({ // "query": format!( // r#" - // {{ - // usersCollection(filter: {{user_id: {{eq: \"{}\"}}}}) {{ - // edges {{ - // node {{ + // {{ + // usersCollection(filter: {{user_id: {{eq: \"{}\"}}}}) {{ + // edges {{ + // node {{ // user_id, // username, // email - // }} - // }} - // }} + // }} + // }} + // }} // }} // "#, // user_id diff --git a/src/nightly.rs b/src/nightly.rs index a5d8776..8c84ab2 100644 --- a/src/nightly.rs +++ b/src/nightly.rs @@ -14,13 +14,10 @@ pub fn print_nightly_warning() { println!("\x1b[34;1mTo disable this message, set the environment variable SUPABASE_RS_NO_NIGHTLY_MSG to 'true'.\x1b[0m"); } -pub fn print_if_dev( - message: &str -) { +pub fn print_if_dev(message: &str) { dotenv().ok(); if env::var("SUPABASE_RS_DEV").unwrap_or_else(|_| "false".to_string()) == "true" { return; } println!("\x1b[34m{}\x1b[0m", message); - -} \ No newline at end of file +} diff --git a/src/query.rs b/src/query.rs index 532a002..0af358a 100644 --- a/src/query.rs +++ b/src/query.rs @@ -20,8 +20,8 @@ //! value: "30".to_string(), //! }; //! let sort = Sort { -//! _column: "name".to_string(), -//! _order: SortOrder::Ascending, +//! column: "name".to_string(), +//! order: SortOrder::Ascending, //! }; //! query.add_filter(filter); //! query.add_sort(sort); diff --git a/src/query_builder/mod.rs b/src/query_builder/mod.rs index d561cd5..ea54a04 100644 --- a/src/query_builder/mod.rs +++ b/src/query_builder/mod.rs @@ -1,3 +1,3 @@ pub mod builder; pub mod filter; -pub mod sort; \ No newline at end of file +pub mod sort; diff --git a/src/realtime/mod.rs b/src/realtime/mod.rs index a96d4e3..8078338 100644 --- a/src/realtime/mod.rs +++ b/src/realtime/mod.rs @@ -1 +1 @@ -#![cfg(feature = "realtime")] \ No newline at end of file +#![cfg(feature = "realtime")] diff --git a/src/request/headers.rs b/src/request/headers.rs index 63e3ce3..f734966 100644 --- a/src/request/headers.rs +++ b/src/request/headers.rs @@ -28,7 +28,10 @@ impl Headers { headers.insert(HeadersTypes::ClientInfo.as_str(), "supabase-rs/0.3.7"); headers.insert(HeadersTypes::ContentType.as_str(), "application/json"); headers.insert(HeadersTypes::ApiKey.as_str(), api_key); - headers.insert(HeadersTypes::Authorization.as_str(), &format!("Bearer {}", auth_token)); + headers.insert( + HeadersTypes::Authorization.as_str(), + &format!("Bearer {}", auth_token), + ); headers } } diff --git a/src/request/mod.rs b/src/request/mod.rs index e018e27..cc0d23a 100644 --- a/src/request/mod.rs +++ b/src/request/mod.rs @@ -2,7 +2,6 @@ pub mod headers; use std::collections::HashMap; - pub struct Headers { pub headers: HashMap, -} \ No newline at end of file +} diff --git a/src/routing/mod.rs b/src/routing/mod.rs index 1c768d9..fd6bb6c 100644 --- a/src/routing/mod.rs +++ b/src/routing/mod.rs @@ -1 +1 @@ -pub mod id; \ No newline at end of file +pub mod id; diff --git a/src/select.rs b/src/select.rs index 309f0f9..06d36b9 100644 --- a/src/select.rs +++ b/src/select.rs @@ -127,19 +127,18 @@ #![allow(clippy::derivable_impls)] #![allow(rustdoc::invalid_rust_codeblocks)] -use crate::SupabaseClient; use crate::query::QueryBuilder; -use crate::success::handle_response; use crate::request::Headers; +use crate::success::handle_response; +use crate::SupabaseClient; -use reqwest::{Client, Response}; use reqwest::header::HeaderMap; -use serde_json::{json, Value}; use reqwest::header::{HeaderName, HeaderValue}; +use reqwest::{Client, Response}; +use serde_json::{json, Value}; use deprecate_until::deprecate_until; - #[cfg(feature = "nightly")] use crate::nightly::print_if_dev; @@ -179,21 +178,20 @@ impl SupabaseClient { ) -> Result, String> { // Build the client and the endpoint let endpoint: String = format!("{}/rest/v1/{}?{}", self.url, table_name, query_string); - + #[cfg(feature = "nightly")] println!("\x1b[33mEndpoint: {}\x1b[0m", endpoint); - + #[cfg(feature = "rustls")] let client = Client::builder().use_rustls_tls().build().unwrap(); - + #[cfg(not(feature = "rustls"))] let client: Client = Client::new(); - + #[cfg(feature = "nightly")] use crate::nightly::print_nightly_warning; #[cfg(feature = "nightly")] print_nightly_warning(); - let endpoint: String = if endpoint.ends_with("?count=exact") { endpoint.replace("?count=exact", "") @@ -201,10 +199,9 @@ impl SupabaseClient { endpoint }; - // create headers with default values let headers: Headers = Headers::with_defaults(&self.api_key, &self.api_key); - + // convert headers to HeaderMap let mut header_map: HeaderMap = HeaderMap::new(); for (key, value) in headers.get_headers() { @@ -213,19 +210,14 @@ impl SupabaseClient { HeaderValue::from_str(&value).map_err(|e| e.to_string())?, ); } - + // send the request - let response: Response = match client - .get(&endpoint) - .headers(header_map) - .send() - .await - { + let response: Response = match client.get(&endpoint).headers(header_map).send().await { Ok(response) => response, Err(error) => return Err(error.to_string()), }; - + // process the response handle_response(response).await } -} \ No newline at end of file +} diff --git a/src/storage/download.rs b/src/storage/download.rs index 4007040..63130c4 100644 --- a/src/storage/download.rs +++ b/src/storage/download.rs @@ -13,17 +13,13 @@ #![cfg(feature = "storage")] -use reqwest::{Client, Response, Error as ReqwestError}; +use anyhow::{Error, Result}; +use reqwest::{Client, Error as ReqwestError, Response}; use std::fs::File; use std::io::prelude::*; -use anyhow::{Error, Result}; - use crate::storage::SupabaseStorage; - - - impl SupabaseStorage { /// Downloads a file from Supabase Storage. /// @@ -40,17 +36,15 @@ impl SupabaseStorage { /// /// let bytes = storage.download().await.unwrap(); /// ``` - pub async fn download( - &self - ) -> Result, ReqwestError> { - - - let url: String = format!("{}/storage/v1/object/public/{}/{}", self.supabase_url, self.bucket_name, self.filename); + pub async fn download(&self) -> Result, ReqwestError> { + let url: String = format!( + "{}/storage/v1/object/public/{}/{}", + self.supabase_url, self.bucket_name, self.filename + ); let client: Client = Client::new(); let response: Response = client.get(&url).send().await?; let bytes = response.bytes().await?; Ok(bytes.to_vec()) - } /// Saves a file to the local system. @@ -68,14 +62,8 @@ impl SupabaseStorage { /// /// storage.save("local_file.txt").await.unwrap(); /// ``` - pub async fn save( - &self, - file_path: &str - ) -> Result<(), Error> { - - let bytes: Vec = self.download().await.map_err(|e| { - Error::new(e) - })?; + pub async fn save(&self, file_path: &str) -> Result<(), Error> { + let bytes: Vec = self.download().await.map_err(|e| Error::new(e))?; let mut file: File = File::create(file_path)?; file.write_all(&bytes)?; diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 7a5fd91..ac100c2 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -27,20 +27,20 @@ //! //! let bytes = storage.download().unwrap(); //! ``` -//! +//! //! ### Downloading a file directly to the local system //! ```ignore //! use supabase_rs::storage::SupabaseStorage; -//! +//! //! let storage = SupabaseStorage { //! supabase_url: "https://example.com".to_string(), //! bucket_name: "bucket".to_string(), //! filename: "file.txt".to_string(), //! }; -//! +//! //! storage.save("local_file.txt").unwrap(); //! ``` -//! +//! #![cfg(feature = "storage")] pub mod download; @@ -54,4 +54,4 @@ pub struct SupabaseStorage { pub bucket_name: String, /// The name of the file. pub filename: String, -} \ No newline at end of file +} diff --git a/src/success.rs b/src/success.rs index 519bdac..a8b40f7 100644 --- a/src/success.rs +++ b/src/success.rs @@ -4,7 +4,7 @@ //! use reqwest::Response; -use serde_json::{Value, json}; +use serde_json::{json, Value}; use crate::errors::{ api_key_missing_error, authorization_failed_error, invalid_query_error, unknown_error, diff --git a/src/tests/base.rs b/src/tests/base.rs index c6c75f6..c17c4d9 100644 --- a/src/tests/base.rs +++ b/src/tests/base.rs @@ -20,10 +20,6 @@ //! are working as expected. //! - - - - #[cfg(test)] mod methods { use crate::SupabaseClient; @@ -33,23 +29,19 @@ mod methods { // import local method tests use crate::tests::methods::{ - init::init, - insert::insert as test_insert, - insert_string::insert_string as test_insert_string, - insert_numeric::insert_numeric as test_insert_numeric, - insert_if_unique_string::insert_if_unique_string as test_insert_if_unique_string, + delete::delete as test_delete, init::init, insert::insert as test_insert, insert_if_unique_numeric::insert_if_unique_numeric as test_insert_if_unique_numeric, - select::select as test_select, - select_filter::select_filter as test_select_filter, + insert_if_unique_string::insert_if_unique_string as test_insert_if_unique_string, + insert_numeric::insert_numeric as test_insert_numeric, + insert_string::insert_string as test_insert_string, query::test_query, + select::select as test_select, select_filter::select_filter as test_select_filter, + select_stacked_queries::select_stacked_queries as test_select_stacked_queries, select_with_columns::select_with_columns as test_select_with_columns, select_with_count::select_with_count as test_select_with_count, select_with_count_and_filter::select_with_count_and_filter as test_select_with_count_and_filter, - delete::delete as test_delete, - upsert_string::upsert_string as test_upsert_string, - upsert_numeric::upsert_numeric as test_upsert_numeric, update_with_column::update_with_column as test_update_with_column, - select_stacked_queries::select_stacked_queries as test_select_stacked_queries, - query::test_query, + upsert_numeric::upsert_numeric as test_upsert_numeric, + upsert_string::upsert_string as test_upsert_string, }; /// Tests the `insert` method of `SupabaseClient`. @@ -143,7 +135,6 @@ mod methods { test_select_stacked_queries().await; } - /// Tests the `query` method of `SupabaseClient`. /// This test is used to test the query builder. #[tokio::test] diff --git a/src/tests/methods/delete.rs b/src/tests/methods/delete.rs index af66b49..421a663 100644 --- a/src/tests/methods/delete.rs +++ b/src/tests/methods/delete.rs @@ -1,8 +1,6 @@ - -use serde_json::{json, Value}; -use crate::SupabaseClient; use crate::tests::methods::init::init; - +use crate::SupabaseClient; +use serde_json::{json, Value}; pub async fn delete() { /// Performs a select_filter operation in an isolated scope. @@ -35,4 +33,4 @@ pub async fn delete() { let response: Result<(), String> = delete_inner(supabase_client).await; assert!(response.is_ok()); -} \ No newline at end of file +} diff --git a/src/tests/methods/init.rs b/src/tests/methods/init.rs index a8ec72d..5e8c0aa 100644 --- a/src/tests/methods/init.rs +++ b/src/tests/methods/init.rs @@ -1,6 +1,6 @@ use crate::SupabaseClient; -use std::env::var; use dotenv::dotenv; +use std::env::var; pub async fn init() -> Result> { dotenv().ok(); @@ -9,4 +9,4 @@ pub async fn init() -> Result> { let supabase_key: String = var("SUPABASE_KEY")?; Ok(SupabaseClient::new(supabase_url, supabase_key)) -} \ No newline at end of file +} diff --git a/src/tests/methods/insert.rs b/src/tests/methods/insert.rs index fe64cc3..b0c602d 100644 --- a/src/tests/methods/insert.rs +++ b/src/tests/methods/insert.rs @@ -1,13 +1,10 @@ -use serde_json::json; -use crate::SupabaseClient; use crate::tests::methods::init::init; - +use crate::SupabaseClient; +use serde_json::json; pub async fn insert() { /// Performs an insert operation in an isolated scope. - async fn insert_inner( - supabase_client: SupabaseClient - ) -> Result<(), String> { + async fn insert_inner(supabase_client: SupabaseClient) -> Result<(), String> { // Usage example let response_inner: Result = supabase_client .insert( @@ -41,4 +38,4 @@ pub async fn insert() { let response: Result<(), String> = insert_inner(supabase_client).await; assert!(response.is_ok()); -} \ No newline at end of file +} diff --git a/src/tests/methods/insert_if_unique_numeric.rs b/src/tests/methods/insert_if_unique_numeric.rs index 5e032e5..a4743e8 100644 --- a/src/tests/methods/insert_if_unique_numeric.rs +++ b/src/tests/methods/insert_if_unique_numeric.rs @@ -1,7 +1,6 @@ -use serde_json::json; -use crate::SupabaseClient; use crate::tests::methods::init::init; - +use crate::SupabaseClient; +use serde_json::json; pub async fn insert_if_unique_numeric() { /// Performs an insert_if_unique operation in an isolated scope. @@ -40,4 +39,4 @@ pub async fn insert_if_unique_numeric() { let response: Result<(), String> = insert_if_unique_inner(supabase_client).await; assert!(response.is_ok()); -} \ No newline at end of file +} diff --git a/src/tests/methods/insert_if_unique_string.rs b/src/tests/methods/insert_if_unique_string.rs index 4776c97..ac7d11e 100644 --- a/src/tests/methods/insert_if_unique_string.rs +++ b/src/tests/methods/insert_if_unique_string.rs @@ -1,6 +1,6 @@ -use serde_json::json; -use crate::SupabaseClient; use crate::tests::methods::init::init; +use crate::SupabaseClient; +use serde_json::json; pub async fn insert_if_unique_string() { /// Performs an insert_if_unique operation in an isolated scope. @@ -39,4 +39,4 @@ pub async fn insert_if_unique_string() { let response: Result<(), String> = insert_if_unique_inner(supabase_client).await; assert!(response.is_ok()); -} \ No newline at end of file +} diff --git a/src/tests/methods/insert_numeric.rs b/src/tests/methods/insert_numeric.rs index d759510..2162acf 100644 --- a/src/tests/methods/insert_numeric.rs +++ b/src/tests/methods/insert_numeric.rs @@ -1,7 +1,6 @@ -use serde_json::json; -use crate::SupabaseClient; use crate::tests::methods::init::init; - +use crate::SupabaseClient; +use serde_json::json; pub async fn insert_numeric() { /// Performs an insert operation in an isolated scope. @@ -38,4 +37,4 @@ pub async fn insert_numeric() { let response: Result<(), String> = insert_inner(supabase_client).await; assert!(response.is_ok()); -} \ No newline at end of file +} diff --git a/src/tests/methods/insert_string.rs b/src/tests/methods/insert_string.rs index a19fa1e..98c2764 100644 --- a/src/tests/methods/insert_string.rs +++ b/src/tests/methods/insert_string.rs @@ -1,7 +1,6 @@ -use serde_json::json; -use crate::SupabaseClient; use crate::tests::methods::init::init; - +use crate::SupabaseClient; +use serde_json::json; pub async fn insert_string() { /// Performs an insert operation in an isolated scope. @@ -38,4 +37,4 @@ pub async fn insert_string() { let response: Result<(), String> = insert_inner(supabase_client).await; assert!(response.is_ok()); -} \ No newline at end of file +} diff --git a/src/tests/methods/query.rs b/src/tests/methods/query.rs index 98a8a1b..90f11ed 100644 --- a/src/tests/methods/query.rs +++ b/src/tests/methods/query.rs @@ -1,11 +1,10 @@ // written by @izyuumi -use crate::query::Query; use crate::query::Filter; use crate::query::Operator; +use crate::query::Query; use crate::query::Sort; use crate::query::SortOrder; - pub async fn test_query() { let mut query: Query = Query::new(); let filter: Filter = Filter { @@ -21,4 +20,4 @@ pub async fn test_query() { query.add_sort(sort); let query_string: String = query.build(); assert_eq!(query_string, "age.gt=30&name.asc"); -} \ No newline at end of file +} diff --git a/src/tests/methods/select.rs b/src/tests/methods/select.rs index 9845d3e..41b6d41 100644 --- a/src/tests/methods/select.rs +++ b/src/tests/methods/select.rs @@ -1,7 +1,6 @@ -use serde_json::{json, Value}; -use crate::SupabaseClient; use crate::tests::methods::init::init; - +use crate::SupabaseClient; +use serde_json::{json, Value}; pub async fn select() { /// Performs a select operation in an isolated scope. @@ -33,4 +32,4 @@ pub async fn select() { let response: Result<(), String> = select_inner(supabase_client).await; assert!(response.is_ok()); -} \ No newline at end of file +} diff --git a/src/tests/methods/select_filter.rs b/src/tests/methods/select_filter.rs index 6e1e920..2bf9f22 100644 --- a/src/tests/methods/select_filter.rs +++ b/src/tests/methods/select_filter.rs @@ -1,8 +1,6 @@ - -use serde_json::{json, Value}; -use crate::SupabaseClient; use crate::tests::methods::init::init; - +use crate::SupabaseClient; +use serde_json::{json, Value}; pub async fn select_filter() { /// Performs a select_filter operation in an isolated scope. @@ -37,4 +35,4 @@ pub async fn select_filter() { let response: Result<(), String> = select_filter_inner(supabase_client).await; assert!(response.is_ok()); -} \ No newline at end of file +} diff --git a/src/tests/methods/select_stacked_queries.rs b/src/tests/methods/select_stacked_queries.rs index 88e2c3e..9339df4 100644 --- a/src/tests/methods/select_stacked_queries.rs +++ b/src/tests/methods/select_stacked_queries.rs @@ -1,8 +1,6 @@ - -use serde_json::{json, Value}; -use crate::SupabaseClient; use crate::tests::methods::init::init; - +use crate::SupabaseClient; +use serde_json::{json, Value}; pub async fn select_stacked_queries() { /// Performs a select_filter operation in an isolated scope. @@ -43,4 +41,4 @@ pub async fn select_stacked_queries() { let response: Result<(), String> = upsert_inner(supabase_client).await; assert!(response.is_ok()); -} \ No newline at end of file +} diff --git a/src/tests/methods/select_with_columns.rs b/src/tests/methods/select_with_columns.rs index c222212..082486b 100644 --- a/src/tests/methods/select_with_columns.rs +++ b/src/tests/methods/select_with_columns.rs @@ -1,13 +1,10 @@ -use serde_json::{json, Value}; -use crate::SupabaseClient; use crate::tests::methods::init::init; - +use crate::SupabaseClient; +use serde_json::{json, Value}; pub async fn select_with_columns() { /// Performs a select_with_columns operation in an isolated scope. - async fn select_filter_columns_inner( - supabase_client: SupabaseClient, - ) -> Result<(), String> { + async fn select_filter_columns_inner(supabase_client: SupabaseClient) -> Result<(), String> { // Usage example let response_inner: Result, String> = supabase_client @@ -39,4 +36,4 @@ pub async fn select_with_columns() { let response: Result<(), String> = select_filter_columns_inner(supabase_client).await; assert!(response.is_ok()); -} \ No newline at end of file +} diff --git a/src/tests/methods/select_with_count.rs b/src/tests/methods/select_with_count.rs index 3efec25..18df69b 100644 --- a/src/tests/methods/select_with_count.rs +++ b/src/tests/methods/select_with_count.rs @@ -1,7 +1,6 @@ -use serde_json::{json, Value}; -use crate::SupabaseClient; use crate::tests::methods::init::init; - +use crate::SupabaseClient; +use serde_json::{json, Value}; pub async fn select_with_count() { /// Performs a select_filter operation in an isolated scope. @@ -33,4 +32,4 @@ pub async fn select_with_count() { let response: Result<(), String> = select_with_count_inner(supabase_client).await; assert!(response.is_ok()); -} \ No newline at end of file +} diff --git a/src/tests/methods/select_with_count_and_filter.rs b/src/tests/methods/select_with_count_and_filter.rs index 155769b..cbe446a 100644 --- a/src/tests/methods/select_with_count_and_filter.rs +++ b/src/tests/methods/select_with_count_and_filter.rs @@ -1,13 +1,12 @@ - -use serde_json::{json, Value}; -use crate::SupabaseClient; use crate::tests::methods::init::init; - +use crate::SupabaseClient; +use serde_json::{json, Value}; pub async fn select_with_count_and_filter() { - /// Performs a select_filter operation in an isolated scope. - async fn select_with_count_and_filter_inner(supabase_client: SupabaseClient) -> Result<(), String> { + async fn select_with_count_and_filter_inner( + supabase_client: SupabaseClient, + ) -> Result<(), String> { // Usage example let response_inner: Result, String> = supabase_client @@ -18,9 +17,7 @@ pub async fn select_with_count_and_filter() { .await; match response_inner { - Ok(response_inner) => { - Ok(()) - } + Ok(response_inner) => Ok(()), Err(error) => { eprintln!("\x1b[31mError: {:?}\x1b[0m", error); Err(error) @@ -31,11 +28,14 @@ pub async fn select_with_count_and_filter() { let supabase_client: SupabaseClient = match init().await { Ok(client) => client, Err(e) => { - eprintln!("\x1b[31mFailed to initialize Supabase client: {:?}\x1b[0m", e); + eprintln!( + "\x1b[31mFailed to initialize Supabase client: {:?}\x1b[0m", + e + ); return; } }; let response: Result<(), String> = select_with_count_and_filter_inner(supabase_client).await; assert!(response.is_ok()); -} \ No newline at end of file +} diff --git a/src/tests/methods/update_with_column.rs b/src/tests/methods/update_with_column.rs index 6c2d8ff..88d5652 100644 --- a/src/tests/methods/update_with_column.rs +++ b/src/tests/methods/update_with_column.rs @@ -1,8 +1,6 @@ - -use serde_json::{json, Value}; -use crate::SupabaseClient; use crate::tests::methods::init::init; - +use crate::SupabaseClient; +use serde_json::{json, Value}; pub async fn update_with_column() { /// Performs a select_filter operation in an isolated scope. @@ -44,4 +42,4 @@ pub async fn update_with_column() { let response: Result<(), String> = update_inner(supabase_client).await; assert!(response.is_ok()); -} \ No newline at end of file +} diff --git a/src/tests/methods/upsert_numeric.rs b/src/tests/methods/upsert_numeric.rs index 7820716..b0a8afb 100644 --- a/src/tests/methods/upsert_numeric.rs +++ b/src/tests/methods/upsert_numeric.rs @@ -1,8 +1,6 @@ - -use serde_json::{json, Value}; -use crate::SupabaseClient; use crate::tests::methods::init::init; - +use crate::SupabaseClient; +use serde_json::{json, Value}; pub async fn upsert_numeric() { /// Performs a select_filter operation in an isolated scope. @@ -46,4 +44,4 @@ pub async fn upsert_numeric() { let response: Result<(), String> = upsert_inner(supabase_client).await; assert!(response.is_ok()); -} \ No newline at end of file +} diff --git a/src/tests/methods/upsert_string.rs b/src/tests/methods/upsert_string.rs index a43d83d..e36baaa 100644 --- a/src/tests/methods/upsert_string.rs +++ b/src/tests/methods/upsert_string.rs @@ -1,8 +1,6 @@ - -use serde_json::{json, Value}; -use crate::SupabaseClient; use crate::tests::methods::init::init; - +use crate::SupabaseClient; +use serde_json::{json, Value}; pub async fn upsert_string() { /// Performs a select_filter operation in an isolated scope. @@ -46,4 +44,4 @@ pub async fn upsert_string() { let response: Result<(), String> = upsert_inner(supabase_client).await; assert!(response.is_ok()); -} \ No newline at end of file +} diff --git a/src/tests/mod.rs b/src/tests/mod.rs index ab35fa2..f065899 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -8,16 +8,16 @@ pub mod methods { pub mod insert_if_unique_string; pub mod insert_numeric; pub mod insert_string; + pub mod query; pub mod select; pub mod select_filter; + pub mod select_stacked_queries; pub mod select_with_columns; pub mod select_with_count; pub mod select_with_count_and_filter; + pub mod update_with_column; pub mod upsert_numeric; pub mod upsert_string; - pub mod update_with_column; - pub mod select_stacked_queries; - pub mod query; } #[cfg(test)] pub fn create_test_supabase_client() -> Result> { diff --git a/src/update.rs b/src/update.rs index 6a902fe..ab32c21 100644 --- a/src/update.rs +++ b/src/update.rs @@ -16,14 +16,14 @@ //! ### Update Example //! //! ``` -//! # use supabaase_rs::SupabaseClient; +//! # use supabase_rs::SupabaseClient; //! #[tokio::main] //! async fn main() { //! let client = SupabaseClient::new( -//! "your_supabase_url", "your_supabase_key" +//! "your_supabase_url".to_string(), "your_supabase_key".to_string() //! ); //! let update_result = client.update( -//! "your_table_name", "row_id", json!({"column_name": "new_value"}) +//! "your_table_name", "row_id", serde_json::json!({"column_name": "new_value"}) //! ).await; //! } //! ``` @@ -31,14 +31,14 @@ //! ### Upsert Example //! //! ``` -//! # use supabaase_rs::SupabaseClient; +//! # use supabase_rs::SupabaseClient; //! #[tokio::main] //! async fn main() { //! let client = SupabaseClient::new( -//! "your_supabase_url", "your_supabase_key" +//! "your_supabase_url".to_string(), "your_supabase_key".to_string() //! ); //! let upsert_result = client.upsert( -//! "your_table_name", "row_id", json!({"column_name": "value"}) +//! "your_table_name", "row_id", serde_json::json!({"column_name": "value"}) //! ).await; //! } //! ```