1use serde::{Deserialize, Serialize};
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
11pub enum TableLockMode {
12 AccessShare,
13 RowShare,
14 RowExclusive,
15 ShareUpdateExclusive,
16 Share,
17 ShareRowExclusive,
18 Exclusive,
19 AccessExclusive,
20}
21
22#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
23pub struct LockTableTarget {
24 pub name: String,
25 pub include_descendants: bool,
26}
27
28#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
29pub struct LockTableStmt {
30 pub targets: Vec<LockTableTarget>,
31 pub mode: TableLockMode,
32 pub nowait: bool,
33}
34
35#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
37pub struct LockingClause {
38 pub strength: LockStrength,
39 pub wait: LockWait,
40 pub relations: Vec<String>,
42}
43
44#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
46pub enum LockStrength {
47 ForKeyShare,
48 ForShare,
49 ForNoKeyUpdate,
50 ForUpdate,
51}
52
53impl LockStrength {
54 #[must_use]
56 pub const fn sql_name(self) -> &'static str {
57 match self {
58 Self::ForKeyShare => "FOR KEY SHARE",
59 Self::ForShare => "FOR SHARE",
60 Self::ForNoKeyUpdate => "FOR NO KEY UPDATE",
61 Self::ForUpdate => "FOR UPDATE",
62 }
63 }
64}
65
66#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
68pub enum LockWait {
69 Block,
70 SkipLocked,
71 NoWait,
72}