-
-
Notifications
You must be signed in to change notification settings - Fork 692
simplify specific db errors matching #1194
Copy link
Copy link
Closed
Milestone
Description
Motivation
Currently, matching DB specific errors is highly verbose, and I believe some common errors could benefit from being simplified. Current solution is the following: #1152
E.g.
match user::Entity::insert_many(models).exec(&state.db).await {
Err(DbErr::Query(RuntimeErr::SqlxError(sqlx::Error::Database(e))))
if e.code().unwrap().eq("23505") =>
{
// 23505 is postgresql error code for violation on column unique constraint
Ok()
}
Err(e) => Err(e),
Ok(_) => Ok()
}Proposed Solutions
I don't know every use cases and common errors, but I believe this ORM would benefit from simplifying error handling.
Another generic enum error could be created + custom DB error mapping logic to this newly created enum.
E.g.
enum DbErr {
ForeignKeyViolation { column: String, key: int },
NotNullViolation { column: String },
UniqueViolation { column: String },
...
}
Additional Information
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels