Debian Codegraph @

src/query_builder/locking_clause.rs

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