1use thiserror::Error;
2
3#[cfg(any(feature = "postgres", feature = "mssql"))]
4use bb8;
5
6#[cfg(feature = "mssql")]
7use bb8_tiberius::Error as Bb8TiberiusError;
8
9#[cfg(feature = "sqlite")]
10use rusqlite;
11#[cfg(feature = "mssql")]
12use tiberius;
13#[cfg(feature = "postgres")]
14use tokio_postgres;
15#[cfg(feature = "turso")]
16use turso;
17
18#[derive(Debug, Error)]
19pub enum SqlMiddlewareDbError {
20 #[cfg(feature = "postgres")]
21 #[error(transparent)]
22 PostgresError(#[from] tokio_postgres::Error),
23
24 #[cfg(feature = "sqlite")]
25 #[error(transparent)]
26 SqliteError(#[from] rusqlite::Error),
27
28 #[cfg(feature = "mssql")]
29 #[error(transparent)]
30 MssqlError(#[from] tiberius::error::Error),
31
32 #[cfg(feature = "postgres")]
33 #[error(transparent)]
34 PoolErrorPostgres(#[from] bb8::RunError<tokio_postgres::Error>),
35
36 #[cfg(feature = "mssql")]
37 #[error(transparent)]
38 PoolErrorMssql(#[from] bb8::RunError<Bb8TiberiusError>),
39
40 #[cfg(feature = "turso")]
41 #[error(transparent)]
42 TursoError(#[from] turso::Error),
43
44 #[error("Configuration error: {0}")]
45 ConfigError(String),
46
47 #[error("Connection error: {0}")]
48 ConnectionError(String),
49
50 #[error("Parameter conversion error: {0}")]
51 ParameterError(String),
52
53 #[error("SQL execution error: {0}")]
54 ExecutionError(String),
55
56 #[error("Unimplemented feature: {0}")]
57 Unimplemented(String),
58
59 #[error("Other database error: {0}")]
60 Other(String),
61}
62
63#[cfg(feature = "sqlite")]
64impl From<bb8::RunError<SqlMiddlewareDbError>> for SqlMiddlewareDbError {
65 fn from(err: bb8::RunError<SqlMiddlewareDbError>) -> Self {
66 SqlMiddlewareDbError::ConnectionError(format!("SQLite pool error: {err}"))
67 }
68}