supabase_client_core/
config.rs1#[cfg(feature = "direct-sql")]
2use std::time::Duration;
3
4#[derive(Debug, Clone)]
9pub struct SupabaseConfig {
10 pub supabase_url: String,
12 pub supabase_key: String,
14 #[cfg(feature = "direct-sql")]
16 pub database_url: Option<String>,
17 pub schema: String,
19 #[cfg(feature = "direct-sql")]
21 pub pool: PoolConfig,
22}
23
24#[cfg(feature = "direct-sql")]
26#[derive(Debug, Clone)]
27pub struct PoolConfig {
28 pub max_connections: u32,
29 pub min_connections: u32,
30 pub acquire_timeout: Duration,
31 pub idle_timeout: Option<Duration>,
32 pub max_lifetime: Option<Duration>,
33}
34
35#[cfg(feature = "direct-sql")]
36impl Default for PoolConfig {
37 fn default() -> Self {
38 Self {
39 max_connections: 10,
40 min_connections: 1,
41 acquire_timeout: Duration::from_secs(30),
42 idle_timeout: Some(Duration::from_secs(600)),
43 max_lifetime: Some(Duration::from_secs(1800)),
44 }
45 }
46}
47
48impl SupabaseConfig {
49 pub fn new(supabase_url: impl Into<String>, supabase_key: impl Into<String>) -> Self {
53 Self {
54 supabase_url: supabase_url.into(),
55 supabase_key: supabase_key.into(),
56 #[cfg(feature = "direct-sql")]
57 database_url: None,
58 schema: "public".to_string(),
59 #[cfg(feature = "direct-sql")]
60 pool: PoolConfig::default(),
61 }
62 }
63
64 pub fn schema(mut self, schema: impl Into<String>) -> Self {
66 self.schema = schema.into();
67 self
68 }
69
70 #[cfg(feature = "direct-sql")]
72 pub fn database_url(mut self, url: impl Into<String>) -> Self {
73 self.database_url = Some(url.into());
74 self
75 }
76
77 #[cfg(feature = "direct-sql")]
79 pub fn max_connections(mut self, n: u32) -> Self {
80 self.pool.max_connections = n;
81 self
82 }
83
84 #[cfg(feature = "direct-sql")]
86 pub fn min_connections(mut self, n: u32) -> Self {
87 self.pool.min_connections = n;
88 self
89 }
90
91 #[cfg(feature = "direct-sql")]
93 pub fn acquire_timeout(mut self, timeout: Duration) -> Self {
94 self.pool.acquire_timeout = timeout;
95 self
96 }
97}