mod executor; mod select; #[cfg(feature = "serialize-query-result")] mod select_json; pub use executor::*; pub use select::*; #[cfg(feature = "serialize-query-result")] pub use select_json::*; use crate::{DatabaseConnection, QueryResult, Statement, TypeErr}; use async_trait::async_trait; use std::{error::Error, fmt}; #[async_trait] pub trait Connector { fn accepts(string: &str) -> bool; async fn connect(string: &str) -> Result; } #[async_trait] pub trait Connection { async fn execute(&self, stmt: Statement) -> Result; async fn query_one(&self, stmt: Statement) -> Result; async fn query_all(&self, stmt: Statement) -> Result, QueryErr>; } #[derive(Debug)] pub struct QueryErr; #[derive(Debug)] pub struct ConnectionErr; // QueryErr // impl Error for QueryErr {} impl fmt::Display for QueryErr { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{:?}", self) } } impl From for QueryErr { fn from(_: TypeErr) -> QueryErr { QueryErr } } // ConnectionErr // impl Error for ConnectionErr {} impl fmt::Display for ConnectionErr { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{:?}", self) } }