use sqlx_core::error::{DatabaseError, Error, ErrorKind};
use std::{error::Error as StdError, fmt};
pub(crate) fn unsupported(operation: &str) -> Error {
Error::Protocol(format!("sqlx-turso: {operation} is not supported"))
}
#[derive(Debug)]
pub struct TursoDatabaseError {
source: turso::Error,
message: String,
}
impl fmt::Display for TursoDatabaseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.message)
}
}
impl StdError for TursoDatabaseError {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
Some(&self.source)
}
}
impl DatabaseError for TursoDatabaseError {
fn message(&self) -> &str {
&self.message
}
fn as_error(&self) -> &(dyn StdError + Send + Sync + 'static) {
self
}
fn as_error_mut(&mut self) -> &mut (dyn StdError + Send + Sync + 'static) {
self
}
fn into_error(self: Box<Self>) -> Box<dyn StdError + Send + Sync + 'static> {
self
}
fn kind(&self) -> ErrorKind {
ErrorKind::Other
}
}
pub(crate) fn engine_error(source: turso::Error) -> Error {
TursoDatabaseError {
message: source.to_string(),
source,
}
.into()
}