Skip to content

Commit 9da2c75

Browse files
committed
Add conflict error helper
1 parent e1980ff commit 9da2c75

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

v-model/src/storage/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::fmt::Debug;
77
pub use async_bb8_diesel::{ConnectionError, PoolError};
88
use async_trait::async_trait;
99
use bb8::RunError;
10+
use diesel::result::{DatabaseErrorKind, Error as DieselError};
1011
pub use diesel::result::Error as DbError;
1112
#[cfg(feature = "mock")]
1213
use mockall::automock;
@@ -43,6 +44,18 @@ pub enum StoreError {
4344
Unknown,
4445
}
4546

47+
impl StoreError {
48+
pub fn is_unique_conflict_err(&self) -> bool {
49+
match self {
50+
Self::Db(DieselError::DatabaseError(
51+
DatabaseErrorKind::UniqueViolation,
52+
_,
53+
)) => true,
54+
_ => false
55+
}
56+
}
57+
}
58+
4659
#[derive(Debug, PartialEq)]
4760
pub struct ListPagination {
4861
pub offset: i64,

0 commit comments

Comments
 (0)