#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum RowLock {
ForUpdate,
ForShare,
ForUpdateSkipLocked,
ForShareSkipLocked,
NoKeyUpdate,
KeyShare,
}
impl RowLock {
#[cfg(any(feature = "mysql", feature = "postgres"))]
pub(crate) const fn as_sql(self) -> &'static str {
match self {
Self::ForUpdate => "FOR UPDATE",
Self::ForShare => "FOR SHARE",
Self::ForUpdateSkipLocked => "FOR UPDATE SKIP LOCKED",
Self::ForShareSkipLocked => "FOR SHARE SKIP LOCKED",
Self::NoKeyUpdate => "FOR NO KEY UPDATE",
Self::KeyShare => "FOR KEY SHARE",
}
}
}
#[cfg(all(test, any(feature = "mysql", feature = "postgres")))]
mod tests {
use super::RowLock;
#[test]
fn skip_locked_modes_render_expected_sql() {
assert_eq!(
RowLock::ForUpdateSkipLocked.as_sql(),
"FOR UPDATE SKIP LOCKED"
);
assert_eq!(
RowLock::ForShareSkipLocked.as_sql(),
"FOR SHARE SKIP LOCKED"
);
assert_eq!(RowLock::ForUpdate.as_sql(), "FOR UPDATE");
assert_eq!(RowLock::ForShare.as_sql(), "FOR SHARE");
assert_eq!(RowLock::NoKeyUpdate.as_sql(), "FOR NO KEY UPDATE");
assert_eq!(RowLock::KeyShare.as_sql(), "FOR KEY SHARE");
}
}