@@ -18,6 +18,7 @@ mod operator;
1818mod query;
1919mod value;
2020
21+ use serde:: { Deserialize , Serialize } ;
2122use std:: fmt;
2223
2324pub use self :: data_type:: DataType ;
7071}
7172
7273/// An identifier, decomposed into its value or character data and the quote style.
73- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
74+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
7475pub struct Ident {
7576 /// The value of the identifier without quotes.
7677 pub value : String ,
@@ -126,7 +127,7 @@ impl fmt::Display for Ident {
126127}
127128
128129/// A name of a table, view, custom type, etc., possibly multi-part, i.e. db.schema.obj
129- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
130+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
130131pub struct ObjectName ( pub Vec < Ident > ) ;
131132
132133impl fmt:: Display for ObjectName {
@@ -140,7 +141,7 @@ impl fmt::Display for ObjectName {
140141/// The parser does not distinguish between expressions of different types
141142/// (e.g. boolean vs string), so the caller must handle expressions of
142143/// inappropriate type, like `WHERE 1` or `SELECT 1=1`, as necessary.
143- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
144+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
144145pub enum Expr {
145146 /// Identifier e.g. table name or column name
146147 Identifier ( Ident ) ,
@@ -303,7 +304,7 @@ impl fmt::Display for Expr {
303304/// Note: we only recognize a complete single expression as `<condition>`,
304305/// not `< 0` nor `1, 2, 3` as allowed in a `<simple when clause>` per
305306/// <https://jakewheat.github.io/sql-overview/sql-2011-foundation-grammar.html#simple-when-clause>
306- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
307+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
307308pub struct WhenClause {
308309 pub condition : Expr ,
309310 pub result : Expr ,
@@ -316,7 +317,7 @@ impl fmt::Display for WhenClause {
316317}
317318
318319/// A window specification (i.e. `OVER (PARTITION BY .. ORDER BY .. etc.)`)
319- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
320+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
320321pub struct WindowSpec {
321322 pub partition_by : Vec < Expr > ,
322323 pub order_by : Vec < OrderByExpr > ,
@@ -361,7 +362,7 @@ impl fmt::Display for WindowSpec {
361362///
362363/// Note: The parser does not validate the specified bounds; the caller should
363364/// reject invalid bounds like `ROWS UNBOUNDED FOLLOWING` before execution.
364- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
365+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
365366pub struct WindowFrame {
366367 pub units : WindowFrameUnits ,
367368 pub start_bound : WindowFrameBound ,
@@ -372,7 +373,7 @@ pub struct WindowFrame {
372373 // TBD: EXCLUDE
373374}
374375
375- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
376+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
376377pub enum WindowFrameUnits {
377378 Rows ,
378379 Range ,
@@ -406,7 +407,7 @@ impl FromStr for WindowFrameUnits {
406407}
407408
408409/// Specifies [WindowFrame]'s `start_bound` and `end_bound`
409- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
410+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
410411pub enum WindowFrameBound {
411412 /// `CURRENT ROW`
412413 CurrentRow ,
@@ -430,7 +431,7 @@ impl fmt::Display for WindowFrameBound {
430431
431432/// A top-level statement (SELECT, INSERT, CREATE, etc.)
432433#[ allow( clippy:: large_enum_variant) ]
433- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
434+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
434435pub enum Statement {
435436 /// SELECT
436437 Query ( Box < Query > ) ,
@@ -774,7 +775,7 @@ impl fmt::Display for Statement {
774775}
775776
776777/// SQL assignment `foo = expr` as used in SQLUpdate
777- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
778+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
778779pub struct Assignment {
779780 pub id : Ident ,
780781 pub value : Expr ,
@@ -787,7 +788,7 @@ impl fmt::Display for Assignment {
787788}
788789
789790/// A function call
790- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
791+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
791792pub struct Function {
792793 pub name : ObjectName ,
793794 pub args : Vec < Expr > ,
@@ -813,7 +814,7 @@ impl fmt::Display for Function {
813814}
814815
815816/// External table's available file format
816- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
817+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
817818pub enum FileFormat {
818819 TEXTFILE ,
819820 SEQUENCEFILE ,
@@ -864,7 +865,7 @@ impl FromStr for FileFormat {
864865
865866/// A `LISTAGG` invocation `LISTAGG( [ DISTINCT ] <expr>[, <separator> ] [ON OVERFLOW <on_overflow>] ) )
866867/// [ WITHIN GROUP (ORDER BY <within_group1>[, ...] ) ]`
867- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
868+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
868869pub struct ListAgg {
869870 pub distinct : bool ,
870871 pub expr : Box < Expr > ,
@@ -900,7 +901,7 @@ impl fmt::Display for ListAgg {
900901}
901902
902903/// The `ON OVERFLOW` clause of a LISTAGG invocation
903- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
904+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
904905pub enum ListAggOnOverflow {
905906 /// `ON OVERFLOW ERROR`
906907 Error ,
@@ -933,7 +934,7 @@ impl fmt::Display for ListAggOnOverflow {
933934 }
934935}
935936
936- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
937+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
937938pub enum ObjectType {
938939 Table ,
939940 View ,
@@ -952,7 +953,7 @@ impl fmt::Display for ObjectType {
952953 }
953954}
954955
955- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
956+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
956957pub struct SqlOption {
957958 pub name : Ident ,
958959 pub value : Value ,
@@ -964,7 +965,7 @@ impl fmt::Display for SqlOption {
964965 }
965966}
966967
967- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
968+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
968969pub enum TransactionMode {
969970 AccessMode ( TransactionAccessMode ) ,
970971 IsolationLevel ( TransactionIsolationLevel ) ,
@@ -980,7 +981,7 @@ impl fmt::Display for TransactionMode {
980981 }
981982}
982983
983- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
984+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
984985pub enum TransactionAccessMode {
985986 ReadOnly ,
986987 ReadWrite ,
@@ -996,7 +997,7 @@ impl fmt::Display for TransactionAccessMode {
996997 }
997998}
998999
999- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
1000+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
10001001pub enum TransactionIsolationLevel {
10011002 ReadUncommitted ,
10021003 ReadCommitted ,
@@ -1016,7 +1017,7 @@ impl fmt::Display for TransactionIsolationLevel {
10161017 }
10171018}
10181019
1019- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
1020+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
10201021pub enum ShowStatementFilter {
10211022 Like ( String ) ,
10221023 Where ( Expr ) ,
@@ -1032,7 +1033,7 @@ impl fmt::Display for ShowStatementFilter {
10321033 }
10331034}
10341035
1035- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
1036+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
10361037pub enum SetVariableValue {
10371038 Ident ( Ident ) ,
10381039 Literal ( Value ) ,
0 commit comments