mod sqldb;
pub use sqldb::*;
use wasmbus_rpc::error::RpcError;
pub use minicbor;
impl SqlDbError {
pub fn new<T: ToString>(code: T, message: String) -> SqlDbError {
SqlDbError {
code: code.to_string(),
message,
}
}
}
impl std::fmt::Display for SqlDbError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "SqlDbError {}: {}", &self.code, &self.message)
}
}
impl From<minicbor::decode::Error> for SqlDbError {
fn from(e: minicbor::decode::Error) -> SqlDbError {
SqlDbError {
code: "decoding".to_string(),
message: e.to_string(),
}
}
}
impl From<SqlDbError> for RpcError {
fn from(e: SqlDbError) -> RpcError {
RpcError::Other(format!("SqlDb error {}: {}", e.code, e.message))
}
}
impl From<RpcError> for SqlDbError {
fn from(e: RpcError) -> SqlDbError {
SqlDbError::new("rpc", e.to_string())
}
}
impl From<String> for Statement {
fn from(sql: String) -> Statement {
Statement {
database: None,
parameters: None,
sql,
}
}
}