Skip to content

Commit

Permalink
feat(sqlx-core): add table function to database error (#2616)
Browse files Browse the repository at this point in the history
  • Loading branch information
saiintbrisson authored Jul 14, 2023
1 parent afb6b10 commit 3db1675
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sqlx-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ pub trait DatabaseError: 'static + Send + Sync + StdError {
None
}

/// Returns the name of the table that was affected by the error, if applicable.
///
/// ### Note
/// Currently only populated by the Postgres driver.
fn table(&self) -> Option<&str> {
None
}

/// Returns the kind of the error, if supported.
///
/// ### Note
Expand Down
4 changes: 4 additions & 0 deletions sqlx-postgres/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ impl DatabaseError for PgDatabaseError {
self.constraint()
}

fn table(&self) -> Option<&str> {
self.table()
}

fn kind(&self) -> ErrorKind {
match self.code() {
error_codes::UNIQUE_VIOLATION => ErrorKind::UniqueViolation,
Expand Down

0 comments on commit 3db1675

Please sign in to comment.