1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//! Database object types for DCL statements
/// Database object types for DCL statements
///
/// This enum represents the various types of database objects that can
/// be targets of GRANT and REVOKE statements.
///
/// # Examples
///
/// ```
/// use reinhardt_query::dcl::ObjectType;
///
/// let object_type = ObjectType::Table;
/// assert_eq!(object_type.as_sql(), "TABLE");
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ObjectType {
/// Database tables
Table,
/// Entire databases
Database,
/// Database schemas (PostgreSQL-specific)
Schema,
/// Sequence objects (PostgreSQL-specific)
Sequence,
/// Functions (PostgreSQL-specific)
Function,
/// Procedures (PostgreSQL-specific)
Procedure,
/// Routines - functions or procedures (PostgreSQL-specific)
Routine,
/// User-defined types (PostgreSQL-specific)
Type,
/// Domain types (PostgreSQL-specific)
Domain,
/// Foreign data wrappers (PostgreSQL-specific)
ForeignDataWrapper,
/// Foreign servers (PostgreSQL-specific)
ForeignServer,
/// Procedural languages (PostgreSQL-specific)
Language,
/// Large objects (PostgreSQL-specific)
LargeObject,
/// Tablespaces (PostgreSQL-specific)
Tablespace,
/// Configuration parameters (PostgreSQL-specific)
Parameter,
}
impl ObjectType {
/// Returns the SQL keyword for this object type
///
/// # Examples
///
/// ```
/// use reinhardt_query::dcl::ObjectType;
///
/// assert_eq!(ObjectType::Table.as_sql(), "TABLE");
/// assert_eq!(ObjectType::Database.as_sql(), "DATABASE");
/// ```
pub fn as_sql(&self) -> &'static str {
match self {
ObjectType::Table => "TABLE",
ObjectType::Database => "DATABASE",
ObjectType::Schema => "SCHEMA",
ObjectType::Sequence => "SEQUENCE",
ObjectType::Function => "FUNCTION",
ObjectType::Procedure => "PROCEDURE",
ObjectType::Routine => "ROUTINE",
ObjectType::Type => "TYPE",
ObjectType::Domain => "DOMAIN",
ObjectType::ForeignDataWrapper => "FOREIGN DATA WRAPPER",
ObjectType::ForeignServer => "FOREIGN SERVER",
ObjectType::Language => "LANGUAGE",
ObjectType::LargeObject => "LARGE OBJECT",
ObjectType::Tablespace => "TABLESPACE",
ObjectType::Parameter => "PARAMETER",
}
}
/// Checks if this object type is PostgreSQL-specific
///
/// Returns `true` for object types that are only available in PostgreSQL,
/// `false` for object types that are common to both PostgreSQL and MySQL.
///
/// # Examples
///
/// ```
/// use reinhardt_query::dcl::ObjectType;
///
/// assert!(!ObjectType::Table.is_postgres_only()); // Common
/// assert!(ObjectType::Schema.is_postgres_only()); // PostgreSQL-specific
/// ```
pub fn is_postgres_only(&self) -> bool {
matches!(
self,
ObjectType::Schema
| ObjectType::Sequence
| ObjectType::Function
| ObjectType::Procedure
| ObjectType::Routine
| ObjectType::Type
| ObjectType::Domain
| ObjectType::ForeignDataWrapper
| ObjectType::ForeignServer
| ObjectType::Language
| ObjectType::LargeObject
| ObjectType::Tablespace
| ObjectType::Parameter
)
}
}