degen_sql/db/postgres/models/
model.rs1
2use std::mem::discriminant;
3
4use serde_json::Error as SerdeJsonError;
5use tokio_postgres::Error as PostgresError;
6
7pub trait Model {}
8
9#[derive(Debug, thiserror::Error )]
10pub enum PostgresModelError {
11 #[error("Timeout")]
12 Timeout,
13
14 #[error(transparent)]
15 Postgres(#[from] PostgresError),
16
17 #[error("UnexpectedRowsCount")]
18 UnexpectedRowsCount,
19
20 #[error(transparent)]
21 SerdeJson(#[from] SerdeJsonError),
22
23 #[error("Error parsing row for database: {0:?}")]
24 RowParseError(Option<String>),
25
26 #[error("ConnectionFailed ")]
27 ConnectionFailed ,
28
29 #[error("PoolCreationFailed {0:?}")]
30
31 PoolCreationFailed(String),
32
33
34 #[error("QueryFailed {0:?}")]
35 QueryFailed(tokio_postgres::Error),
36
37
38 #[error("PostgresError {0:?}")]
39 PostgresError(tokio_postgres::Error),
40
41 #[error("PoolError {0:?}")]
42 PoolError(deadpool::managed::PoolError<tokio_postgres::Error>),
43
44
45}
46
47impl PartialEq for PostgresModelError {
48 fn eq(&self, other: &Self) -> bool {
49 discriminant(self) == discriminant(other)
50 }
51}
52
53impl Eq for PostgresModelError {}
54
55
56impl From<deadpool::managed::PoolError<tokio_postgres::Error>> for PostgresModelError {
57 fn from(error: deadpool::managed::PoolError<tokio_postgres::Error>) -> Self {
58 PostgresModelError::PoolError(error)
59 }
60}