Skip to content

Commit 3db1675

Browse files
feat(sqlx-core): add table function to database error (#2616)
1 parent afb6b10 commit 3db1675

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

sqlx-core/src/error.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,14 @@ pub trait DatabaseError: 'static + Send + Sync + StdError {
212212
None
213213
}
214214

215+
/// Returns the name of the table that was affected by the error, if applicable.
216+
///
217+
/// ### Note
218+
/// Currently only populated by the Postgres driver.
219+
fn table(&self) -> Option<&str> {
220+
None
221+
}
222+
215223
/// Returns the kind of the error, if supported.
216224
///
217225
/// ### Note

sqlx-postgres/src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ impl DatabaseError for PgDatabaseError {
204204
self.constraint()
205205
}
206206

207+
fn table(&self) -> Option<&str> {
208+
self.table()
209+
}
210+
207211
fn kind(&self) -> ErrorKind {
208212
match self.code() {
209213
error_codes::UNIQUE_VIOLATION => ErrorKind::UniqueViolation,

0 commit comments

Comments
 (0)