use klieo_core::error::MemoryError;
const UNDEFINED_TABLE: &str = "42P01";
pub(crate) fn store_err(e: sqlx::Error) -> MemoryError {
MemoryError::Store(e.to_string())
}
pub(crate) fn is_undefined_table(e: &sqlx::Error) -> bool {
matches!(e, sqlx::Error::Database(db) if db.code().as_deref() == Some(UNDEFINED_TABLE))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn store_err_routes_to_store_variant() {
let mem = store_err(sqlx::Error::PoolClosed);
assert!(matches!(mem, MemoryError::Store(_)));
}
#[test]
fn non_database_error_is_not_undefined_table() {
assert!(!is_undefined_table(&sqlx::Error::PoolClosed));
}
}