use std::fmt::Debug;
use thiserror::Error;
#[derive(Error, Debug, Clone)]
pub enum PostgresError {
#[error("Connection error: {0}")]
ConnectionError(String),
#[error("Query execution error: {0}")]
QueryError(String),
#[error("Database creation error: {0}")]
DatabaseCreationError(String),
#[error("Database drop error: {0}")]
DatabaseDropError(String),
#[error("Transaction error: {0}")]
TransactionError(String),
#[error("Configuration error: {0}")]
ConfigError(String),
#[error("Pool creation error: {0}")]
PoolCreationError(String),
#[error("Other error: {0}")]
Other(String),
}
impl From<String> for PostgresError {
fn from(s: String) -> Self {
Self::Other(s)
}
}
impl From<&str> for PostgresError {
fn from(s: &str) -> Self {
Self::Other(s.to_string())
}
}
#[cfg(feature = "with-tokio-postgres")]
impl From<tokio_postgres::Error> for PostgresError {
fn from(err: tokio_postgres::Error) -> Self {
Self::QueryError(err.to_string())
}
}
#[cfg(feature = "with-sqlx")]
impl From<sqlx::Error> for PostgresError {
fn from(err: sqlx::Error) -> Self {
Self::QueryError(err.to_string())
}
}