@@ -2386,7 +2386,7 @@ pub enum Statement {
2386
2386
identity : Option < TruncateIdentityOption > ,
2387
2387
/// Postgres-specific option
2388
2388
/// [ CASCADE | RESTRICT ]
2389
- cascade : Option < TruncateCascadeOption > ,
2389
+ cascade : Option < CascadeOption > ,
2390
2390
/// ClickHouse-specific option
2391
2391
/// [ ON CLUSTER cluster_name ]
2392
2392
///
@@ -2527,6 +2527,8 @@ pub enum Statement {
2527
2527
/// if not None, has Clickhouse `TO` clause, specify the table into which to insert results
2528
2528
/// <https://clickhouse.com/docs/en/sql-reference/statements/create/view#materialized-view>
2529
2529
to : Option < ObjectName > ,
2530
+ /// MySQL: Optional parameters for the view algorithm, definer, and security context
2531
+ params : Option < CreateViewParams > ,
2530
2532
} ,
2531
2533
/// ```sql
2532
2534
/// CREATE TABLE
@@ -3196,9 +3198,9 @@ pub enum Statement {
3196
3198
Revoke {
3197
3199
privileges : Privileges ,
3198
3200
objects : GrantObjects ,
3199
- grantees : Vec < Ident > ,
3201
+ grantees : Vec < Grantee > ,
3200
3202
granted_by : Option < Ident > ,
3201
- cascade : bool ,
3203
+ cascade : Option < CascadeOption > ,
3202
3204
} ,
3203
3205
/// ```sql
3204
3206
/// DEALLOCATE [ PREPARE ] { name | ALL }
@@ -3634,8 +3636,8 @@ impl fmt::Display for Statement {
3634
3636
}
3635
3637
if let Some ( cascade) = cascade {
3636
3638
match cascade {
3637
- TruncateCascadeOption :: Cascade => write ! ( f, " CASCADE" ) ?,
3638
- TruncateCascadeOption :: Restrict => write ! ( f, " RESTRICT" ) ?,
3639
+ CascadeOption :: Cascade => write ! ( f, " CASCADE" ) ?,
3640
+ CascadeOption :: Restrict => write ! ( f, " RESTRICT" ) ?,
3639
3641
}
3640
3642
}
3641
3643
@@ -3964,11 +3966,19 @@ impl fmt::Display for Statement {
3964
3966
if_not_exists,
3965
3967
temporary,
3966
3968
to,
3969
+ params,
3967
3970
} => {
3968
3971
write ! (
3969
3972
f,
3970
- "CREATE {or_replace}{materialized}{temporary}VIEW {if_not_exists}{name}{to} " ,
3973
+ "CREATE {or_replace}" ,
3971
3974
or_replace = if * or_replace { "OR REPLACE " } else { "" } ,
3975
+ ) ?;
3976
+ if let Some ( params) = params {
3977
+ params. fmt ( f) ?;
3978
+ }
3979
+ write ! (
3980
+ f,
3981
+ "{materialized}{temporary}VIEW {if_not_exists}{name}{to}" ,
3972
3982
materialized = if * materialized { "MATERIALIZED " } else { "" } ,
3973
3983
name = name,
3974
3984
temporary = if * temporary { "TEMPORARY " } else { "" } ,
@@ -4719,7 +4729,9 @@ impl fmt::Display for Statement {
4719
4729
if let Some ( grantor) = granted_by {
4720
4730
write ! ( f, " GRANTED BY {grantor}" ) ?;
4721
4731
}
4722
- write ! ( f, " {}" , if * cascade { "CASCADE" } else { "RESTRICT" } ) ?;
4732
+ if let Some ( cascade) = cascade {
4733
+ write ! ( f, " {}" , cascade) ?;
4734
+ }
4723
4735
Ok ( ( ) )
4724
4736
}
4725
4737
Statement :: Deallocate { name, prepare } => write ! (
@@ -5121,16 +5133,25 @@ pub enum TruncateIdentityOption {
5121
5133
Continue ,
5122
5134
}
5123
5135
5124
- /// PostgreSQL cascade option for TRUNCATE table
5136
+ /// Cascade/restrict option for Postgres TRUNCATE table, MySQL GRANT/REVOKE, etc.
5125
5137
/// [ CASCADE | RESTRICT ]
5126
5138
#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5127
5139
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
5128
5140
#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5129
- pub enum TruncateCascadeOption {
5141
+ pub enum CascadeOption {
5130
5142
Cascade ,
5131
5143
Restrict ,
5132
5144
}
5133
5145
5146
+ impl Display for CascadeOption {
5147
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
5148
+ match self {
5149
+ CascadeOption :: Cascade => write ! ( f, "CASCADE" ) ,
5150
+ CascadeOption :: Restrict => write ! ( f, "RESTRICT" ) ,
5151
+ }
5152
+ }
5153
+ }
5154
+
5134
5155
/// Transaction started with [ TRANSACTION | WORK ]
5135
5156
#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5136
5157
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
@@ -5422,7 +5443,7 @@ impl fmt::Display for Action {
5422
5443
#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5423
5444
pub struct Grantee {
5424
5445
pub grantee_type : GranteesType ,
5425
- pub name : Option < ObjectName > ,
5446
+ pub name : Option < GranteeName > ,
5426
5447
}
5427
5448
5428
5449
impl fmt:: Display for Grantee {
@@ -5455,7 +5476,7 @@ impl fmt::Display for Grantee {
5455
5476
GranteesType :: None => ( ) ,
5456
5477
}
5457
5478
if let Some ( ref name) = self . name {
5458
- write ! ( f , "{}" , name ) ?;
5479
+ name . fmt ( f ) ?;
5459
5480
}
5460
5481
Ok ( ( ) )
5461
5482
}
@@ -5476,6 +5497,28 @@ pub enum GranteesType {
5476
5497
None ,
5477
5498
}
5478
5499
5500
+ /// Users/roles designated in a GRANT/REVOKE
5501
+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5502
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
5503
+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5504
+ pub enum GranteeName {
5505
+ /// A bare identifier
5506
+ ObjectName ( ObjectName ) ,
5507
+ /// A MySQL user/host pair such as 'root'@'%'
5508
+ UserHost { user : Ident , host : Ident } ,
5509
+ }
5510
+
5511
+ impl fmt:: Display for GranteeName {
5512
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
5513
+ match self {
5514
+ GranteeName :: ObjectName ( name) => name. fmt ( f) ,
5515
+ GranteeName :: UserHost { user, host } => {
5516
+ write ! ( f, "{}@{}" , user, host)
5517
+ }
5518
+ }
5519
+ }
5520
+ }
5521
+
5479
5522
/// Objects on which privileges are granted in a GRANT statement.
5480
5523
#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5481
5524
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
@@ -7478,15 +7521,84 @@ pub enum MySQLColumnPosition {
7478
7521
impl Display for MySQLColumnPosition {
7479
7522
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
7480
7523
match self {
7481
- MySQLColumnPosition :: First => Ok ( write ! ( f, "FIRST" ) ? ) ,
7524
+ MySQLColumnPosition :: First => write ! ( f, "FIRST" ) ,
7482
7525
MySQLColumnPosition :: After ( ident) => {
7483
7526
let column_name = & ident. value ;
7484
- Ok ( write ! ( f, "AFTER {column_name}" ) ? )
7527
+ write ! ( f, "AFTER {column_name}" )
7485
7528
}
7486
7529
}
7487
7530
}
7488
7531
}
7489
7532
7533
+ /// MySQL `CREATE VIEW` algorithm parameter: [ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}]
7534
+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
7535
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
7536
+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
7537
+ pub enum CreateViewAlgorithm {
7538
+ Undefined ,
7539
+ Merge ,
7540
+ TempTable ,
7541
+ }
7542
+
7543
+ impl Display for CreateViewAlgorithm {
7544
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
7545
+ match self {
7546
+ CreateViewAlgorithm :: Undefined => write ! ( f, "UNDEFINED" ) ,
7547
+ CreateViewAlgorithm :: Merge => write ! ( f, "MERGE" ) ,
7548
+ CreateViewAlgorithm :: TempTable => write ! ( f, "TEMPTABLE" ) ,
7549
+ }
7550
+ }
7551
+ }
7552
+ /// MySQL `CREATE VIEW` security parameter: [SQL SECURITY { DEFINER | INVOKER }]
7553
+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
7554
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
7555
+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
7556
+ pub enum CreateViewSecurity {
7557
+ Definer ,
7558
+ Invoker ,
7559
+ }
7560
+
7561
+ impl Display for CreateViewSecurity {
7562
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
7563
+ match self {
7564
+ CreateViewSecurity :: Definer => write ! ( f, "DEFINER" ) ,
7565
+ CreateViewSecurity :: Invoker => write ! ( f, "INVOKER" ) ,
7566
+ }
7567
+ }
7568
+ }
7569
+
7570
+ /// [MySQL] `CREATE VIEW` additional parameters
7571
+ ///
7572
+ /// [MySQL]: https://dev.mysql.com/doc/refman/9.1/en/create-view.html
7573
+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
7574
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
7575
+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
7576
+ pub struct CreateViewParams {
7577
+ pub algorithm : Option < CreateViewAlgorithm > ,
7578
+ pub definer : Option < GranteeName > ,
7579
+ pub security : Option < CreateViewSecurity > ,
7580
+ }
7581
+
7582
+ impl Display for CreateViewParams {
7583
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
7584
+ let CreateViewParams {
7585
+ algorithm,
7586
+ definer,
7587
+ security,
7588
+ } = self ;
7589
+ if let Some ( algorithm) = algorithm {
7590
+ write ! ( f, "ALGORITHM = {algorithm} " ) ?;
7591
+ }
7592
+ if let Some ( definers) = definer {
7593
+ write ! ( f, "DEFINER = {definers} " ) ?;
7594
+ }
7595
+ if let Some ( security) = security {
7596
+ write ! ( f, "SQL SECURITY {security} " ) ?;
7597
+ }
7598
+ Ok ( ( ) )
7599
+ }
7600
+ }
7601
+
7490
7602
/// Engine of DB. Some warehouse has parameters of engine, e.g. [clickhouse]
7491
7603
///
7492
7604
/// [clickhouse]: https://clickhouse.com/docs/en/engines/table-engines
0 commit comments