Skip to main content

uqa_sql/ast/
type_privileges.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! `GRANT | REVOKE ... ON TYPE | DOMAIN`.
8
9use serde::{Deserialize, Serialize};
10
11use super::{AclRoleSpecification, RoleSpecification, TypeObjectKind};
12
13/// A privilege named by `GRANT | REVOKE ... ON TYPE | DOMAIN`. Types have only `USAGE`; other names are rejected after the targets are resolved, as `PostgreSQL` does.
14#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
15pub enum TypePrivilege {
16    Usage,
17    Unsupported(String),
18}
19
20#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
21pub enum TypeRevokeBehavior {
22    Restrict,
23    Cascade,
24}
25
26/// `GRANT | REVOKE [GRANT OPTION FOR] privileges ON TYPE | DOMAIN names TO | FROM grantees [WITH GRANT OPTION] [GRANTED BY role] [CASCADE | RESTRICT]`. An empty privilege list is `ALL [PRIVILEGES]`.
27#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct GrantTypeStmt {
29    pub kind: TypeObjectKind,
30    pub is_grant: bool,
31    pub grant_option: bool,
32    pub grant_option_only: bool,
33    pub privileges: Vec<TypePrivilege>,
34    /// Rendered, possibly qualified type names as written.
35    pub names: Vec<String>,
36    pub grantees: Vec<AclRoleSpecification>,
37    pub grantor: Option<RoleSpecification>,
38    pub revoke_behavior: TypeRevokeBehavior,
39}