1use std::sync::Arc;
2
3#[derive(Clone, Debug, thiserror::Error)]
4pub enum Error {
5 #[error("Database configuration error: {0}")]
6 Config(#[from] quokka_config::Error),
7 #[error("Unable to connect to database: {0:?}")]
8 ConnectionSetupError(ConnectionType),
9 #[error("Unable to find entity")]
10 NotFoundError,
11 #[error("Internal Server Error")]
12 DatabaseError(Arc<sqlx::Error>),
13 #[error("Unable to search entities")]
14 SearchError,
15 #[error("Unable to count entities")]
16 CountError,
17 #[error("Unable to map database data to entit {0}")]
18 EntityMapError(String),
19}
20
21#[derive(Clone, Debug)]
22pub enum ConnectionType {
23 Write,
24 Readonly,
25}
26
27pub type Result<T> = std::result::Result<T, Error>;
28
29impl From<sqlx::Error> for Error {
30 fn from(err: sqlx::Error) -> Self {
31 match err {
32 sqlx::Error::RowNotFound => Self::NotFoundError,
33 error => {
34 tracing::error!(?error, "Unknown Database Error");
35 Self::DatabaseError(error.into())
36 }
37 }
38 }
39}