use std::io;
use odbc_api::{Error as OdbcError};
use chrono::ParseError;
use thiserror::Error;
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Error, Debug)]
pub enum Error {
#[error("ODBC error: {0}")]
Odbc(#[from] OdbcError),
#[error("Connection error: {0}")]
Connection(String),
#[error("Query error: {0}")]
Query(String),
#[error("Type conversion error: {0}")]
TypeConversion(String),
#[error("Encoding error: {0}")]
Encoding(String),
#[error("IO error: {0}")]
Io(#[from] io::Error),
#[error("Parse error: {0}")]
Parse(#[from] ParseError),
#[error("Serialization error: {0}")]
Serialization(String),
#[error("Transaction error: {0}")]
Transaction(String),
#[error("Configuration error: {0}")]
Configuration(String),
#[error("Database error: {0}")]
Database(String),
}
impl Error {
pub fn connection(message: impl Into<String>) -> Self {
Error::Connection(message.into())
}
pub fn query(message: impl Into<String>) -> Self {
Error::Query(message.into())
}
pub fn type_conversion(message: impl Into<String>) -> Self {
Error::TypeConversion(message.into())
}
pub fn serialization(message: impl Into<String>) -> Self {
Error::Serialization(message.into())
}
pub fn transaction(message: impl Into<String>) -> Self {
Error::Transaction(message.into())
}
pub fn configuration(message: impl Into<String>) -> Self {
Error::Configuration(message.into())
}
pub fn database(message: impl Into<String>) -> Self {
Error::Database(message.into())
}
}