1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
pub use self::QueryOneError::NoRowsReturned;
pub use tokio_postgres::error::{DbError, ErrorPosition, Severity, SqlState};
use af_core::prelude::*;
use af_core::string::SharedString;
pub type Result<T = (), E = Error> = std::result::Result<T, E>;
#[derive(Debug, Error)]
pub enum Error {
#[error(transparent)]
Db(Box<DbError>),
#[error("{0}")]
Other(SharedString),
}
#[derive(Debug, Error)]
pub enum QueryOneError {
#[error("No rows returned.")]
NoRowsReturned,
#[error(transparent)]
Other(#[from] Error),
}
impl Error {
pub fn new(message: impl Into<SharedString>) -> Self {
Self::Other(message.into())
}
}
impl From<tokio_postgres::Error> for Error {
fn from(err: tokio_postgres::Error) -> Self {
match err.code() {
Some(_) => Error::Db(std::error::Error::downcast(err.into_source().unwrap()).unwrap()),
None => Error::Other(err.to_string().into()),
}
}
}