ddnet_account_sql/
lib.rs

1//! This crate contains a interfaces for common tasks
2//! on the database.
3
4#![deny(missing_docs)]
5#![deny(warnings)]
6#![deny(clippy::nursery)]
7#![deny(clippy::all)]
8
9use any::AnyQueryResult;
10
11#[cfg(not(any(feature = "mysql", feature = "sqlite")))]
12std::compile_error!("at least the mysql or sqlite feature must be used.");
13
14/// Our version of sqlx any variants
15pub mod any;
16/// Everything related to queries
17pub mod query;
18/// Everything related to versioning table setups
19pub mod version;
20
21/// Checks if the query result resulted in an error that indicates
22/// a duplicate entry.
23pub fn is_duplicate_entry(res: &Result<AnyQueryResult, sqlx::Error>) -> bool {
24    res.as_ref().is_err_and(|err| {
25        if let sqlx::Error::Database(err) = err {
26            matches!(err.kind(), sqlx::error::ErrorKind::UniqueViolation)
27        } else {
28            false
29        }
30    })
31}