Skip to main content

toolu_orm_query/
error.rs

1//! QueryError enum for query execution failures.
2
3use toolu_orm_core::error::DbCoreError;
4
5#[derive(Debug, thiserror::Error)]
6pub enum QueryError {
7  #[cfg(all(
8    feature = "libsql",
9    not(feature = "rusqlite"),
10    not(feature = "postgres")
11  ))]
12  #[error("database error: {0}")]
13  Driver(#[from] libsql::Error),
14
15  #[cfg(all(
16    feature = "rusqlite",
17    not(feature = "libsql"),
18    not(feature = "postgres")
19  ))]
20  #[error("database error: {0}")]
21  Driver(#[from] rusqlite::Error),
22
23  #[cfg(all(
24    feature = "postgres",
25    not(feature = "libsql"),
26    not(feature = "rusqlite")
27  ))]
28  #[error("database error: {0}")]
29  Driver(#[from] tokio_postgres::Error),
30
31  #[error("row mapping error for field '{field}': {source}")]
32  RowMapping { field: String, source: DbCoreError },
33
34  #[error("no rows found in table '{table}'")]
35  NotFound { table: String },
36
37  #[error("transaction failed: {0}")]
38  Transaction(Box<QueryError>),
39}
40
41impl From<DbCoreError> for QueryError {
42  fn from(e: DbCoreError) -> Self {
43    QueryError::RowMapping {
44      field: "unknown".to_owned(),
45      source: e,
46    }
47  }
48}