sql_middleware/
error.rs

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