diesel/query_dsl/
locking_dsl.rs

1#[cfg(feature = "with-deprecated")]
2use query_builder::locking_clause::ForUpdate;
3use query_builder::AsQuery;
4use query_source::Table;
5
6/// The `for_update` method
7///
8/// This trait should not be relied on directly by most apps. Its behavior is
9/// provided by [`QueryDsl`]. However, you may need a where clause on this trait
10/// to call `for_update` from generic code.
11///
12/// [`QueryDsl`]: ../trait.QueryDsl.html
13#[cfg(feature = "with-deprecated")]
14#[deprecated(since = "1.3.0", note = "use `LockingDsl<ForUpdate>` instead")]
15pub trait ForUpdateDsl {
16    /// The type returned by `for_update`. See [`dsl::ForUpdate`] for
17    /// convenient access to this type.
18    ///
19    /// [`dsl::ForUpdate`]: ../../dsl/type.ForUpdate.html
20    type Output;
21
22    /// See the trait level documentation
23    fn for_update(self) -> Self::Output;
24}
25
26#[cfg(feature = "with-deprecated")]
27#[allow(deprecated)]
28impl<T> ForUpdateDsl for T
29where
30    T: LockingDsl<ForUpdate>,
31{
32    type Output = <T as LockingDsl<ForUpdate>>::Output;
33
34    fn for_update(self) -> Self::Output {
35        self.with_lock(ForUpdate)
36    }
37}
38
39/// Methods related to locking select statements
40///
41/// This trait should not be relied on directly by most apps. Its behavior is
42/// provided by [`QueryDsl`]. However, you may need a where clause on this trait
43/// to call `for_update` from generic code.
44///
45/// [`QueryDsl`]: ../trait.QueryDsl.html
46pub trait LockingDsl<Lock> {
47    /// The type returned by `set_lock`. See [`dsl::ForUpdate`] and friends for
48    /// convenient access to this type.
49    ///
50    /// [`dsl::ForUpdate`]: ../../dsl/type.ForUpdate.html
51    type Output;
52
53    /// See the trait level documentation
54    fn with_lock(self, lock: Lock) -> Self::Output;
55}
56
57impl<T, Lock> LockingDsl<Lock> for T
58where
59    T: Table + AsQuery,
60    T::Query: LockingDsl<Lock>,
61{
62    type Output = <T::Query as LockingDsl<Lock>>::Output;
63
64    fn with_lock(self, lock: Lock) -> Self::Output {
65        self.as_query().with_lock(lock)
66    }
67}
68
69/// Methods related to modifiers on locking select statements
70///
71/// This trait should not be relied on directly by most apps. Its behavior is
72/// provided by [`QueryDsl`]. However, you may need a where clause on this trait
73/// to call `skip_locked` from generic code.
74///
75/// [`QueryDsl`]: ../trait.QueryDsl.html
76pub trait ModifyLockDsl<Modifier> {
77    /// The type returned by `modify_lock`. See [`dsl::SkipLocked`] and friends
78    /// for convenient access to this type.
79    ///
80    /// [`dsl::SkipLocked`]: ../../dsl/type.SkipLocked.html
81    type Output;
82
83    /// See the trait level documentation
84    fn modify_lock(self, modifier: Modifier) -> Self::Output;
85}