Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Moving several struct variants out of Statement enum to allow for trait impls for specific sub-variants #2057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
LucaCappelletti94 wants to merge 12 commits into apache:main
base: main
Choose a base branch
Loading
from LucaCappelletti94:statement-structs
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
12 commits
Select commit Hold shift + click to select a range
67f0bca
Moved `Analyze` out of `Statement` enum
LucaCappelletti94 Oct 6, 2025
f006125
Moved `Truncate` out of the `Statement` enum
LucaCappelletti94 Oct 6, 2025
4862b28
Moved the `Msck` struct outside of `Statement` enum
LucaCappelletti94 Oct 6, 2025
9a4d235
Moved the `Update` struct out of the `Statement` enum
LucaCappelletti94 Oct 6, 2025
94f3b1b
Moved `CreateView` struct out of `Statement` enum
LucaCappelletti94 Oct 6, 2025
ef260ca
Moved `CreateRole` struct out of the `Statement` enum
LucaCappelletti94 Oct 6, 2025
1e18b87
Moved `CreateExtension` and `DropExtension` structs out of `Statement...
LucaCappelletti94 Oct 6, 2025
fa34d81
Fixed documentation error
LucaCappelletti94 Oct 6, 2025
112a96d
Reformatted code
LucaCappelletti94 Oct 6, 2025
8f70b00
Moved `AlterTable` struct out of `Statement`
LucaCappelletti94 Oct 6, 2025
20d1c9d
Moved `DropFunction` struct out of `Statement` enum
LucaCappelletti94 Oct 6, 2025
7782556
Restored previous implementation of `Spanned` trait for `CreateView`
LucaCappelletti94 Oct 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 112 additions & 1 deletion src/ast/dcl.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "visitor")]
use sqlparser_derive::{Visit, VisitMut};

use super::{display_comma_separated, Expr, Ident, Password};
use super::{display_comma_separated, Expr, Ident, Password, Spanned};
use crate::ast::{display_separated, ObjectName};
use crate::tokenizer::Span;

/// An option in `ROLE` statement.
///
Expand Down Expand Up @@ -252,3 +253,113 @@ impl fmt::Display for SecondaryRoles {
}
}
}

/// CREATE ROLE statement
/// See [PostgreSQL](https://www.postgresql.org/docs/current/sql-createrole.html)
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct CreateRole {
pub names: Vec<ObjectName>,
pub if_not_exists: bool,
// Postgres
pub login: Option<bool>,
pub inherit: Option<bool>,
pub bypassrls: Option<bool>,
pub password: Option<Password>,
pub superuser: Option<bool>,
pub create_db: Option<bool>,
pub create_role: Option<bool>,
pub replication: Option<bool>,
pub connection_limit: Option<Expr>,
pub valid_until: Option<Expr>,
pub in_role: Vec<Ident>,
pub in_group: Vec<Ident>,
pub role: Vec<Ident>,
pub user: Vec<Ident>,
pub admin: Vec<Ident>,
// MSSQL
pub authorization_owner: Option<ObjectName>,
}

impl fmt::Display for CreateRole {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"CREATE ROLE {if_not_exists}{names}{superuser}{create_db}{create_role}{inherit}{login}{replication}{bypassrls}",
if_not_exists = if self.if_not_exists { "IF NOT EXISTS " } else { "" },
names = display_separated(&self.names, ", "),
superuser = match self.superuser {
Some(true) => " SUPERUSER",
Some(false) => " NOSUPERUSER",
None => ""
},
create_db = match self.create_db {
Some(true) => " CREATEDB",
Some(false) => " NOCREATEDB",
None => ""
},
create_role = match self.create_role {
Some(true) => " CREATEROLE",
Some(false) => " NOCREATEROLE",
None => ""
},
inherit = match self.inherit {
Some(true) => " INHERIT",
Some(false) => " NOINHERIT",
None => ""
},
login = match self.login {
Some(true) => " LOGIN",
Some(false) => " NOLOGIN",
None => ""
},
replication = match self.replication {
Some(true) => " REPLICATION",
Some(false) => " NOREPLICATION",
None => ""
},
bypassrls = match self.bypassrls {
Some(true) => " BYPASSRLS",
Some(false) => " NOBYPASSRLS",
None => ""
}
)?;
if let Some(limit) = &self.connection_limit {
write!(f, " CONNECTION LIMIT {limit}")?;
}
match &self.password {
Some(Password::Password(pass)) => write!(f, " PASSWORD {pass}")?,
Some(Password::NullPassword) => write!(f, " PASSWORD NULL")?,
None => {}
};
if let Some(until) = &self.valid_until {
write!(f, " VALID UNTIL {until}")?;
}
if !self.in_role.is_empty() {
write!(f, " IN ROLE {}", display_comma_separated(&self.in_role))?;
}
if !self.in_group.is_empty() {
write!(f, " IN GROUP {}", display_comma_separated(&self.in_group))?;
}
if !self.role.is_empty() {
write!(f, " ROLE {}", display_comma_separated(&self.role))?;
}
if !self.user.is_empty() {
write!(f, " USER {}", display_comma_separated(&self.user))?;
}
if !self.admin.is_empty() {
write!(f, " ADMIN {}", display_comma_separated(&self.admin))?;
}
if let Some(owner) = &self.authorization_owner {
write!(f, " AUTHORIZATION {owner}")?;
}
Ok(())
}
}

impl Spanned for CreateRole {
fn span(&self) -> Span {
Span::empty()
}
}
Loading

AltStyle によって変換されたページ (->オリジナル) /