wae_database/connection/
statement.rs1use crate::connection::{config::DatabaseResult, row::DatabaseRows};
4use wae_types::WaeError;
5
6pub enum DatabaseStatement {
8 #[cfg(feature = "turso")]
10 Turso(turso::Statement),
11 #[cfg(feature = "postgres")]
13 Postgres(String),
14 #[cfg(feature = "mysql")]
16 MySql(String),
17}
18
19impl DatabaseStatement {
20 #[cfg(feature = "turso")]
21 pub(crate) fn new_turso(stmt: turso::Statement) -> Self {
22 Self::Turso(stmt)
23 }
24
25 #[cfg(feature = "postgres")]
26 pub(crate) fn new_postgres(sql: String) -> Self {
27 Self::Postgres(sql)
28 }
29
30 #[cfg(feature = "mysql")]
31 pub(crate) fn new_mysql(sql: String) -> Self {
32 Self::MySql(sql)
33 }
34
35 pub async fn query(&mut self, _params: Vec<wae_types::Value>) -> DatabaseResult<DatabaseRows> {
37 match self {
38 #[cfg(feature = "turso")]
39 Self::Turso(stmt) => {
40 let turso_params = crate::types::from_wae_values(_params);
41 stmt.query(turso_params)
42 .await
43 .map_err(|e| WaeError::internal(format!("Query failed: {}", e)))
44 .map(DatabaseRows::new_turso)
45 }
46 #[cfg(feature = "postgres")]
47 Self::Postgres(_) => Err(WaeError::internal("Prepared statements not supported for Postgres yet")),
48 #[cfg(feature = "mysql")]
49 Self::MySql(_) => Err(WaeError::internal("Prepared statements not supported for MySQL yet")),
50 }
51 }
52}