Skip to content
11 changes: 10 additions & 1 deletion src/ast/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,16 @@ pub enum Comment {
/// until end-of-line or end-of-file in the source code.
///
/// Note: `content` will include the terminating new-line character, if any.
SingleLine { content: String, prefix: String },
/// A single-line comment, typically introduced with a prefix and spanning
/// until end-of-line or end-of-file in the source code.
///
/// Note: `content` will include the terminating new-line character, if any.
SingleLine {
/// The content of the comment (including trailing newline, if any).
content: String,
/// The prefix introducing the comment (e.g. `--`, `#`).
prefix: String,
},

/// A multi-line comment, typically enclosed in `/* .. */` markers. The
/// string represents the content excluding the markers.
Expand Down
45 changes: 36 additions & 9 deletions src/ast/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ use super::{value::escape_single_quote_string, ColumnDef};
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
/// A member of an ENUM type.
pub enum EnumMember {
/// Just a name.
Name(String),
/// ClickHouse allows to specify an integer value for each enum value.
///
Expand Down Expand Up @@ -957,18 +959,31 @@ impl fmt::Display for TimezoneInfo {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum IntervalFields {
/// `YEAR` field
Year,
/// `MONTH` field
Month,
/// `DAY` field
Day,
/// `HOUR` field
Hour,
/// `MINUTE` field
Minute,
/// `SECOND` field
Second,
/// `YEAR TO MONTH` field
YearToMonth,
/// `DAY TO HOUR` field
DayToHour,
/// `DAY TO MINUTE` field
DayToMinute,
/// `DAY TO SECOND` field
DayToSecond,
/// `HOUR TO MINUTE` field
HourToMinute,
/// `HOUR TO SECOND` field
HourToSecond,
/// `MINUTE TO SECOND` field
MinuteToSecond,
}

Expand Down Expand Up @@ -1000,11 +1015,11 @@ impl fmt::Display for IntervalFields {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum ExactNumberInfo {
/// No additional information, e.g. `DECIMAL`
/// No additional information, e.g. `DECIMAL`.
None,
/// Only precision information, e.g. `DECIMAL(10)`
/// Only precision information, e.g. `DECIMAL(10)`.
Precision(u64),
/// Precision and scale information, e.g. `DECIMAL(10,2)`
/// Precision and scale information, e.g. `DECIMAL(10,2)`.
PrecisionAndScale(u64, i64),
}

Expand All @@ -1031,13 +1046,14 @@ impl fmt::Display for ExactNumberInfo {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum CharacterLength {
/// Integer length with optional unit (e.g. `CHAR(10)` or `VARCHAR(10 CHARACTERS)`).
IntegerLength {
/// Default (if VARYING) or maximum (if not VARYING) length
length: u64,
/// Optional unit. If not informed, the ANSI handles it as CHARACTERS implicitly
unit: Option<CharLengthUnits>,
},
/// VARCHAR(MAX) or NVARCHAR(MAX), used in T-SQL (Microsoft SQL Server)
/// VARCHAR(MAX) or NVARCHAR(MAX), used in T-SQL (Microsoft SQL Server).
Max,
}

Expand Down Expand Up @@ -1087,12 +1103,16 @@ impl fmt::Display for CharLengthUnits {
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
/// Information about [binary length][1], including length and possibly unit.
///
/// [1]: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#binary-length
pub enum BinaryLength {
/// Integer length for binary types (e.g. `VARBINARY(100)`).
IntegerLength {
/// Default (if VARYING)
length: u64,
},
/// VARBINARY(MAX) used in T-SQL (Microsoft SQL Server)
/// VARBINARY(MAX) used in T-SQL (Microsoft SQL Server).
Max,
}

Expand All @@ -1118,13 +1138,13 @@ impl fmt::Display for BinaryLength {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum ArrayElemTypeDef {
/// `ARRAY`
/// Use `ARRAY` style without an explicit element type.
None,
/// `ARRAY<INT>`
/// Angle-bracket style, e.g. `ARRAY<INT>`.
AngleBracket(Box<DataType>),
/// `INT[]` or `INT[2]`
/// Square-bracket style, e.g. `INT[]` or `INT[2]`.
SquareBracket(Box<DataType>, Option<u64>),
/// `Array(Int64)`
/// Parenthesis style, e.g. `Array(Int64)`.
Parenthesis(Box<DataType>),
}

Expand All @@ -1136,12 +1156,19 @@ pub enum ArrayElemTypeDef {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum GeometricTypeKind {
/// Point geometry
Point,
/// Line geometry
Line,
/// Line segment geometry
LineSegment,
/// Box geometry
GeometricBox,
/// Path geometry
GeometricPath,
/// Polygon geometry
Polygon,
/// Circle geometry
Circle,
}

Expand Down
80 changes: 72 additions & 8 deletions src/ast/dcl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,25 @@ use crate::tokenizer::Span;
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum RoleOption {
/// Enable or disable BYPASSRLS.
BypassRLS(bool),
/// Connection limit expression.
ConnectionLimit(Expr),
/// CREATEDB flag.
CreateDB(bool),
/// CREATEROLE flag.
CreateRole(bool),
/// INHERIT flag.
Inherit(bool),
/// LOGIN flag.
Login(bool),
/// Password value or NULL password.
Password(Password),
/// Replication privilege flag.
Replication(bool),
/// SUPERUSER flag.
SuperUser(bool),
/// `VALID UNTIL` expression.
ValidUntil(Expr),
}

Expand Down Expand Up @@ -104,8 +114,11 @@ impl fmt::Display for RoleOption {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum SetConfigValue {
/// Use the default value.
Default,
/// Use the current value (`FROM CURRENT`).
FromCurrent,
/// Set to the provided expression value.
Value(Expr),
}

Expand All @@ -116,7 +129,9 @@ pub enum SetConfigValue {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum ResetConfig {
/// Reset all configuration parameters.
ALL,
/// Reset the named configuration parameter.
ConfigName(ObjectName),
}

Expand All @@ -127,28 +142,48 @@ pub enum ResetConfig {
pub enum AlterRoleOperation {
/// Generic
RenameRole {
/// Role name to rename.
role_name: Ident,
},
/// MS SQL Server
/// <https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-role-transact-sql>
AddMember {
/// Member name to add to the role.
member_name: Ident,
},
/// MS SQL Server
///
/// <https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-role-transact-sql>
DropMember {
/// Member name to remove from the role.
member_name: Ident,
},
/// PostgreSQL
/// <https://www.postgresql.org/docs/current/sql-alterrole.html>
WithOptions {
/// Role options to apply.
options: Vec<RoleOption>,
},
/// PostgreSQL
/// <https://www.postgresql.org/docs/current/sql-alterrole.html>
///
/// `SET configuration_parameter { TO | = } { value | DEFAULT }`
Set {
/// Configuration name to set.
config_name: ObjectName,
/// Value to assign to the configuration.
config_value: SetConfigValue,
/// Optional database scope for the setting.
in_database: Option<ObjectName>,
},
/// PostgreSQL
/// <https://www.postgresql.org/docs/current/sql-alterrole.html>
///
/// `RESET configuration_parameter` | `RESET ALL`
Reset {
/// Configuration to reset.
config_name: ResetConfig,
/// Optional database scope for the reset.
in_database: Option<ObjectName>,
},
}
Expand Down Expand Up @@ -205,14 +240,22 @@ impl fmt::Display for AlterRoleOperation {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum Use {
Catalog(ObjectName), // e.g. `USE CATALOG foo.bar`
Schema(ObjectName), // e.g. `USE SCHEMA foo.bar`
Database(ObjectName), // e.g. `USE DATABASE foo.bar`
Warehouse(ObjectName), // e.g. `USE WAREHOUSE foo.bar`
Role(ObjectName), // e.g. `USE ROLE PUBLIC`
SecondaryRoles(SecondaryRoles), // e.g. `USE SECONDARY ROLES ALL`
Object(ObjectName), // e.g. `USE foo.bar`
Default, // e.g. `USE DEFAULT`
/// Switch to the given catalog (e.g. `USE CATALOG ...`).
Catalog(ObjectName),
/// Switch to the given schema (e.g. `USE SCHEMA ...`).
Schema(ObjectName),
/// Switch to the given database (e.g. `USE DATABASE ...`).
Database(ObjectName),
/// Switch to the given warehouse (e.g. `USE WAREHOUSE ...`).
Warehouse(ObjectName),
/// Switch to the given role (e.g. `USE ROLE ...`).
Role(ObjectName),
/// Use secondary roles specification (e.g. `USE SECONDARY ROLES ...`).
SecondaryRoles(SecondaryRoles),
/// Use the specified object (e.g. `USE foo.bar`).
Object(ObjectName),
/// Reset to default (e.g. `USE DEFAULT`).
Default,
}

impl fmt::Display for Use {
Expand All @@ -239,8 +282,11 @@ impl fmt::Display for Use {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum SecondaryRoles {
/// Use all secondary roles.
All,
/// Use no secondary roles.
None,
/// Explicit list of secondary roles.
List(Vec<Ident>),
}

Expand All @@ -260,25 +306,43 @@ impl fmt::Display for SecondaryRoles {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct CreateRole {
/// Role names to create.
pub names: Vec<ObjectName>,
/// Whether `IF NOT EXISTS` was specified.
pub if_not_exists: bool,
// Postgres
/// Whether `LOGIN` was specified.
pub login: Option<bool>,
/// Whether `INHERIT` was specified.
pub inherit: Option<bool>,
/// Whether `BYPASSRLS` was specified.
pub bypassrls: Option<bool>,
/// Optional password for the role.
pub password: Option<Password>,
/// Whether `SUPERUSER` was specified.
pub superuser: Option<bool>,
/// Whether `CREATEDB` was specified.
pub create_db: Option<bool>,
/// Whether `CREATEROLE` was specified.
pub create_role: Option<bool>,
/// Whether `REPLICATION` privilege was specified.
pub replication: Option<bool>,
/// Optional connection limit expression.
pub connection_limit: Option<Expr>,
/// Optional account validity expression.
pub valid_until: Option<Expr>,
/// Members of `IN ROLE` clause.
pub in_role: Vec<Ident>,
/// Members of `IN GROUP` clause.
pub in_group: Vec<Ident>,
/// Roles listed in `ROLE` clause.
pub role: Vec<Ident>,
/// Users listed in `USER` clause.
pub user: Vec<Ident>,
/// Admin users listed in `ADMIN` clause.
pub admin: Vec<Ident>,
// MSSQL
/// Optional authorization owner.
pub authorization_owner: Option<ObjectName>,
}

Expand Down
Loading