Skip to main content

supabase_client_query/
backend.rs

1use std::sync::Arc;
2
3#[cfg(feature = "direct-sql")]
4use sqlx::PgPool;
5
6/// Backend for query execution.
7///
8/// By default, queries are executed via the PostgREST REST API.
9/// With the `direct-sql` feature, queries can be executed directly via sqlx.
10#[derive(Clone)]
11pub enum QueryBackend {
12    /// PostgREST REST API backend (default).
13    Rest {
14        http: reqwest::Client,
15        base_url: Arc<str>,
16        api_key: Arc<str>,
17        schema: String,
18    },
19    /// Direct SQL via sqlx (opt-in with `direct-sql` feature).
20    #[cfg(feature = "direct-sql")]
21    DirectSql {
22        pool: Arc<PgPool>,
23    },
24}
25
26impl std::fmt::Debug for QueryBackend {
27    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28        match self {
29            Self::Rest { base_url, schema, .. } => {
30                f.debug_struct("Rest")
31                    .field("base_url", base_url)
32                    .field("schema", schema)
33                    .finish()
34            }
35            #[cfg(feature = "direct-sql")]
36            Self::DirectSql { .. } => f.debug_struct("DirectSql").finish(),
37        }
38    }
39}