@@ -18,6 +18,8 @@ mod operator;
18
18
mod query;
19
19
mod value;
20
20
21
+ #[ cfg( feature = "serde" ) ]
22
+ use serde:: { Deserialize , Serialize } ;
21
23
use std:: fmt;
22
24
23
25
pub use self :: data_type:: DataType ;
71
73
72
74
/// An identifier, decomposed into its value or character data and the quote style.
73
75
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
76
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
74
77
pub struct Ident {
75
78
/// The value of the identifier without quotes.
76
79
pub value : String ,
@@ -127,6 +130,7 @@ impl fmt::Display for Ident {
127
130
128
131
/// A name of a table, view, custom type, etc., possibly multi-part, i.e. db.schema.obj
129
132
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
133
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
130
134
pub struct ObjectName ( pub Vec < Ident > ) ;
131
135
132
136
impl fmt:: Display for ObjectName {
@@ -141,6 +145,7 @@ impl fmt::Display for ObjectName {
141
145
/// (e.g. boolean vs string), so the caller must handle expressions of
142
146
/// inappropriate type, like `WHERE 1` or `SELECT 1=1`, as necessary.
143
147
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
148
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
144
149
pub enum Expr {
145
150
/// Identifier e.g. table name or column name
146
151
Identifier ( Ident ) ,
@@ -308,6 +313,7 @@ impl fmt::Display for Expr {
308
313
309
314
/// A window specification (i.e. `OVER (PARTITION BY .. ORDER BY .. etc.)`)
310
315
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
316
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
311
317
pub struct WindowSpec {
312
318
pub partition_by : Vec < Expr > ,
313
319
pub order_by : Vec < OrderByExpr > ,
@@ -353,6 +359,7 @@ impl fmt::Display for WindowSpec {
353
359
/// Note: The parser does not validate the specified bounds; the caller should
354
360
/// reject invalid bounds like `ROWS UNBOUNDED FOLLOWING` before execution.
355
361
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
362
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
356
363
pub struct WindowFrame {
357
364
pub units : WindowFrameUnits ,
358
365
pub start_bound : WindowFrameBound ,
@@ -364,6 +371,7 @@ pub struct WindowFrame {
364
371
}
365
372
366
373
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
374
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
367
375
pub enum WindowFrameUnits {
368
376
Rows ,
369
377
Range ,
@@ -398,6 +406,7 @@ impl FromStr for WindowFrameUnits {
398
406
399
407
/// Specifies [WindowFrame]'s `start_bound` and `end_bound`
400
408
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
409
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
401
410
pub enum WindowFrameBound {
402
411
/// `CURRENT ROW`
403
412
CurrentRow ,
@@ -422,6 +431,7 @@ impl fmt::Display for WindowFrameBound {
422
431
/// A top-level statement (SELECT, INSERT, CREATE, etc.)
423
432
#[ allow( clippy:: large_enum_variant) ]
424
433
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
434
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
425
435
pub enum Statement {
426
436
/// SELECT
427
437
Query ( Box < Query > ) ,
@@ -766,6 +776,7 @@ impl fmt::Display for Statement {
766
776
767
777
/// SQL assignment `foo = expr` as used in SQLUpdate
768
778
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
779
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
769
780
pub struct Assignment {
770
781
pub id : Ident ,
771
782
pub value : Expr ,
@@ -779,6 +790,7 @@ impl fmt::Display for Assignment {
779
790
780
791
/// A function call
781
792
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
793
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
782
794
pub struct Function {
783
795
pub name : ObjectName ,
784
796
pub args : Vec < Expr > ,
@@ -805,6 +817,7 @@ impl fmt::Display for Function {
805
817
806
818
/// External table's available file format
807
819
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
820
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
808
821
pub enum FileFormat {
809
822
TEXTFILE ,
810
823
SEQUENCEFILE ,
@@ -856,6 +869,7 @@ impl FromStr for FileFormat {
856
869
/// A `LISTAGG` invocation `LISTAGG( [ DISTINCT ] <expr>[, <separator> ] [ON OVERFLOW <on_overflow>] ) )
857
870
/// [ WITHIN GROUP (ORDER BY <within_group1>[, ...] ) ]`
858
871
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
872
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
859
873
pub struct ListAgg {
860
874
pub distinct : bool ,
861
875
pub expr : Box < Expr > ,
@@ -892,6 +906,7 @@ impl fmt::Display for ListAgg {
892
906
893
907
/// The `ON OVERFLOW` clause of a LISTAGG invocation
894
908
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
909
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
895
910
pub enum ListAggOnOverflow {
896
911
/// `ON OVERFLOW ERROR`
897
912
Error ,
@@ -925,6 +940,7 @@ impl fmt::Display for ListAggOnOverflow {
925
940
}
926
941
927
942
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
943
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
928
944
pub enum ObjectType {
929
945
Table ,
930
946
View ,
@@ -944,6 +960,7 @@ impl fmt::Display for ObjectType {
944
960
}
945
961
946
962
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
963
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
947
964
pub struct SqlOption {
948
965
pub name : Ident ,
949
966
pub value : Value ,
@@ -956,6 +973,7 @@ impl fmt::Display for SqlOption {
956
973
}
957
974
958
975
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
976
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
959
977
pub enum TransactionMode {
960
978
AccessMode ( TransactionAccessMode ) ,
961
979
IsolationLevel ( TransactionIsolationLevel ) ,
@@ -972,6 +990,7 @@ impl fmt::Display for TransactionMode {
972
990
}
973
991
974
992
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
993
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
975
994
pub enum TransactionAccessMode {
976
995
ReadOnly ,
977
996
ReadWrite ,
@@ -988,6 +1007,7 @@ impl fmt::Display for TransactionAccessMode {
988
1007
}
989
1008
990
1009
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
1010
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
991
1011
pub enum TransactionIsolationLevel {
992
1012
ReadUncommitted ,
993
1013
ReadCommitted ,
@@ -1008,6 +1028,7 @@ impl fmt::Display for TransactionIsolationLevel {
1008
1028
}
1009
1029
1010
1030
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
1031
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1011
1032
pub enum ShowStatementFilter {
1012
1033
Like ( String ) ,
1013
1034
Where ( Expr ) ,
@@ -1024,6 +1045,7 @@ impl fmt::Display for ShowStatementFilter {
1024
1045
}
1025
1046
1026
1047
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
1048
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1027
1049
pub enum SetVariableValue {
1028
1050
Ident ( Ident ) ,
1029
1051
Literal ( Value ) ,
0 commit comments