mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-31 19:27:21 +00:00
Add serde support to AST structs and enums (#196)
Apply serde to AST structs and enums to be serializable/deserializable. serde support is optional, can be activated by feature named "serde".
This commit is contained in:
parent
d9a7491d9a
commit
2f1015339a
7 changed files with 63 additions and 1 deletions
|
@ -19,8 +19,9 @@ name = "sqlparser"
|
||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bigdecimal = { version = "0.1.0", optional = true }
|
bigdecimal = { version = "0.1.0", features = ["serde"], optional = true }
|
||||||
log = "0.4.5"
|
log = "0.4.5"
|
||||||
|
serde = { version = "1.0", features = ["derive"], optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
simple_logger = "1.0.1"
|
simple_logger = "1.0.1"
|
||||||
|
|
|
@ -11,10 +11,13 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use super::ObjectName;
|
use super::ObjectName;
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
/// SQL data types
|
/// SQL data types
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum DataType {
|
pub enum DataType {
|
||||||
/// Fixed-length character type e.g. CHAR(10)
|
/// Fixed-length character type e.g. CHAR(10)
|
||||||
Char(Option<u64>),
|
Char(Option<u64>),
|
||||||
|
|
|
@ -13,10 +13,13 @@
|
||||||
//! AST types specific to CREATE/ALTER variants of [Statement]
|
//! AST types specific to CREATE/ALTER variants of [Statement]
|
||||||
//! (commonly referred to as Data Definition Language, or DDL)
|
//! (commonly referred to as Data Definition Language, or DDL)
|
||||||
use super::{display_comma_separated, DataType, Expr, Ident, ObjectName};
|
use super::{display_comma_separated, DataType, Expr, Ident, ObjectName};
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
/// An `ALTER TABLE` (`Statement::AlterTable`) operation
|
/// An `ALTER TABLE` (`Statement::AlterTable`) operation
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum AlterTableOperation {
|
pub enum AlterTableOperation {
|
||||||
/// `ADD <table_constraint>`
|
/// `ADD <table_constraint>`
|
||||||
AddConstraint(TableConstraint),
|
AddConstraint(TableConstraint),
|
||||||
|
@ -36,6 +39,7 @@ impl fmt::Display for AlterTableOperation {
|
||||||
/// A table-level constraint, specified in a `CREATE TABLE` or an
|
/// A table-level constraint, specified in a `CREATE TABLE` or an
|
||||||
/// `ALTER TABLE ADD <constraint>` statement.
|
/// `ALTER TABLE ADD <constraint>` statement.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum TableConstraint {
|
pub enum TableConstraint {
|
||||||
/// `[ CONSTRAINT <name> ] { PRIMARY KEY | UNIQUE } (<columns>)`
|
/// `[ CONSTRAINT <name> ] { PRIMARY KEY | UNIQUE } (<columns>)`
|
||||||
Unique {
|
Unique {
|
||||||
|
@ -95,6 +99,7 @@ impl fmt::Display for TableConstraint {
|
||||||
|
|
||||||
/// SQL column definition
|
/// SQL column definition
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct ColumnDef {
|
pub struct ColumnDef {
|
||||||
pub name: Ident,
|
pub name: Ident,
|
||||||
pub data_type: DataType,
|
pub data_type: DataType,
|
||||||
|
@ -129,6 +134,7 @@ impl fmt::Display for ColumnDef {
|
||||||
/// non-constraint options, lumping them all together under the umbrella of
|
/// non-constraint options, lumping them all together under the umbrella of
|
||||||
/// "column options," and we allow any column option to be named.
|
/// "column options," and we allow any column option to be named.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct ColumnOptionDef {
|
pub struct ColumnOptionDef {
|
||||||
pub name: Option<Ident>,
|
pub name: Option<Ident>,
|
||||||
pub option: ColumnOption,
|
pub option: ColumnOption,
|
||||||
|
@ -143,6 +149,7 @@ impl fmt::Display for ColumnOptionDef {
|
||||||
/// `ColumnOption`s are modifiers that follow a column definition in a `CREATE
|
/// `ColumnOption`s are modifiers that follow a column definition in a `CREATE
|
||||||
/// TABLE` statement.
|
/// TABLE` statement.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum ColumnOption {
|
pub enum ColumnOption {
|
||||||
/// `NULL`
|
/// `NULL`
|
||||||
Null,
|
Null,
|
||||||
|
@ -220,6 +227,7 @@ fn display_constraint_name<'a>(name: &'a Option<Ident>) -> impl fmt::Display + '
|
||||||
///
|
///
|
||||||
/// Used in foreign key constraints in `ON UPDATE` and `ON DELETE` options.
|
/// Used in foreign key constraints in `ON UPDATE` and `ON DELETE` options.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum ReferentialAction {
|
pub enum ReferentialAction {
|
||||||
Restrict,
|
Restrict,
|
||||||
Cascade,
|
Cascade,
|
||||||
|
|
|
@ -18,6 +18,8 @@ mod operator;
|
||||||
mod query;
|
mod query;
|
||||||
mod value;
|
mod value;
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
pub use self::data_type::DataType;
|
pub use self::data_type::DataType;
|
||||||
|
@ -71,6 +73,7 @@ where
|
||||||
|
|
||||||
/// An identifier, decomposed into its value or character data and the quote style.
|
/// An identifier, decomposed into its value or character data and the quote style.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct Ident {
|
pub struct Ident {
|
||||||
/// The value of the identifier without quotes.
|
/// The value of the identifier without quotes.
|
||||||
pub value: String,
|
pub value: String,
|
||||||
|
@ -127,6 +130,7 @@ impl fmt::Display for Ident {
|
||||||
|
|
||||||
/// A name of a table, view, custom type, etc., possibly multi-part, i.e. db.schema.obj
|
/// A name of a table, view, custom type, etc., possibly multi-part, i.e. db.schema.obj
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct ObjectName(pub Vec<Ident>);
|
pub struct ObjectName(pub Vec<Ident>);
|
||||||
|
|
||||||
impl fmt::Display for ObjectName {
|
impl fmt::Display for ObjectName {
|
||||||
|
@ -141,6 +145,7 @@ impl fmt::Display for ObjectName {
|
||||||
/// (e.g. boolean vs string), so the caller must handle expressions of
|
/// (e.g. boolean vs string), so the caller must handle expressions of
|
||||||
/// inappropriate type, like `WHERE 1` or `SELECT 1=1`, as necessary.
|
/// inappropriate type, like `WHERE 1` or `SELECT 1=1`, as necessary.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum Expr {
|
pub enum Expr {
|
||||||
/// Identifier e.g. table name or column name
|
/// Identifier e.g. table name or column name
|
||||||
Identifier(Ident),
|
Identifier(Ident),
|
||||||
|
@ -308,6 +313,7 @@ impl fmt::Display for Expr {
|
||||||
|
|
||||||
/// A window specification (i.e. `OVER (PARTITION BY .. ORDER BY .. etc.)`)
|
/// A window specification (i.e. `OVER (PARTITION BY .. ORDER BY .. etc.)`)
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct WindowSpec {
|
pub struct WindowSpec {
|
||||||
pub partition_by: Vec<Expr>,
|
pub partition_by: Vec<Expr>,
|
||||||
pub order_by: Vec<OrderByExpr>,
|
pub order_by: Vec<OrderByExpr>,
|
||||||
|
@ -353,6 +359,7 @@ impl fmt::Display for WindowSpec {
|
||||||
/// Note: The parser does not validate the specified bounds; the caller should
|
/// Note: The parser does not validate the specified bounds; the caller should
|
||||||
/// reject invalid bounds like `ROWS UNBOUNDED FOLLOWING` before execution.
|
/// reject invalid bounds like `ROWS UNBOUNDED FOLLOWING` before execution.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct WindowFrame {
|
pub struct WindowFrame {
|
||||||
pub units: WindowFrameUnits,
|
pub units: WindowFrameUnits,
|
||||||
pub start_bound: WindowFrameBound,
|
pub start_bound: WindowFrameBound,
|
||||||
|
@ -364,6 +371,7 @@ pub struct WindowFrame {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum WindowFrameUnits {
|
pub enum WindowFrameUnits {
|
||||||
Rows,
|
Rows,
|
||||||
Range,
|
Range,
|
||||||
|
@ -398,6 +406,7 @@ impl FromStr for WindowFrameUnits {
|
||||||
|
|
||||||
/// Specifies [WindowFrame]'s `start_bound` and `end_bound`
|
/// Specifies [WindowFrame]'s `start_bound` and `end_bound`
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum WindowFrameBound {
|
pub enum WindowFrameBound {
|
||||||
/// `CURRENT ROW`
|
/// `CURRENT ROW`
|
||||||
CurrentRow,
|
CurrentRow,
|
||||||
|
@ -422,6 +431,7 @@ impl fmt::Display for WindowFrameBound {
|
||||||
/// A top-level statement (SELECT, INSERT, CREATE, etc.)
|
/// A top-level statement (SELECT, INSERT, CREATE, etc.)
|
||||||
#[allow(clippy::large_enum_variant)]
|
#[allow(clippy::large_enum_variant)]
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum Statement {
|
pub enum Statement {
|
||||||
/// SELECT
|
/// SELECT
|
||||||
Query(Box<Query>),
|
Query(Box<Query>),
|
||||||
|
@ -766,6 +776,7 @@ impl fmt::Display for Statement {
|
||||||
|
|
||||||
/// SQL assignment `foo = expr` as used in SQLUpdate
|
/// SQL assignment `foo = expr` as used in SQLUpdate
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct Assignment {
|
pub struct Assignment {
|
||||||
pub id: Ident,
|
pub id: Ident,
|
||||||
pub value: Expr,
|
pub value: Expr,
|
||||||
|
@ -779,6 +790,7 @@ impl fmt::Display for Assignment {
|
||||||
|
|
||||||
/// A function call
|
/// A function call
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct Function {
|
pub struct Function {
|
||||||
pub name: ObjectName,
|
pub name: ObjectName,
|
||||||
pub args: Vec<Expr>,
|
pub args: Vec<Expr>,
|
||||||
|
@ -805,6 +817,7 @@ impl fmt::Display for Function {
|
||||||
|
|
||||||
/// External table's available file format
|
/// External table's available file format
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum FileFormat {
|
pub enum FileFormat {
|
||||||
TEXTFILE,
|
TEXTFILE,
|
||||||
SEQUENCEFILE,
|
SEQUENCEFILE,
|
||||||
|
@ -856,6 +869,7 @@ impl FromStr for FileFormat {
|
||||||
/// A `LISTAGG` invocation `LISTAGG( [ DISTINCT ] <expr>[, <separator> ] [ON OVERFLOW <on_overflow>] ) )
|
/// A `LISTAGG` invocation `LISTAGG( [ DISTINCT ] <expr>[, <separator> ] [ON OVERFLOW <on_overflow>] ) )
|
||||||
/// [ WITHIN GROUP (ORDER BY <within_group1>[, ...] ) ]`
|
/// [ WITHIN GROUP (ORDER BY <within_group1>[, ...] ) ]`
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct ListAgg {
|
pub struct ListAgg {
|
||||||
pub distinct: bool,
|
pub distinct: bool,
|
||||||
pub expr: Box<Expr>,
|
pub expr: Box<Expr>,
|
||||||
|
@ -892,6 +906,7 @@ impl fmt::Display for ListAgg {
|
||||||
|
|
||||||
/// The `ON OVERFLOW` clause of a LISTAGG invocation
|
/// The `ON OVERFLOW` clause of a LISTAGG invocation
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum ListAggOnOverflow {
|
pub enum ListAggOnOverflow {
|
||||||
/// `ON OVERFLOW ERROR`
|
/// `ON OVERFLOW ERROR`
|
||||||
Error,
|
Error,
|
||||||
|
@ -925,6 +940,7 @@ impl fmt::Display for ListAggOnOverflow {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum ObjectType {
|
pub enum ObjectType {
|
||||||
Table,
|
Table,
|
||||||
View,
|
View,
|
||||||
|
@ -944,6 +960,7 @@ impl fmt::Display for ObjectType {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct SqlOption {
|
pub struct SqlOption {
|
||||||
pub name: Ident,
|
pub name: Ident,
|
||||||
pub value: Value,
|
pub value: Value,
|
||||||
|
@ -956,6 +973,7 @@ impl fmt::Display for SqlOption {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum TransactionMode {
|
pub enum TransactionMode {
|
||||||
AccessMode(TransactionAccessMode),
|
AccessMode(TransactionAccessMode),
|
||||||
IsolationLevel(TransactionIsolationLevel),
|
IsolationLevel(TransactionIsolationLevel),
|
||||||
|
@ -972,6 +990,7 @@ impl fmt::Display for TransactionMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum TransactionAccessMode {
|
pub enum TransactionAccessMode {
|
||||||
ReadOnly,
|
ReadOnly,
|
||||||
ReadWrite,
|
ReadWrite,
|
||||||
|
@ -988,6 +1007,7 @@ impl fmt::Display for TransactionAccessMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum TransactionIsolationLevel {
|
pub enum TransactionIsolationLevel {
|
||||||
ReadUncommitted,
|
ReadUncommitted,
|
||||||
ReadCommitted,
|
ReadCommitted,
|
||||||
|
@ -1008,6 +1028,7 @@ impl fmt::Display for TransactionIsolationLevel {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum ShowStatementFilter {
|
pub enum ShowStatementFilter {
|
||||||
Like(String),
|
Like(String),
|
||||||
Where(Expr),
|
Where(Expr),
|
||||||
|
@ -1024,6 +1045,7 @@ impl fmt::Display for ShowStatementFilter {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum SetVariableValue {
|
pub enum SetVariableValue {
|
||||||
Ident(Ident),
|
Ident(Ident),
|
||||||
Literal(Value),
|
Literal(Value),
|
||||||
|
|
|
@ -10,10 +10,13 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
/// Unary operators
|
/// Unary operators
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum UnaryOperator {
|
pub enum UnaryOperator {
|
||||||
Plus,
|
Plus,
|
||||||
Minus,
|
Minus,
|
||||||
|
@ -32,6 +35,7 @@ impl fmt::Display for UnaryOperator {
|
||||||
|
|
||||||
/// Binary operators
|
/// Binary operators
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum BinaryOperator {
|
pub enum BinaryOperator {
|
||||||
Plus,
|
Plus,
|
||||||
Minus,
|
Minus,
|
||||||
|
|
|
@ -11,10 +11,13 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// The most complete variant of a `SELECT` query expression, optionally
|
/// The most complete variant of a `SELECT` query expression, optionally
|
||||||
/// including `WITH`, `UNION` / other set operations, and `ORDER BY`.
|
/// including `WITH`, `UNION` / other set operations, and `ORDER BY`.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct Query {
|
pub struct Query {
|
||||||
/// WITH (common table expressions, or CTEs)
|
/// WITH (common table expressions, or CTEs)
|
||||||
pub ctes: Vec<Cte>,
|
pub ctes: Vec<Cte>,
|
||||||
|
@ -55,6 +58,7 @@ impl fmt::Display for Query {
|
||||||
/// A node in a tree, representing a "query body" expression, roughly:
|
/// A node in a tree, representing a "query body" expression, roughly:
|
||||||
/// `SELECT ... [ {UNION|EXCEPT|INTERSECT} SELECT ...]`
|
/// `SELECT ... [ {UNION|EXCEPT|INTERSECT} SELECT ...]`
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum SetExpr {
|
pub enum SetExpr {
|
||||||
/// Restricted SELECT .. FROM .. HAVING (no ORDER BY or set operations)
|
/// Restricted SELECT .. FROM .. HAVING (no ORDER BY or set operations)
|
||||||
Select(Box<Select>),
|
Select(Box<Select>),
|
||||||
|
@ -92,6 +96,7 @@ impl fmt::Display for SetExpr {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum SetOperator {
|
pub enum SetOperator {
|
||||||
Union,
|
Union,
|
||||||
Except,
|
Except,
|
||||||
|
@ -112,6 +117,7 @@ impl fmt::Display for SetOperator {
|
||||||
/// appear either as the only body item of an `SQLQuery`, or as an operand
|
/// appear either as the only body item of an `SQLQuery`, or as an operand
|
||||||
/// to a set operation like `UNION`.
|
/// to a set operation like `UNION`.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct Select {
|
pub struct Select {
|
||||||
pub distinct: bool,
|
pub distinct: bool,
|
||||||
/// MSSQL syntax: `TOP (<N>) [ PERCENT ] [ WITH TIES ]`
|
/// MSSQL syntax: `TOP (<N>) [ PERCENT ] [ WITH TIES ]`
|
||||||
|
@ -156,6 +162,7 @@ impl fmt::Display for Select {
|
||||||
/// of the columns returned by the query. The parser does not validate that the
|
/// of the columns returned by the query. The parser does not validate that the
|
||||||
/// number of columns in the query matches the number of columns in the query.
|
/// number of columns in the query matches the number of columns in the query.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct Cte {
|
pub struct Cte {
|
||||||
pub alias: TableAlias,
|
pub alias: TableAlias,
|
||||||
pub query: Query,
|
pub query: Query,
|
||||||
|
@ -169,6 +176,7 @@ impl fmt::Display for Cte {
|
||||||
|
|
||||||
/// One item of the comma-separated list following `SELECT`
|
/// One item of the comma-separated list following `SELECT`
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum SelectItem {
|
pub enum SelectItem {
|
||||||
/// Any expression, not followed by `[ AS ] alias`
|
/// Any expression, not followed by `[ AS ] alias`
|
||||||
UnnamedExpr(Expr),
|
UnnamedExpr(Expr),
|
||||||
|
@ -192,6 +200,7 @@ impl fmt::Display for SelectItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct TableWithJoins {
|
pub struct TableWithJoins {
|
||||||
pub relation: TableFactor,
|
pub relation: TableFactor,
|
||||||
pub joins: Vec<Join>,
|
pub joins: Vec<Join>,
|
||||||
|
@ -209,6 +218,7 @@ impl fmt::Display for TableWithJoins {
|
||||||
|
|
||||||
/// A table name or a parenthesized subquery with an optional alias
|
/// A table name or a parenthesized subquery with an optional alias
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum TableFactor {
|
pub enum TableFactor {
|
||||||
Table {
|
Table {
|
||||||
name: ObjectName,
|
name: ObjectName,
|
||||||
|
@ -274,6 +284,7 @@ impl fmt::Display for TableFactor {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct TableAlias {
|
pub struct TableAlias {
|
||||||
pub name: Ident,
|
pub name: Ident,
|
||||||
pub columns: Vec<Ident>,
|
pub columns: Vec<Ident>,
|
||||||
|
@ -290,6 +301,7 @@ impl fmt::Display for TableAlias {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct Join {
|
pub struct Join {
|
||||||
pub relation: TableFactor,
|
pub relation: TableFactor,
|
||||||
pub join_operator: JoinOperator,
|
pub join_operator: JoinOperator,
|
||||||
|
@ -355,6 +367,7 @@ impl fmt::Display for Join {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum JoinOperator {
|
pub enum JoinOperator {
|
||||||
Inner(JoinConstraint),
|
Inner(JoinConstraint),
|
||||||
LeftOuter(JoinConstraint),
|
LeftOuter(JoinConstraint),
|
||||||
|
@ -368,6 +381,7 @@ pub enum JoinOperator {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum JoinConstraint {
|
pub enum JoinConstraint {
|
||||||
On(Expr),
|
On(Expr),
|
||||||
Using(Vec<Ident>),
|
Using(Vec<Ident>),
|
||||||
|
@ -376,6 +390,7 @@ pub enum JoinConstraint {
|
||||||
|
|
||||||
/// An `ORDER BY` expression
|
/// An `ORDER BY` expression
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct OrderByExpr {
|
pub struct OrderByExpr {
|
||||||
pub expr: Expr,
|
pub expr: Expr,
|
||||||
/// Optional `ASC` or `DESC`
|
/// Optional `ASC` or `DESC`
|
||||||
|
@ -402,6 +417,7 @@ impl fmt::Display for OrderByExpr {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct Offset {
|
pub struct Offset {
|
||||||
pub value: Expr,
|
pub value: Expr,
|
||||||
pub rows: OffsetRows,
|
pub rows: OffsetRows,
|
||||||
|
@ -415,6 +431,7 @@ impl fmt::Display for Offset {
|
||||||
|
|
||||||
/// Stores the keyword after `OFFSET <number>`
|
/// Stores the keyword after `OFFSET <number>`
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum OffsetRows {
|
pub enum OffsetRows {
|
||||||
/// Omitting ROW/ROWS is non-standard MySQL quirk.
|
/// Omitting ROW/ROWS is non-standard MySQL quirk.
|
||||||
None,
|
None,
|
||||||
|
@ -433,6 +450,7 @@ impl fmt::Display for OffsetRows {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct Fetch {
|
pub struct Fetch {
|
||||||
pub with_ties: bool,
|
pub with_ties: bool,
|
||||||
pub percent: bool,
|
pub percent: bool,
|
||||||
|
@ -452,6 +470,7 @@ impl fmt::Display for Fetch {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct Top {
|
pub struct Top {
|
||||||
/// SQL semantic equivalent of LIMIT but with same structure as FETCH.
|
/// SQL semantic equivalent of LIMIT but with same structure as FETCH.
|
||||||
pub with_ties: bool,
|
pub with_ties: bool,
|
||||||
|
@ -472,6 +491,7 @@ impl fmt::Display for Top {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct Values(pub Vec<Vec<Expr>>);
|
pub struct Values(pub Vec<Vec<Expr>>);
|
||||||
|
|
||||||
impl fmt::Display for Values {
|
impl fmt::Display for Values {
|
||||||
|
|
|
@ -12,10 +12,13 @@
|
||||||
|
|
||||||
#[cfg(feature = "bigdecimal")]
|
#[cfg(feature = "bigdecimal")]
|
||||||
use bigdecimal::BigDecimal;
|
use bigdecimal::BigDecimal;
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
/// Primitive SQL values such as number and string
|
/// Primitive SQL values such as number and string
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum Value {
|
pub enum Value {
|
||||||
/// Numeric literal
|
/// Numeric literal
|
||||||
#[cfg(not(feature = "bigdecimal"))]
|
#[cfg(not(feature = "bigdecimal"))]
|
||||||
|
@ -116,6 +119,7 @@ impl fmt::Display for Value {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub enum DateTimeField {
|
pub enum DateTimeField {
|
||||||
Year,
|
Year,
|
||||||
Month,
|
Month,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue