use klieo_core::error::MemoryError;
use sqlx_core::error::Error as SqlxError;
const UNDEFINED_TABLE: &str = "42P01";
pub(crate) fn store_err(e: SqlxError) -> MemoryError {
MemoryError::Store(e.to_string())
}
pub(crate) fn is_undefined_table(e: &SqlxError) -> bool {
matches!(e, SqlxError::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(SqlxError::PoolClosed);
assert!(matches!(mem, MemoryError::Store(_)));
}
#[test]
fn non_database_error_is_not_undefined_table() {
assert!(!is_undefined_table(&SqlxError::PoolClosed));
}
}