Skip to main content

linkrs_query/parser/ast/stmt/
dcl.rs

1use linkrs_core::types::Span;
2
3#[derive(Debug, Clone, PartialEq)]
4pub struct CreateUserStmt {
5    pub span: Span,
6    pub username: String,
7    pub password: String,
8    pub if_not_exists: bool,
9}
10
11#[derive(Debug, Clone, PartialEq)]
12pub struct AlterUserStmt {
13    pub span: Span,
14    pub username: String,
15    pub password: Option<String>,
16    pub is_locked: Option<bool>,
17}
18
19#[derive(Debug, Clone, PartialEq)]
20pub struct DropUserStmt {
21    pub span: Span,
22    pub username: String,
23    pub if_exists: bool,
24}
25
26#[derive(Debug, Clone, PartialEq)]
27pub struct ChangePasswordStmt {
28    pub span: Span,
29    pub username: Option<String>,
30    pub old_password: String,
31    pub new_password: String,
32}
33
34#[derive(Debug, Clone, Copy, PartialEq, Eq)]
35pub enum RoleType {
36    God,
37    Admin,
38    Dba,
39    User,
40    Guest,
41}
42
43impl RoleType {
44    pub fn as_str(&self) -> &'static str {
45        match self {
46            RoleType::God => "GOD",
47            RoleType::Admin => "ADMIN",
48            RoleType::Dba => "DBA",
49            RoleType::User => "USER",
50            RoleType::Guest => "GUEST",
51        }
52    }
53}
54
55impl std::str::FromStr for RoleType {
56    type Err = String;
57
58    fn from_str(s: &str) -> Result<Self, Self::Err> {
59        match s.to_uppercase().as_str() {
60            "GOD" => Ok(RoleType::God),
61            "ADMIN" => Ok(RoleType::Admin),
62            "DBA" => Ok(RoleType::Dba),
63            "USER" => Ok(RoleType::User),
64            "GUEST" => Ok(RoleType::Guest),
65            _ => Err(format!("Unknown role type: {}", s)),
66        }
67    }
68}
69
70#[derive(Debug, Clone, PartialEq)]
71pub struct GrantStmt {
72    pub span: Span,
73    pub role: RoleType,
74    pub space_name: String,
75    pub username: String,
76}
77
78#[derive(Debug, Clone, PartialEq)]
79pub struct RevokeStmt {
80    pub span: Span,
81    pub role: RoleType,
82    pub space_name: String,
83    pub username: String,
84}
85
86#[derive(Debug, Clone, PartialEq)]
87pub struct DescribeUserStmt {
88    pub span: Span,
89    pub username: String,
90}
91
92#[derive(Debug, Clone, PartialEq)]
93pub struct ShowUsersStmt {
94    pub span: Span,
95}
96
97#[derive(Debug, Clone, PartialEq)]
98pub struct ShowRolesStmt {
99    pub span: Span,
100    pub space_name: Option<String>,
101}