vibesql_ast/grant.rs
1//! GRANT statement AST structures
2//!
3//! This module defines AST structures for GRANT statements that assign privileges
4//! to roles/users on database objects.
5
6/// Privilege types that can be granted on database objects.
7#[derive(Debug, Clone, PartialEq)]
8pub enum PrivilegeType {
9 /// SELECT privilege (read access)
10 /// Optional column list for column-level SELECT privileges (SQL:1999 Feature F031-03)
11 Select(Option<Vec<String>>),
12 /// INSERT privilege (write access)
13 /// Optional column list for column-level INSERT privileges (SQL:1999 Feature F031-03)
14 Insert(Option<Vec<String>>),
15 /// UPDATE privilege (modify access)
16 /// Optional column list for column-level UPDATE privileges (SQL:1999 Feature E081-05)
17 Update(Option<Vec<String>>),
18 /// DELETE privilege (delete access)
19 Delete,
20 /// REFERENCES privilege (foreign key access)
21 /// Optional column list for column-level REFERENCES privileges (SQL:1999 Feature E081-07)
22 References(Option<Vec<String>>),
23 /// USAGE privilege (schema/sequence usage)
24 Usage,
25 /// CREATE privilege (create objects in schema)
26 Create,
27 /// EXECUTE privilege (function/procedure execution)
28 Execute,
29 /// TRIGGER privilege (create triggers on table)
30 Trigger,
31 /// UNDER privilege (create subtypes of user-defined type)
32 Under,
33 /// ALL PRIVILEGES (all applicable privileges for the object type)
34 AllPrivileges,
35}
36
37/// Types of database objects that can have privileges granted on them.
38#[derive(Debug, Clone, PartialEq)]
39pub enum ObjectType {
40 /// Table object
41 Table,
42 /// Schema object
43 Schema,
44 /// Domain object - user-defined data type with constraints (SQL:1999 Feature F031-03)
45 Domain,
46 /// Collation object - character comparison rules (SQL:1999 Feature F031-06)
47 Collation,
48 /// Character set object - character encoding definitions (SQL:1999 Feature F031-08)
49 CharacterSet,
50 /// Translation object - character set conversions (SQL:1999 Feature F031-09)
51 Translation,
52 /// Type object - user-defined types (SQL:1999 Feature F031-10)
53 Type,
54 /// Sequence object - auto-increment sequences (SQL:1999 Feature F031-11)
55 Sequence,
56 /// Function object (SQL:1999 Feature P001)
57 Function,
58 /// Procedure object (SQL:1999 Feature P001)
59 Procedure,
60 /// Routine object (generic term covering both functions and procedures)
61 Routine,
62 /// Method object (SQL:1999 Feature S091)
63 Method,
64 /// Constructor method for user-defined types
65 ConstructorMethod,
66 /// Static method for user-defined types
67 StaticMethod,
68 /// Instance method for user-defined types
69 InstanceMethod,
70 /// Specific function - function by signature (SQL:1999 Feature F031-15)
71 SpecificFunction,
72 /// Specific procedure - procedure by signature (SQL:1999 Feature F031-16)
73 SpecificProcedure,
74 /// Specific routine - routine by signature (SQL:1999 Feature F031-17)
75 SpecificRoutine,
76 /// Specific method - method by signature (SQL:1999 Feature F031-12)
77 SpecificMethod,
78 /// Specific constructor method (SQL:1999 Feature F031-12)
79 SpecificConstructorMethod,
80 /// Specific static method (SQL:1999 Feature F031-12)
81 SpecificStaticMethod,
82 /// Specific instance method (SQL:1999 Feature F031-12)
83 SpecificInstanceMethod,
84}
85
86/// GRANT statement - assigns privileges to roles/users.
87///
88/// Example SQL:
89/// ```sql
90/// GRANT SELECT ON TABLE users TO manager;
91/// GRANT INSERT, UPDATE ON TABLE orders TO clerk;
92/// GRANT ALL PRIVILEGES ON TABLE products TO admin WITH GRANT OPTION;
93/// GRANT EXECUTE ON METHOD calculate FOR address_type TO app_role;
94/// ```
95#[derive(Debug, Clone, PartialEq)]
96pub struct GrantStmt {
97 /// List of privileges being granted
98 pub privileges: Vec<PrivilegeType>,
99 /// Type of object (TABLE, SCHEMA, etc.)
100 pub object_type: ObjectType,
101 /// Name of the object (table, schema, etc.) - supports qualified names like "schema.table"
102 pub object_name: String,
103 /// Optional type name for method/routine objects (e.g., "FOR address_type")
104 pub for_type_name: Option<String>,
105 /// List of roles/users receiving the privileges
106 pub grantees: Vec<String>,
107 /// Whether grantees can grant these privileges to others
108 pub with_grant_option: bool,
109}