@@ -18,6 +18,8 @@ mod operator;
1818mod query;
1919mod value;
2020
21+ #[ cfg( feature = "serde" ) ]
22+ use serde:: { Deserialize , Serialize } ;
2123use std:: fmt;
2224
2325pub use self :: data_type:: DataType ;
7173
7274/// An identifier, decomposed into its value or character data and the quote style.
7375#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
76+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
7477pub struct Ident {
7578 /// The value of the identifier without quotes.
7679 pub value : String ,
@@ -127,6 +130,7 @@ impl fmt::Display for Ident {
127130
128131/// A name of a table, view, custom type, etc., possibly multi-part, i.e. db.schema.obj
129132#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
133+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
130134pub struct ObjectName ( pub Vec < Ident > ) ;
131135
132136impl fmt:: Display for ObjectName {
@@ -141,6 +145,7 @@ impl fmt::Display for ObjectName {
141145/// (e.g. boolean vs string), so the caller must handle expressions of
142146/// inappropriate type, like `WHERE 1` or `SELECT 1=1`, as necessary.
143147#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
148+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
144149pub enum Expr {
145150 /// Identifier e.g. table name or column name
146151 Identifier ( Ident ) ,
@@ -308,6 +313,7 @@ impl fmt::Display for Expr {
308313
309314/// A window specification (i.e. `OVER (PARTITION BY .. ORDER BY .. etc.)`)
310315#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
316+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
311317pub struct WindowSpec {
312318 pub partition_by : Vec < Expr > ,
313319 pub order_by : Vec < OrderByExpr > ,
@@ -353,6 +359,7 @@ impl fmt::Display for WindowSpec {
353359/// Note: The parser does not validate the specified bounds; the caller should
354360/// reject invalid bounds like `ROWS UNBOUNDED FOLLOWING` before execution.
355361#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
362+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
356363pub struct WindowFrame {
357364 pub units : WindowFrameUnits ,
358365 pub start_bound : WindowFrameBound ,
@@ -364,6 +371,7 @@ pub struct WindowFrame {
364371}
365372
366373#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
374+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
367375pub enum WindowFrameUnits {
368376 Rows ,
369377 Range ,
@@ -398,6 +406,7 @@ impl FromStr for WindowFrameUnits {
398406
399407/// Specifies [WindowFrame]'s `start_bound` and `end_bound`
400408#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
409+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
401410pub enum WindowFrameBound {
402411 /// `CURRENT ROW`
403412 CurrentRow ,
@@ -422,6 +431,7 @@ impl fmt::Display for WindowFrameBound {
422431/// A top-level statement (SELECT, INSERT, CREATE, etc.)
423432#[ allow( clippy:: large_enum_variant) ]
424433#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
434+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
425435pub enum Statement {
426436 /// SELECT
427437 Query ( Box < Query > ) ,
@@ -766,6 +776,7 @@ impl fmt::Display for Statement {
766776
767777/// SQL assignment `foo = expr` as used in SQLUpdate
768778#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
779+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
769780pub struct Assignment {
770781 pub id : Ident ,
771782 pub value : Expr ,
@@ -779,6 +790,7 @@ impl fmt::Display for Assignment {
779790
780791/// A function call
781792#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
793+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
782794pub struct Function {
783795 pub name : ObjectName ,
784796 pub args : Vec < Expr > ,
@@ -805,6 +817,7 @@ impl fmt::Display for Function {
805817
806818/// External table's available file format
807819#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
820+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
808821pub enum FileFormat {
809822 TEXTFILE ,
810823 SEQUENCEFILE ,
@@ -856,6 +869,7 @@ impl FromStr for FileFormat {
856869/// A `LISTAGG` invocation `LISTAGG( [ DISTINCT ] <expr>[, <separator> ] [ON OVERFLOW <on_overflow>] ) )
857870/// [ WITHIN GROUP (ORDER BY <within_group1>[, ...] ) ]`
858871#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
872+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
859873pub struct ListAgg {
860874 pub distinct : bool ,
861875 pub expr : Box < Expr > ,
@@ -892,6 +906,7 @@ impl fmt::Display for ListAgg {
892906
893907/// The `ON OVERFLOW` clause of a LISTAGG invocation
894908#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
909+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
895910pub enum ListAggOnOverflow {
896911 /// `ON OVERFLOW ERROR`
897912 Error ,
@@ -925,6 +940,7 @@ impl fmt::Display for ListAggOnOverflow {
925940}
926941
927942#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
943+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
928944pub enum ObjectType {
929945 Table ,
930946 View ,
@@ -944,6 +960,7 @@ impl fmt::Display for ObjectType {
944960}
945961
946962#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
963+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
947964pub struct SqlOption {
948965 pub name : Ident ,
949966 pub value : Value ,
@@ -956,6 +973,7 @@ impl fmt::Display for SqlOption {
956973}
957974
958975#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
976+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
959977pub enum TransactionMode {
960978 AccessMode ( TransactionAccessMode ) ,
961979 IsolationLevel ( TransactionIsolationLevel ) ,
@@ -972,6 +990,7 @@ impl fmt::Display for TransactionMode {
972990}
973991
974992#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
993+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
975994pub enum TransactionAccessMode {
976995 ReadOnly ,
977996 ReadWrite ,
@@ -988,6 +1007,7 @@ impl fmt::Display for TransactionAccessMode {
9881007}
9891008
9901009#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
1010+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
9911011pub enum TransactionIsolationLevel {
9921012 ReadUncommitted ,
9931013 ReadCommitted ,
@@ -1008,6 +1028,7 @@ impl fmt::Display for TransactionIsolationLevel {
10081028}
10091029
10101030#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
1031+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
10111032pub enum ShowStatementFilter {
10121033 Like ( String ) ,
10131034 Where ( Expr ) ,
@@ -1024,6 +1045,7 @@ impl fmt::Display for ShowStatementFilter {
10241045}
10251046
10261047#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
1048+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
10271049pub enum SetVariableValue {
10281050 Ident ( Ident ) ,
10291051 Literal ( Value ) ,
0 commit comments