|
| 1 | +use backend::Backend; |
| 2 | +use query_builder::{AstPass, QueryFragment}; |
| 3 | +use result::QueryResult; |
| 4 | + |
| 5 | +#[derive(Debug, Clone, Copy, QueryId)] |
| 6 | +pub struct NoLockingClause; |
| 7 | + |
| 8 | +impl<DB: Backend> QueryFragment<DB> for NoLockingClause { |
| 9 | + fn walk_ast(&self, _: AstPass<DB>) -> QueryResult<()> { |
| 10 | + Ok(()) |
| 11 | + } |
| 12 | +} |
| 13 | + |
| 14 | +#[derive(Debug, Clone, Copy, QueryId)] |
| 15 | +pub struct LockingClause<LockMode = ForUpdate, Modifier = NoModifier> { |
| 16 | + pub(crate) lock_mode: LockMode, |
| 17 | + modifier: Modifier, |
| 18 | +} |
| 19 | + |
| 20 | +impl<LockMode, Modifier> LockingClause<LockMode, Modifier> { |
| 21 | + pub(crate) fn new(lock_mode: LockMode, modifier: Modifier) -> Self { |
| 22 | + LockingClause { lock_mode, modifier } |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +impl<DB: Backend, L: QueryFragment<DB>, M: QueryFragment<DB>> QueryFragment<DB> for LockingClause<L, M> { |
| 27 | + fn walk_ast(&self, mut out: AstPass<DB>) -> QueryResult<()> { |
| 28 | + self.lock_mode.walk_ast(out.reborrow())?; |
| 29 | + self.modifier.walk_ast(out.reborrow()) |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +/// LockMode parameters |
| 34 | +/// All the different types of row locks that can be acquired. |
| 35 | +#[derive(Debug, Clone, Copy, QueryId)] |
| 36 | +pub struct ForUpdate; |
| 37 | + |
| 38 | +#[derive(Debug, Clone, Copy, QueryId)] |
| 39 | +pub struct ForNoKeyUpdate; |
| 40 | + |
| 41 | +#[derive(Debug, Clone, Copy, QueryId)] |
| 42 | +pub struct ForShare; |
| 43 | + |
| 44 | +#[derive(Debug, Clone, Copy, QueryId)] |
| 45 | +pub struct ForKeyShare; |
| 46 | + |
| 47 | +/// Modifiers |
| 48 | +/// To be used in conjunction with a lock mode. |
| 49 | +#[derive(Debug, Clone, Copy, QueryId)] |
| 50 | +pub struct NoModifier; |
| 51 | + |
| 52 | +#[derive(Debug, Clone, Copy, QueryId)] |
| 53 | +pub struct SkipLocked; |
| 54 | + |
| 55 | +#[derive(Debug, Clone, Copy, QueryId)] |
| 56 | +pub struct NoWait; |
0 commit comments