wae_database/connection/
config.rs1use serde::{Deserialize, Serialize};
4#[cfg(feature = "turso")]
5use std::path::PathBuf;
6use wae_types::{WaeError, WaeResult};
7
8pub type DatabaseResult<T> = WaeResult<T>;
10
11pub type DatabaseError = WaeError;
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
16pub enum DatabaseConfig {
17 #[cfg(feature = "turso")]
19 Turso {
20 path: Option<PathBuf>,
22 },
23 #[cfg(feature = "postgres")]
25 Postgres {
26 connection_string: String,
28 max_connections: Option<usize>,
30 },
31 #[cfg(feature = "mysql")]
33 MySql {
34 connection_string: String,
36 max_connections: Option<usize>,
38 },
39}
40
41impl DatabaseConfig {
42 #[cfg(feature = "turso")]
44 pub fn turso_in_memory() -> Self {
45 Self::Turso { path: None }
46 }
47
48 #[cfg(feature = "turso")]
50 pub fn turso_file<P: Into<PathBuf>>(path: P) -> Self {
51 Self::Turso { path: Some(path.into()) }
52 }
53
54 #[cfg(feature = "postgres")]
56 pub fn postgres<S: Into<String>>(connection_string: S) -> Self {
57 Self::Postgres { connection_string: connection_string.into(), max_connections: None }
58 }
59
60 #[cfg(feature = "postgres")]
62 pub fn postgres_with_max_connections<S: Into<String>>(connection_string: S, max_connections: usize) -> Self {
63 Self::Postgres { connection_string: connection_string.into(), max_connections: Some(max_connections) }
64 }
65
66 #[cfg(feature = "mysql")]
68 pub fn mysql<S: Into<String>>(connection_string: S) -> Self {
69 Self::MySql { connection_string: connection_string.into(), max_connections: None }
70 }
71
72 #[cfg(feature = "mysql")]
74 pub fn mysql_with_max_connections<S: Into<String>>(connection_string: S, max_connections: usize) -> Self {
75 Self::MySql { connection_string: connection_string.into(), max_connections: Some(max_connections) }
76 }
77}