From 505d7bd00f4547c69055718c398deeb88ad0fb38 Mon Sep 17 00:00:00 2001 From: lovasoa Date: Sun, 4 Sep 2022 19:52:26 +0200 Subject: [PATCH 01/13] Add an AST visitor This adds an optional "derive-visitor" feature which lets the user visit and mutate the AST easily --- Cargo.toml | 3 +- src/ast/data_type.rs | 46 +++--- src/ast/ddl.rs | 29 ++-- src/ast/mod.rs | 314 +++++++++++++++++++++---------------- src/ast/operator.rs | 7 +- src/ast/query.rs | 55 +++++-- src/ast/value.rs | 28 ++-- src/keywords.rs | 5 + src/tokenizer.rs | 79 +++++----- tests/sqlparser_visitor.rs | 20 +++ 10 files changed, 358 insertions(+), 228 deletions(-) create mode 100644 tests/sqlparser_visitor.rs diff --git a/Cargo.toml b/Cargo.toml index 02ac9a53f..debfdf028 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ version = "0.22.0" authors = ["Andy Grove "] homepage = "https://github.com/sqlparser-rs/sqlparser-rs" documentation = "https://docs.rs/sqlparser/" -keywords = [ "ansi", "sql", "lexer", "parser" ] +keywords = ["ansi", "sql", "lexer", "parser"] repository = "https://github.com/sqlparser-rs/sqlparser-rs" license = "Apache-2.0" include = [ @@ -32,6 +32,7 @@ serde = { version = "1.0", features = ["derive"], optional = true } # of dev-dependencies because of # https://github.com/rust-lang/cargo/issues/1596 serde_json = { version = "1.0", optional = true } +derive-visitor = { version = "0.3.0", git = "https://github.com/lovasoa/derive-visitor.git", branch = "issue8-implement-mutable-visit", optional = true } [dev-dependencies] simple_logger = "2.1" diff --git a/src/ast/data_type.rs b/src/ast/data_type.rs index 3a6ebf4cd..a6d7e6909 100644 --- a/src/ast/data_type.rs +++ b/src/ast/data_type.rs @@ -17,6 +17,9 @@ use core::fmt; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; +#[cfg(feature = "derive-visitor")] +use derive_visitor::{Drive, DriveMut}; + use crate::ast::ObjectName; use super::value::escape_single_quote_string; @@ -24,47 +27,48 @@ use super::value::escape_single_quote_string; /// SQL data types #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum DataType { /// Fixed-length character type e.g. CHAR(10) - Char(Option), + Char(#[cfg_attr(feature = "derive-visitor", drive(skip))] Option), /// Variable-length character type e.g. VARCHAR(10) - Varchar(Option), + Varchar(#[cfg_attr(feature = "derive-visitor", drive(skip))] Option), /// Variable-length character type e.g. NVARCHAR(10) - Nvarchar(Option), + Nvarchar(#[cfg_attr(feature = "derive-visitor", drive(skip))] Option), /// Uuid type Uuid, /// Large character object e.g. CLOB(1000) - Clob(u64), + Clob(#[cfg_attr(feature = "derive-visitor", drive(skip))] u64), /// Fixed-length binary type e.g. BINARY(10) - Binary(u64), + Binary(#[cfg_attr(feature = "derive-visitor", drive(skip))] u64), /// Variable-length binary type e.g. VARBINARY(10) - Varbinary(u64), + Varbinary(#[cfg_attr(feature = "derive-visitor", drive(skip))] u64), /// Large binary object e.g. BLOB(1000) - Blob(u64), + Blob(#[cfg_attr(feature = "derive-visitor", drive(skip))] u64), /// Decimal type with optional precision and scale e.g. DECIMAL(10,2) - Decimal(Option, Option), + Decimal(#[cfg_attr(feature = "derive-visitor", drive(skip))] Option, #[cfg_attr(feature = "derive-visitor", drive(skip))] Option), /// Floating point with optional precision e.g. FLOAT(8) - Float(Option), + Float(#[cfg_attr(feature = "derive-visitor", drive(skip))] Option), /// Tiny integer with optional display width e.g. TINYINT or TINYINT(3) - TinyInt(Option), + TinyInt(#[cfg_attr(feature = "derive-visitor", drive(skip))] Option), /// Unsigned tiny integer with optional display width e.g. TINYINT UNSIGNED or TINYINT(3) UNSIGNED - UnsignedTinyInt(Option), + UnsignedTinyInt(#[cfg_attr(feature = "derive-visitor", drive(skip))] Option), /// Small integer with optional display width e.g. SMALLINT or SMALLINT(5) - SmallInt(Option), + SmallInt(#[cfg_attr(feature = "derive-visitor", drive(skip))] Option), /// Unsigned small integer with optional display width e.g. SMALLINT UNSIGNED or SMALLINT(5) UNSIGNED - UnsignedSmallInt(Option), + UnsignedSmallInt(#[cfg_attr(feature = "derive-visitor", drive(skip))] Option), /// Integer with optional display width e.g. INT or INT(11) - Int(Option), + Int(#[cfg_attr(feature = "derive-visitor", drive(skip))] Option), /// Integer with optional display width e.g. INTEGER or INTEGER(11) - Integer(Option), + Integer(#[cfg_attr(feature = "derive-visitor", drive(skip))] Option), /// Unsigned integer with optional display width e.g. INT UNSIGNED or INT(11) UNSIGNED - UnsignedInt(Option), + UnsignedInt(#[cfg_attr(feature = "derive-visitor", drive(skip))] Option), /// Unsigned integer with optional display width e.g. INTGER UNSIGNED or INTEGER(11) UNSIGNED - UnsignedInteger(Option), + UnsignedInteger(#[cfg_attr(feature = "derive-visitor", drive(skip))] Option), /// Big integer with optional display width e.g. BIGINT or BIGINT(20) - BigInt(Option), + BigInt(#[cfg_attr(feature = "derive-visitor", drive(skip))] Option), /// Unsigned big integer with optional display width e.g. BIGINT UNSIGNED or BIGINT(20) UNSIGNED - UnsignedBigInt(Option), + UnsignedBigInt(#[cfg_attr(feature = "derive-visitor", drive(skip))] Option), /// Floating point e.g. REAL Real, /// Double e.g. DOUBLE PRECISION @@ -96,9 +100,9 @@ pub enum DataType { /// Arrays Array(Box), /// Enums - Enum(Vec), + Enum(#[cfg_attr(feature = "derive-visitor", drive(skip))] Vec), /// Set - Set(Vec), + Set(#[cfg_attr(feature = "derive-visitor", drive(skip))] Vec), } impl fmt::Display for DataType { diff --git a/src/ast/ddl.rs b/src/ast/ddl.rs index 1847f2518..62ae582b5 100644 --- a/src/ast/ddl.rs +++ b/src/ast/ddl.rs @@ -20,6 +20,9 @@ use core::fmt; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; +#[cfg(feature = "derive-visitor")] +use derive_visitor::{Drive, DriveMut}; + use crate::ast::value::escape_single_quote_string; use crate::ast::{display_comma_separated, display_separated, DataType, Expr, Ident, ObjectName}; use crate::tokenizer::Token; @@ -27,6 +30,7 @@ use crate::tokenizer::Token; /// An `ALTER TABLE` (`Statement::AlterTable`) operation #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum AlterTableOperation { /// `ADD ` AddConstraint(TableConstraint), @@ -34,15 +38,15 @@ pub enum AlterTableOperation { AddColumn { column_def: ColumnDef }, /// `DROP CONSTRAINT [ IF EXISTS ] ` DropConstraint { - if_exists: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] if_exists: bool, name: Ident, - cascade: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] cascade: bool, }, /// `DROP [ COLUMN ] [ IF EXISTS ] [ CASCADE ]` DropColumn { column_name: Ident, - if_exists: bool, - cascade: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] if_exists: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] cascade: bool, }, /// `RENAME TO PARTITION (partition=val)` RenamePartitions { @@ -51,12 +55,12 @@ pub enum AlterTableOperation { }, /// Add Partitions AddPartitions { - if_not_exists: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] if_not_exists: bool, new_partitions: Vec, }, DropPartitions { partitions: Vec, - if_exists: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] if_exists: bool, }, /// `RENAME [ COLUMN ] TO ` RenameColumn { @@ -178,6 +182,7 @@ impl fmt::Display for AlterTableOperation { /// An `ALTER COLUMN` (`Statement::AlterTable`) operation #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum AlterColumnOperation { /// `SET NOT NULL` SetNotNull, @@ -221,13 +226,14 @@ impl fmt::Display for AlterColumnOperation { /// `ALTER TABLE ADD ` statement. #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum TableConstraint { /// `[ CONSTRAINT ] { PRIMARY KEY | UNIQUE } ()` Unique { name: Option, columns: Vec, /// Whether this is a `PRIMARY KEY` or just a `UNIQUE` constraint - is_primary: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] is_primary: bool, }, /// A referential integrity constraint (`[ CONSTRAINT ] FOREIGN KEY () /// REFERENCES () @@ -297,6 +303,7 @@ impl fmt::Display for TableConstraint { /// SQL column definition #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub struct ColumnDef { pub name: Ident, pub data_type: DataType, @@ -332,6 +339,7 @@ impl fmt::Display for ColumnDef { /// "column options," and we allow any column option to be named. #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub struct ColumnOptionDef { pub name: Option, pub option: ColumnOption, @@ -347,6 +355,7 @@ impl fmt::Display for ColumnOptionDef { /// TABLE` statement. #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum ColumnOption { /// `NULL` Null, @@ -356,7 +365,7 @@ pub enum ColumnOption { Default(Expr), /// `{ PRIMARY KEY | UNIQUE }` Unique { - is_primary: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] is_primary: bool, }, /// A referential integrity constraint (`[FOREIGN KEY REFERENCES /// () @@ -376,7 +385,7 @@ pub enum ColumnOption { /// - ... DialectSpecific(Vec), CharacterSet(ObjectName), - Comment(String), + Comment(#[cfg_attr(feature = "derive-visitor", drive(skip))] String), } impl fmt::Display for ColumnOption { @@ -433,7 +442,7 @@ fn display_constraint_name(name: &'_ Option) -> impl fmt::Display + '_ { /// /// Used in foreign key constraints in `ON UPDATE` and `ON DELETE` options. #[derive(Debug, Clone, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum ReferentialAction { Restrict, Cascade, diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 4f5fdb2eb..9768aecae 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -28,6 +28,9 @@ use core::fmt; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; +#[cfg(feature = "derive-visitor")] +use derive_visitor::{Drive, DriveMut}; + pub use self::data_type::DataType; pub use self::ddl::{ AlterColumnOperation, AlterTableOperation, ColumnDef, ColumnOption, ColumnOptionDef, @@ -42,16 +45,16 @@ pub use self::query::{ pub use self::value::{DateTimeField, TrimWhereField, Value}; struct DisplaySeparated<'a, T> -where - T: fmt::Display, + where + T: fmt::Display, { slice: &'a [T], sep: &'static str, } impl<'a, T> fmt::Display for DisplaySeparated<'a, T> -where - T: fmt::Display, + where + T: fmt::Display, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let mut delim = ""; @@ -65,35 +68,35 @@ where } fn display_separated<'a, T>(slice: &'a [T], sep: &'static str) -> DisplaySeparated<'a, T> -where - T: fmt::Display, + where + T: fmt::Display, { DisplaySeparated { slice, sep } } fn display_comma_separated(slice: &[T]) -> DisplaySeparated<'_, T> -where - T: fmt::Display, + where + T: fmt::Display, { DisplaySeparated { slice, sep: ", " } } /// An identifier, decomposed into its value or character data and the quote style. #[derive(Debug, Clone, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub struct Ident { /// The value of the identifier without quotes. - pub value: String, + #[cfg_attr(feature = "derive-visitor", drive(skip))] pub value: String, /// The starting quote if any. Valid quote characters are the single quote, /// double quote, backtick, and opening square bracket. - pub quote_style: Option, + #[cfg_attr(feature = "derive-visitor", drive(skip))] pub quote_style: Option, } impl Ident { /// Create a new identifier with the given value and no quotes. pub fn new(value: S) -> Self - where - S: Into, + where + S: Into, { Ident { value: value.into(), @@ -104,8 +107,8 @@ impl Ident { /// Create a new quoted identifier with the given quote and value. This function /// panics if the given quote is not a valid quote character. pub fn with_quote(quote: char, value: S) -> Self - where - S: Into, + where + S: Into, { assert!(quote == '\'' || quote == '"' || quote == '`' || quote == '['); Ident { @@ -141,6 +144,7 @@ impl fmt::Display for Ident { /// A name of a table, view, custom type, etc., possibly multi-part, i.e. db.schema.obj #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub struct ObjectName(pub Vec); impl fmt::Display for ObjectName { @@ -151,6 +155,7 @@ impl fmt::Display for ObjectName { #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] /// Represents an Array Expression, either /// `ARRAY[..]`, or `[..]` pub struct Array { @@ -158,7 +163,7 @@ pub struct Array { pub elem: Vec, /// `true` for `ARRAY[..]`, `false` for `[..]` - pub named: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] pub named: bool, } impl fmt::Display for Array { @@ -175,6 +180,7 @@ impl fmt::Display for Array { /// JsonOperator #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum JsonOperator { /// -> keeps the value as json Arrow, @@ -212,6 +218,7 @@ impl fmt::Display for JsonOperator { /// inappropriate type, like `WHERE 1` or `SELECT 1=1`, as necessary. #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum Expr { /// Identifier e.g. table name or column name Identifier(Ident), @@ -249,24 +256,24 @@ pub enum Expr { InList { expr: Box, list: Vec, - negated: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] negated: bool, }, /// `[ NOT ] IN (SELECT ...)` InSubquery { expr: Box, subquery: Box, - negated: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] negated: bool, }, /// `[ NOT ] IN UNNEST(array_expression)` InUnnest { expr: Box, array_expr: Box, - negated: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] negated: bool, }, /// ` [ NOT ] BETWEEN AND ` Between { expr: Box, - negated: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] negated: bool, low: Box, high: Box, }, @@ -278,24 +285,24 @@ pub enum Expr { }, /// LIKE Like { - negated: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] negated: bool, expr: Box, pattern: Box, - escape_char: Option, + #[cfg_attr(feature = "derive-visitor", drive(skip))] escape_char: Option, }, /// ILIKE (case-insensitive LIKE) ILike { - negated: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] negated: bool, expr: Box, pattern: Box, - escape_char: Option, + #[cfg_attr(feature = "derive-visitor", drive(skip))] escape_char: Option, }, /// SIMILAR TO regex SimilarTo { - negated: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] negated: bool, expr: Box, pattern: Box, - escape_char: Option, + #[cfg_attr(feature = "derive-visitor", drive(skip))] escape_char: Option, }, /// Any operation e.g. `1 ANY (1)` or `foo > ANY(bar)`, It will be wrapped in the right side of BinaryExpr AnyOp(Box), @@ -324,7 +331,7 @@ pub enum Expr { /// AT a timestamp to a different timezone e.g. `FROM_UNIXTIME(0) AT TIME ZONE 'UTC-06:00'` AtTimeZone { timestamp: Box, - time_zone: String, + #[cfg_attr(feature = "derive-visitor", drive(skip))] time_zone: String, }, /// EXTRACT(DateTimeField FROM ) Extract { @@ -367,7 +374,7 @@ pub enum Expr { /// A constant of form ` 'value'`. /// This can represent ANSI SQL `DATE`, `TIME`, and `TIMESTAMP` literals (such as `DATE '2020-01-01'`), /// as well as constants of other types (a non-standard PostgreSQL extension). - TypedString { data_type: DataType, value: String }, + TypedString { data_type: DataType, #[cfg_attr(feature = "derive-visitor", drive(skip))] value: String }, /// Access a map-like object by field (e.g. `column['field']` or `column[4]` /// Note that depending on the dialect, struct like accesses may be /// parsed as [`ArrayIndex`] or [`MapAccess`] @@ -388,7 +395,7 @@ pub enum Expr { }, /// An exists expression `[ NOT ] EXISTS(SELECT ...)`, used in expressions like /// `WHERE [ NOT ] EXISTS (SELECT ...)`. - Exists { subquery: Box, negated: bool }, + Exists { subquery: Box, #[cfg_attr(feature = "derive-visitor", drive(skip))] negated: bool }, /// A parenthesized subquery `(SELECT ...)`, used in expression like /// `SELECT (subquery) AS x` or `WHERE (subquery) = x` Subquery(Box), @@ -724,6 +731,7 @@ impl fmt::Display for Expr { /// A window specification (i.e. `OVER (PARTITION BY .. ORDER BY .. etc.)`) #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub struct WindowSpec { pub partition_by: Vec, pub order_by: Vec, @@ -769,6 +777,7 @@ impl fmt::Display for WindowSpec { /// reject invalid bounds like `ROWS UNBOUNDED FOLLOWING` before execution. #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub struct WindowFrame { pub units: WindowFrameUnits, pub start_bound: WindowFrameBound, @@ -794,6 +803,7 @@ impl Default for WindowFrame { #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum WindowFrameUnits { Rows, Range, @@ -813,13 +823,14 @@ impl fmt::Display for WindowFrameUnits { /// Specifies [WindowFrame]'s `start_bound` and `end_bound` #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum WindowFrameBound { /// `CURRENT ROW` CurrentRow, /// ` PRECEDING` or `UNBOUNDED PRECEDING` - Preceding(Option), + Preceding(#[cfg_attr(feature = "derive-visitor", drive(skip))] Option), /// ` FOLLOWING` or `UNBOUNDED FOLLOWING`. - Following(Option), + Following(#[cfg_attr(feature = "derive-visitor", drive(skip))] Option), } impl fmt::Display for WindowFrameBound { @@ -836,6 +847,7 @@ impl fmt::Display for WindowFrameBound { #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum AddDropSync { ADD, DROP, @@ -854,6 +866,7 @@ impl fmt::Display for AddDropSync { #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum ShowCreateObject { Event, Function, @@ -878,6 +891,7 @@ impl fmt::Display for ShowCreateObject { #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum CommentObject { Column, Table, @@ -896,16 +910,17 @@ impl fmt::Display for CommentObject { #[allow(clippy::large_enum_variant)] #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum Statement { /// Analyze (Hive) Analyze { table_name: ObjectName, partitions: Option>, - for_columns: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] for_columns: bool, columns: Vec, - cache_metadata: bool, - noscan: bool, - compute_statistics: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] cache_metadata: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] noscan: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] compute_statistics: bool, }, /// Truncate (Hive) Truncate { @@ -915,7 +930,7 @@ pub enum Statement { /// Msck (Hive) Msck { table_name: ObjectName, - repair: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] repair: bool, partition_action: Option, }, /// SELECT @@ -925,13 +940,13 @@ pub enum Statement { /// Only for Sqlite or: Option, /// INTO - optional keyword - into: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] into: bool, /// TABLE table_name: ObjectName, /// COLUMNS columns: Vec, /// Overwrite (Hive) - overwrite: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] overwrite: bool, /// A SQL query that specifies what to insert source: Box, /// partitioned insert (Hive) @@ -939,14 +954,14 @@ pub enum Statement { /// Columns defined after PARTITION after_columns: Vec, /// whether the insert has the table keyword (Hive) - table: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] table: bool, on: Option, }, // TODO: Support ROW FORMAT Directory { - overwrite: bool, - local: bool, - path: String, + #[cfg_attr(feature = "derive-visitor", drive(skip))] overwrite: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] local: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] path: String, file_format: Option, source: Box, }, @@ -956,7 +971,7 @@ pub enum Statement { /// COLUMNS columns: Vec, /// If true, is a 'COPY TO' statement. If false is a 'COPY FROM' - to: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] to: bool, /// The source of 'COPY FROM', or the target of 'COPY TO' target: CopyTarget, /// WITH options (from PostgreSQL version 9.0) @@ -964,7 +979,7 @@ pub enum Statement { /// WITH options (before PostgreSQL version 9.0) legacy_options: Vec, /// VALUES a vector of values to be copied - values: Vec>, + #[cfg_attr(feature = "derive-visitor", drive(skip))] values: Vec>, }, /// Close - closes the portal underlying an open cursor. Close { @@ -993,8 +1008,8 @@ pub enum Statement { }, /// CREATE VIEW CreateView { - or_replace: bool, - materialized: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] or_replace: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] materialized: bool, /// View name name: ObjectName, columns: Vec, @@ -1003,11 +1018,11 @@ pub enum Statement { }, /// CREATE TABLE CreateTable { - or_replace: bool, - temporary: bool, - external: bool, - global: Option, - if_not_exists: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] or_replace: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] temporary: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] external: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] global: Option, + #[cfg_attr(feature = "derive-visitor", drive(skip))] if_not_exists: bool, /// Table name name: ObjectName, /// Optional schema @@ -1018,23 +1033,23 @@ pub enum Statement { table_properties: Vec, with_options: Vec, file_format: Option, - location: Option, + #[cfg_attr(feature = "derive-visitor", drive(skip))] location: Option, query: Option>, - without_rowid: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] without_rowid: bool, like: Option, clone: Option, - engine: Option, - default_charset: Option, - collation: Option, - on_commit: Option, + #[cfg_attr(feature = "derive-visitor", drive(skip))] engine: Option, + #[cfg_attr(feature = "derive-visitor", drive(skip))] default_charset: Option, + #[cfg_attr(feature = "derive-visitor", drive(skip))] collation: Option, + #[cfg_attr(feature = "derive-visitor", drive(skip))] on_commit: Option, /// Click house "ON CLUSTER" clause: /// - on_cluster: Option, + #[cfg_attr(feature = "derive-visitor", drive(skip))] on_cluster: Option, }, /// SQLite's `CREATE VIRTUAL TABLE .. USING ()` CreateVirtualTable { name: ObjectName, - if_not_exists: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] if_not_exists: bool, module_name: Ident, module_args: Vec, }, @@ -1044,8 +1059,8 @@ pub enum Statement { name: ObjectName, table_name: ObjectName, columns: Vec, - unique: bool, - if_not_exists: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] unique: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] if_not_exists: bool, }, /// ALTER TABLE AlterTable { @@ -1058,15 +1073,15 @@ pub enum Statement { /// The type of the object to drop: TABLE, VIEW, etc. object_type: ObjectType, /// An optional `IF EXISTS` clause. (Non-standard.) - if_exists: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] if_exists: bool, /// One or more objects to drop. (ANSI SQL requires exactly one.) names: Vec, /// Whether `CASCADE` was specified. This will be `false` when /// `RESTRICT` or no drop behavior at all was specified. - cascade: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] cascade: bool, /// Hive allows you specify whether the table's stored data will be /// deleted along with the dropped table - purge: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] purge: bool, }, /// DECLARE - Declaring Cursor Variables /// @@ -1076,19 +1091,19 @@ pub enum Statement { /// Cursor name name: Ident, /// Causes the cursor to return data in binary rather than in text format. - binary: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] binary: bool, /// None = Not specified /// Some(true) = INSENSITIVE /// Some(false) = ASENSITIVE - sensitive: Option, + #[cfg_attr(feature = "derive-visitor", drive(skip))] sensitive: Option, /// None = Not specified /// Some(true) = SCROLL /// Some(false) = NO SCROLL - scroll: Option, + #[cfg_attr(feature = "derive-visitor", drive(skip))] scroll: Option, /// None = Not specified /// Some(true) = WITH HOLD, specifies that the cursor can continue to be used after the transaction that created it successfully commits /// Some(false) = WITHOUT HOLD, specifies that the cursor cannot be used outside of the transaction that created it - hold: Option, + #[cfg_attr(feature = "derive-visitor", drive(skip))] hold: Option, query: Box, }, /// FETCH - retrieve rows from a query using a cursor @@ -1112,9 +1127,9 @@ pub enum Statement { /// Note: this is a PostgreSQL-specific statement, /// but may also compatible with other SQL. SetRole { - local: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] local: bool, // SESSION is the default if neither SESSION nor LOCAL appears. - session: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] session: bool, role_name: Option, }, /// SET @@ -1123,8 +1138,8 @@ pub enum Statement { /// least MySQL and PostgreSQL. Not all MySQL-specific syntatic forms are /// supported yet. SetVariable { - local: bool, - hivevar: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] local: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] hivevar: bool, variable: ObjectName, value: Vec, }, @@ -1132,8 +1147,8 @@ pub enum Statement { /// /// Note: this is a MySQL-specific statement. SetNames { - charset_name: String, - collation_name: Option, + #[cfg_attr(feature = "derive-visitor", drive(skip))] charset_name: String, + #[cfg_attr(feature = "derive-visitor", drive(skip))] collation_name: Option, }, /// SET NAMES DEFAULT /// @@ -1158,8 +1173,8 @@ pub enum Statement { /// /// Note: this is a MySQL-specific statement. ShowColumns { - extended: bool, - full: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] extended: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] full: bool, table_name: ObjectName, filter: Option, }, @@ -1167,8 +1182,8 @@ pub enum Statement { /// /// Note: this is a MySQL-specific statement. ShowTables { - extended: bool, - full: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] extended: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] full: bool, db_name: Option, filter: Option, }, @@ -1186,7 +1201,7 @@ pub enum Statement { SetTransaction { modes: Vec, snapshot: Option, - session: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] session: bool, }, /// `COMMENT ON ...` /// @@ -1194,31 +1209,31 @@ pub enum Statement { Comment { object_type: CommentObject, object_name: ObjectName, - comment: Option, + #[cfg_attr(feature = "derive-visitor", drive(skip))] comment: Option, }, /// `COMMIT [ TRANSACTION | WORK ] [ AND [ NO ] CHAIN ]` - Commit { chain: bool }, + Commit { #[cfg_attr(feature = "derive-visitor", drive(skip))] chain: bool }, /// `ROLLBACK [ TRANSACTION | WORK ] [ AND [ NO ] CHAIN ]` - Rollback { chain: bool }, + Rollback { #[cfg_attr(feature = "derive-visitor", drive(skip))] chain: bool }, /// CREATE SCHEMA CreateSchema { schema_name: ObjectName, - if_not_exists: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] if_not_exists: bool, }, /// CREATE DATABASE CreateDatabase { db_name: ObjectName, - if_not_exists: bool, - location: Option, - managed_location: Option, + #[cfg_attr(feature = "derive-visitor", drive(skip))] if_not_exists: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] location: Option, + #[cfg_attr(feature = "derive-visitor", drive(skip))] managed_location: Option, }, /// CREATE FUNCTION /// /// Hive: https://cwiki.apache.org/confluence/display/hive/languagemanual+ddl#LanguageManualDDL-Create/Drop/ReloadFunction CreateFunction { - temporary: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] temporary: bool, name: ObjectName, - class_name: String, + #[cfg_attr(feature = "derive-visitor", drive(skip))] class_name: String, using: Option, }, /// `ASSERT [AS ]` @@ -1231,7 +1246,7 @@ pub enum Statement { privileges: Privileges, objects: GrantObjects, grantees: Vec, - with_grant_option: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] with_grant_option: bool, granted_by: Option, }, /// REVOKE privileges ON objects FROM grantees @@ -1240,12 +1255,12 @@ pub enum Statement { objects: GrantObjects, grantees: Vec, granted_by: Option, - cascade: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] cascade: bool, }, /// `DEALLOCATE [ PREPARE ] { name | ALL }` /// /// Note: this is a PostgreSQL-specific statement. - Deallocate { name: Ident, prepare: bool }, + Deallocate { name: Ident, #[cfg_attr(feature = "derive-visitor", drive(skip))] prepare: bool }, /// `EXECUTE name [ ( parameter [, ...] ) ]` /// /// Note: this is a PostgreSQL-specific statement. @@ -1265,24 +1280,24 @@ pub enum Statement { Kill { modifier: Option, // processlist_id - id: u64, + #[cfg_attr(feature = "derive-visitor", drive(skip))] id: u64, }, /// EXPLAIN TABLE /// Note: this is a MySQL-specific statement. See ExplainTable { // If true, query used the MySQL `DESCRIBE` alias for explain - describe_alias: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] describe_alias: bool, // Table name table_name: ObjectName, }, /// EXPLAIN / DESCRIBE for select_statement Explain { // If true, query used the MySQL `DESCRIBE` alias for explain - describe_alias: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] describe_alias: bool, /// Carry out the command and show actual run times and other statistics. - analyze: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] analyze: bool, // Display additional information regarding the plan. - verbose: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] verbose: bool, /// A SQL query that specifies what to explain statement: Box, }, @@ -1291,7 +1306,7 @@ pub enum Statement { // MERGE INTO statement, based on Snowflake. See Merge { // optional INTO keyword - into: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] into: bool, // Specifies the table to merge table: TableFactor, // Specifies the table or subquery to join with the target table @@ -1782,10 +1797,10 @@ impl fmt::Display for Statement { } if let Some(HiveFormat { - row_format, - storage, - location, - }) = hive_formats + row_format, + storage, + location, + }) = hive_formats { match row_format { Some(HiveRowFormat::SERDE { class }) => { @@ -1796,9 +1811,9 @@ impl fmt::Display for Statement { } match storage { Some(HiveIOFormat::IOF { - input_format, - output_format, - }) => write!( + input_format, + output_format, + }) => write!( f, " STORED AS INPUTFORMAT {} OUTPUTFORMAT {}", input_format, output_format @@ -2065,10 +2080,10 @@ impl fmt::Display for Statement { Ok(()) } Statement::Commit { chain } => { - write!(f, "COMMIT{}", if *chain { " AND CHAIN" } else { "" },) + write!(f, "COMMIT{}", if *chain { " AND CHAIN" } else { "" }, ) } Statement::Rollback { chain } => { - write!(f, "ROLLBACK{}", if *chain { " AND CHAIN" } else { "" },) + write!(f, "ROLLBACK{}", if *chain { " AND CHAIN" } else { "" }, ) } Statement::CreateSchema { schema_name, @@ -2181,6 +2196,7 @@ impl fmt::Display for Statement { #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] #[non_exhaustive] pub enum OnInsert { /// ON DUPLICATE KEY UPDATE (MySQL when the key already exists, then execute an update instead) @@ -2202,11 +2218,12 @@ impl fmt::Display for OnInsert { /// Privileges granted in a GRANT statement or revoked in a REVOKE statement. #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum Privileges { /// All privileges applicable to the object type All { /// Optional keyword from the spec, ignored in practice - with_privileges_keyword: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] with_privileges_keyword: bool, }, /// Specific privileges (e.g. `SELECT`, `INSERT`) Actions(Vec), @@ -2238,6 +2255,7 @@ impl fmt::Display for Privileges { /// Specific direction for FETCH statement #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum FetchDirection { Count { limit: Value }, Next, @@ -2301,6 +2319,7 @@ impl fmt::Display for FetchDirection { /// A privilege on a database object (table, sequence, etc.). #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum Action { Connect, Create, @@ -2350,6 +2369,7 @@ impl fmt::Display for Action { /// Objects on which privileges are granted in a GRANT statement. #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum GrantObjects { /// Grant privileges on `ALL SEQUENCES IN SCHEMA [, ...]` AllSequencesInSchema { schemas: Vec }, @@ -2396,6 +2416,7 @@ impl fmt::Display for GrantObjects { /// SQL assignment `foo = expr` as used in SQLUpdate #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub struct Assignment { pub id: Vec, pub value: Expr, @@ -2409,6 +2430,7 @@ impl fmt::Display for Assignment { #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum FunctionArgExpr { Expr(Expr), /// Qualified wildcard, e.g. `alias.*` or `schema.table.*`. @@ -2429,6 +2451,7 @@ impl fmt::Display for FunctionArgExpr { #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum FunctionArg { Named { name: Ident, arg: FunctionArgExpr }, Unnamed(FunctionArgExpr), @@ -2445,6 +2468,7 @@ impl fmt::Display for FunctionArg { #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum CloseCursor { All, Specific { name: Ident }, @@ -2462,15 +2486,16 @@ impl fmt::Display for CloseCursor { /// A function call #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub struct Function { pub name: ObjectName, pub args: Vec, pub over: Option, // aggregate functions may specify eg `COUNT(DISTINCT x)` - pub distinct: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] pub distinct: bool, // Some functions must be called without trailing parentheses, for example Postgres // do it for current_catalog, current_schema, etc. This flags is used for formatting. - pub special: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] pub special: bool, } impl fmt::Display for Function { @@ -2498,6 +2523,7 @@ impl fmt::Display for Function { /// External table's available file format #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum FileFormat { TEXTFILE, SEQUENCEFILE, @@ -2527,8 +2553,9 @@ impl fmt::Display for FileFormat { /// [ WITHIN GROUP (ORDER BY [, ...] ) ]` #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub struct ListAgg { - pub distinct: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] pub distinct: bool, pub expr: Box, pub separator: Option>, pub on_overflow: Option, @@ -2564,6 +2591,7 @@ impl fmt::Display for ListAgg { /// The `ON OVERFLOW` clause of a LISTAGG invocation #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum ListAggOnOverflow { /// `ON OVERFLOW ERROR` Error, @@ -2571,7 +2599,7 @@ pub enum ListAggOnOverflow { /// `ON OVERFLOW TRUNCATE [ ] WITH[OUT] COUNT` Truncate { filler: Option>, - with_count: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] with_count: bool, }, } @@ -2598,6 +2626,7 @@ impl fmt::Display for ListAggOnOverflow { #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum ObjectType { Table, View, @@ -2618,6 +2647,7 @@ impl fmt::Display for ObjectType { #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum KillType { Connection, Query, @@ -2638,6 +2668,7 @@ impl fmt::Display for KillType { #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum HiveDistributionStyle { PARTITIONED { columns: Vec, @@ -2645,26 +2676,28 @@ pub enum HiveDistributionStyle { CLUSTERED { columns: Vec, sorted_by: Vec, - num_buckets: i32, + #[cfg_attr(feature = "derive-visitor", drive(skip))] num_buckets: i32, }, SKEWED { columns: Vec, on: Vec, - stored_as_directories: bool, + #[cfg_attr(feature = "derive-visitor", drive(skip))] stored_as_directories: bool, }, NONE, } #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum HiveRowFormat { - SERDE { class: String }, + SERDE { #[cfg_attr(feature = "derive-visitor", drive(skip))] class: String }, DELIMITED, } #[allow(clippy::large_enum_variant)] #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] #[allow(clippy::large_enum_variant)] pub enum HiveIOFormat { IOF { @@ -2678,14 +2711,16 @@ pub enum HiveIOFormat { #[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub struct HiveFormat { pub row_format: Option, pub storage: Option, - pub location: Option, + #[cfg_attr(feature = "derive-visitor", drive(skip))] pub location: Option, } #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub struct SqlOption { pub name: Ident, pub value: Value, @@ -2699,6 +2734,7 @@ impl fmt::Display for SqlOption { #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum TransactionMode { AccessMode(TransactionAccessMode), IsolationLevel(TransactionIsolationLevel), @@ -2716,6 +2752,7 @@ impl fmt::Display for TransactionMode { #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum TransactionAccessMode { ReadOnly, ReadWrite, @@ -2733,6 +2770,7 @@ impl fmt::Display for TransactionAccessMode { #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum TransactionIsolationLevel { ReadUncommitted, ReadCommitted, @@ -2754,9 +2792,10 @@ impl fmt::Display for TransactionIsolationLevel { #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum ShowStatementFilter { - Like(String), - ILike(String), + Like(#[cfg_attr(feature = "derive-visitor", drive(skip))] String), + ILike(#[cfg_attr(feature = "derive-visitor", drive(skip))] String), Where(Expr), } @@ -2776,6 +2815,7 @@ impl fmt::Display for ShowStatementFilter { /// https://sqlite.org/lang_conflict.html #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum SqliteOnConflict { Rollback, Abort, @@ -2799,16 +2839,17 @@ impl fmt::Display for SqliteOnConflict { #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum CopyTarget { Stdin, Stdout, File { /// The path name of the input or output file. - filename: String, + #[cfg_attr(feature = "derive-visitor", drive(skip))] filename: String, }, Program { /// A command to execute - command: String, + #[cfg_attr(feature = "derive-visitor", drive(skip))] command: String, }, } @@ -2830,6 +2871,7 @@ impl fmt::Display for CopyTarget { #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum OnCommit { DeleteRows, PreserveRows, @@ -2841,21 +2883,22 @@ pub enum OnCommit { /// #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum CopyOption { /// FORMAT format_name Format(Ident), /// FREEZE \[ boolean \] - Freeze(bool), + Freeze(#[cfg_attr(feature = "derive-visitor", drive(skip))] bool), /// DELIMITER 'delimiter_character' - Delimiter(char), + Delimiter(#[cfg_attr(feature = "derive-visitor", drive(skip))] char), /// NULL 'null_string' - Null(String), + Null(#[cfg_attr(feature = "derive-visitor", drive(skip))] String), /// HEADER \[ boolean \] - Header(bool), + Header(#[cfg_attr(feature = "derive-visitor", drive(skip))] bool), /// QUOTE 'quote_character' - Quote(char), + Quote(#[cfg_attr(feature = "derive-visitor", drive(skip))] char), /// ESCAPE 'escape_character' - Escape(char), + Escape(#[cfg_attr(feature = "derive-visitor", drive(skip))] char), /// FORCE_QUOTE { ( column_name [, ...] ) | * } ForceQuote(Vec), /// FORCE_NOT_NULL ( column_name [, ...] ) @@ -2863,7 +2906,7 @@ pub enum CopyOption { /// FORCE_NULL ( column_name [, ...] ) ForceNull(Vec), /// ENCODING 'encoding_name' - Encoding(String), + Encoding(#[cfg_attr(feature = "derive-visitor", drive(skip))] String), } impl fmt::Display for CopyOption { @@ -2894,13 +2937,14 @@ impl fmt::Display for CopyOption { /// #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum CopyLegacyOption { /// BINARY Binary, /// DELIMITER \[ AS \] 'delimiter_character' - Delimiter(char), + Delimiter(#[cfg_attr(feature = "derive-visitor", drive(skip))] char), /// NULL \[ AS \] 'null_string' - Null(String), + Null(#[cfg_attr(feature = "derive-visitor", drive(skip))] String), /// CSV ... Csv(Vec), } @@ -2922,13 +2966,14 @@ impl fmt::Display for CopyLegacyOption { /// #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum CopyLegacyCsvOption { /// HEADER Header, /// QUOTE \[ AS \] 'quote_character' - Quote(char), + Quote(#[cfg_attr(feature = "derive-visitor", drive(skip))] char), /// ESCAPE \[ AS \] 'escape_character' - Escape(char), + Escape(#[cfg_attr(feature = "derive-visitor", drive(skip))] char), /// FORCE QUOTE { column_name [, ...] | * } ForceQuote(Vec), /// FORCE NOT NULL column_name [, ...] @@ -2953,6 +2998,7 @@ impl fmt::Display for CopyLegacyCsvOption { /// #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum MergeClause { MatchedUpdate { predicate: Option, @@ -3014,6 +3060,7 @@ impl fmt::Display for MergeClause { #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum DiscardObject { ALL, PLANS, @@ -3034,10 +3081,11 @@ impl fmt::Display for DiscardObject { #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum CreateFunctionUsing { - Jar(String), - File(String), - Archive(String), + Jar(#[cfg_attr(feature = "derive-visitor", drive(skip))] String), + File(#[cfg_attr(feature = "derive-visitor", drive(skip))] String), + Archive(#[cfg_attr(feature = "derive-visitor", drive(skip))] String), } impl fmt::Display for CreateFunctionUsing { diff --git a/src/ast/operator.rs b/src/ast/operator.rs index 1c96ebbcb..5505f74b9 100644 --- a/src/ast/operator.rs +++ b/src/ast/operator.rs @@ -17,11 +17,15 @@ use alloc::{string::String, vec::Vec}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; +#[cfg(feature = "derive-visitor")] +use derive_visitor::{Drive, DriveMut}; + use super::display_separated; /// Unary operators #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum UnaryOperator { Plus, Minus, @@ -59,6 +63,7 @@ impl fmt::Display for UnaryOperator { /// Binary operators #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum BinaryOperator { Plus, Minus, @@ -90,7 +95,7 @@ pub enum BinaryOperator { /// /// See [CREATE OPERATOR](https://www.postgresql.org/docs/current/sql-createoperator.html) /// for more information. - PGCustomBinaryOperator(Vec), + PGCustomBinaryOperator(#[cfg_attr(feature = "derive-visitor", drive(skip))] Vec), } impl fmt::Display for BinaryOperator { diff --git a/src/ast/query.rs b/src/ast/query.rs index bc5af9e5f..574f7d209 100644 --- a/src/ast/query.rs +++ b/src/ast/query.rs @@ -16,12 +16,16 @@ use alloc::{boxed::Box, vec::Vec}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; +#[cfg(feature = "derive-visitor")] +use derive_visitor::{Drive, DriveMut}; + use crate::ast::*; /// The most complete variant of a `SELECT` query expression, optionally /// including `WITH`, `UNION` / other set operations, and `ORDER BY`. #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub struct Query { /// WITH (common table expressions, or CTEs) pub with: Option, @@ -69,6 +73,7 @@ impl fmt::Display for Query { #[allow(clippy::large_enum_variant)] #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "derive-visitor", derive(Drive, DriveMut))] pub enum SetExpr { /// Restricted SELECT .. FROM .. HAVING (no ORDER BY or set operations) Select(Box