sharenet/backend/crates/db/src/postgres.rs
2025-03-26 21:31:13 -04:00

26 lines
529 B
Rust

use sqlx::PgPool;
pub type DBConn = PgPool;
const UNIQUE_CONSTRAINT_VIOLATION_CODE: &str = "2067";
fn is_unique_constraint_violation(err: &sqlx::Error) -> bool {
if let sqlx::Error::Database(db_err) = err {
if let Some(code) = db_err.code() {
if code == UNIQUE_CONSTRAINT_VIOLATION_CODE {
return true;
}
}
}
false
}
fn is_row_not_found_error(err: &sqlx::Error) -> bool {
if let sqlx::Error::RowNotFound = err {
return true;
}
false
}