@@ -2368,7 +2368,7 @@ pub enum Statement {
2368
2368
identity : Option < TruncateIdentityOption > ,
2369
2369
/// Postgres-specific option
2370
2370
/// [ CASCADE | RESTRICT ]
2371
- cascade : Option < TruncateCascadeOption > ,
2371
+ cascade : Option < CascadeOption > ,
2372
2372
/// ClickHouse-specific option
2373
2373
/// [ ON CLUSTER cluster_name ]
2374
2374
///
@@ -2509,6 +2509,8 @@ pub enum Statement {
2509
2509
/// if not None, has Clickhouse `TO` clause, specify the table into which to insert results
2510
2510
/// <https://clickhouse.com/docs/en/sql-reference/statements/create/view#materialized-view>
2511
2511
to : Option < ObjectName > ,
2512
+ /// MySQL: Optional parameters for the view algorithm, definer, and security context
2513
+ params : Option < CreateViewParams > ,
2512
2514
} ,
2513
2515
/// ```sql
2514
2516
/// CREATE TABLE
@@ -3178,9 +3180,9 @@ pub enum Statement {
3178
3180
Revoke {
3179
3181
privileges : Privileges ,
3180
3182
objects : GrantObjects ,
3181
- grantees : Vec < Ident > ,
3183
+ grantees : Vec < Grantee > ,
3182
3184
granted_by : Option < Ident > ,
3183
- cascade : bool ,
3185
+ cascade : Option < CascadeOption > ,
3184
3186
} ,
3185
3187
/// ```sql
3186
3188
/// DEALLOCATE [ PREPARE ] { name | ALL }
@@ -3616,8 +3618,8 @@ impl fmt::Display for Statement {
3616
3618
}
3617
3619
if let Some ( cascade) = cascade {
3618
3620
match cascade {
3619
- TruncateCascadeOption :: Cascade => write ! ( f, " CASCADE" ) ?,
3620
- TruncateCascadeOption :: Restrict => write ! ( f, " RESTRICT" ) ?,
3621
+ CascadeOption :: Cascade => write ! ( f, " CASCADE" ) ?,
3622
+ CascadeOption :: Restrict => write ! ( f, " RESTRICT" ) ?,
3621
3623
}
3622
3624
}
3623
3625
@@ -3946,11 +3948,19 @@ impl fmt::Display for Statement {
3946
3948
if_not_exists,
3947
3949
temporary,
3948
3950
to,
3951
+ params,
3949
3952
} => {
3950
3953
write ! (
3951
3954
f,
3952
- "CREATE {or_replace}{materialized}{temporary}VIEW {if_not_exists}{name}{to} " ,
3955
+ "CREATE {or_replace}" ,
3953
3956
or_replace = if * or_replace { "OR REPLACE " } else { "" } ,
3957
+ ) ?;
3958
+ if let Some ( params) = params {
3959
+ params. fmt ( f) ?;
3960
+ }
3961
+ write ! (
3962
+ f,
3963
+ "{materialized}{temporary}VIEW {if_not_exists}{name}{to}" ,
3954
3964
materialized = if * materialized { "MATERIALIZED " } else { "" } ,
3955
3965
name = name,
3956
3966
temporary = if * temporary { "TEMPORARY " } else { "" } ,
@@ -4701,7 +4711,9 @@ impl fmt::Display for Statement {
4701
4711
if let Some ( grantor) = granted_by {
4702
4712
write ! ( f, " GRANTED BY {grantor}" ) ?;
4703
4713
}
4704
- write ! ( f, " {}" , if * cascade { "CASCADE" } else { "RESTRICT" } ) ?;
4714
+ if let Some ( cascade) = cascade {
4715
+ write ! ( f, " {}" , cascade) ?;
4716
+ }
4705
4717
Ok ( ( ) )
4706
4718
}
4707
4719
Statement :: Deallocate { name, prepare } => write ! (
@@ -5103,16 +5115,25 @@ pub enum TruncateIdentityOption {
5103
5115
Continue ,
5104
5116
}
5105
5117
5106
- /// PostgreSQL cascade option for TRUNCATE table
5118
+ /// Cascade/restrict option for Postgres TRUNCATE table, MySQL GRANT/REVOKE, etc.
5107
5119
/// [ CASCADE | RESTRICT ]
5108
5120
#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5109
5121
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
5110
5122
#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5111
- pub enum TruncateCascadeOption {
5123
+ pub enum CascadeOption {
5112
5124
Cascade ,
5113
5125
Restrict ,
5114
5126
}
5115
5127
5128
+ impl Display for CascadeOption {
5129
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
5130
+ match self {
5131
+ CascadeOption :: Cascade => write ! ( f, "CASCADE" ) ,
5132
+ CascadeOption :: Restrict => write ! ( f, "RESTRICT" ) ,
5133
+ }
5134
+ }
5135
+ }
5136
+
5116
5137
/// Transaction started with [ TRANSACTION | WORK ]
5117
5138
#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5118
5139
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
@@ -5404,7 +5425,7 @@ impl fmt::Display for Action {
5404
5425
#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5405
5426
pub struct Grantee {
5406
5427
pub grantee_type : GranteesType ,
5407
- pub name : Option < ObjectName > ,
5428
+ pub name : Option < GranteeName > ,
5408
5429
}
5409
5430
5410
5431
impl fmt:: Display for Grantee {
@@ -5437,7 +5458,7 @@ impl fmt::Display for Grantee {
5437
5458
GranteesType :: None => ( ) ,
5438
5459
}
5439
5460
if let Some ( ref name) = self . name {
5440
- write ! ( f , "{}" , name ) ?;
5461
+ name . fmt ( f ) ?;
5441
5462
}
5442
5463
Ok ( ( ) )
5443
5464
}
@@ -5458,6 +5479,28 @@ pub enum GranteesType {
5458
5479
None ,
5459
5480
}
5460
5481
5482
+ /// Users/roles designated in a GRANT/REVOKE
5483
+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5484
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
5485
+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5486
+ pub enum GranteeName {
5487
+ /// A bare identifier
5488
+ ObjectName ( ObjectName ) ,
5489
+ /// A MySQL user/host pair such as 'root'@'%'
5490
+ UserHost { user : Ident , host : Ident } ,
5491
+ }
5492
+
5493
+ impl fmt:: Display for GranteeName {
5494
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
5495
+ match self {
5496
+ GranteeName :: ObjectName ( name) => name. fmt ( f) ,
5497
+ GranteeName :: UserHost { user, host } => {
5498
+ write ! ( f, "{}@{}" , user, host)
5499
+ }
5500
+ }
5501
+ }
5502
+ }
5503
+
5461
5504
/// Objects on which privileges are granted in a GRANT statement.
5462
5505
#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5463
5506
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
@@ -7460,15 +7503,84 @@ pub enum MySQLColumnPosition {
7460
7503
impl Display for MySQLColumnPosition {
7461
7504
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
7462
7505
match self {
7463
- MySQLColumnPosition :: First => Ok ( write ! ( f, "FIRST" ) ? ) ,
7506
+ MySQLColumnPosition :: First => write ! ( f, "FIRST" ) ,
7464
7507
MySQLColumnPosition :: After ( ident) => {
7465
7508
let column_name = & ident. value ;
7466
- Ok ( write ! ( f, "AFTER {column_name}" ) ? )
7509
+ write ! ( f, "AFTER {column_name}" )
7467
7510
}
7468
7511
}
7469
7512
}
7470
7513
}
7471
7514
7515
+ /// MySQL `CREATE VIEW` algorithm parameter: [ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}]
7516
+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
7517
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
7518
+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
7519
+ pub enum CreateViewAlgorithm {
7520
+ Undefined ,
7521
+ Merge ,
7522
+ TempTable ,
7523
+ }
7524
+
7525
+ impl Display for CreateViewAlgorithm {
7526
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
7527
+ match self {
7528
+ CreateViewAlgorithm :: Undefined => write ! ( f, "UNDEFINED" ) ,
7529
+ CreateViewAlgorithm :: Merge => write ! ( f, "MERGE" ) ,
7530
+ CreateViewAlgorithm :: TempTable => write ! ( f, "TEMPTABLE" ) ,
7531
+ }
7532
+ }
7533
+ }
7534
+ /// MySQL `CREATE VIEW` security parameter: [SQL SECURITY { DEFINER | INVOKER }]
7535
+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
7536
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
7537
+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
7538
+ pub enum CreateViewSecurity {
7539
+ Definer ,
7540
+ Invoker ,
7541
+ }
7542
+
7543
+ impl Display for CreateViewSecurity {
7544
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
7545
+ match self {
7546
+ CreateViewSecurity :: Definer => write ! ( f, "DEFINER" ) ,
7547
+ CreateViewSecurity :: Invoker => write ! ( f, "INVOKER" ) ,
7548
+ }
7549
+ }
7550
+ }
7551
+
7552
+ /// [MySQL] `CREATE VIEW` additional parameters
7553
+ ///
7554
+ /// [MySQL]: https://dev.mysql.com/doc/refman/9.1/en/create-view.html
7555
+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
7556
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
7557
+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
7558
+ pub struct CreateViewParams {
7559
+ pub algorithm : Option < CreateViewAlgorithm > ,
7560
+ pub definer : Option < GranteeName > ,
7561
+ pub security : Option < CreateViewSecurity > ,
7562
+ }
7563
+
7564
+ impl Display for CreateViewParams {
7565
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
7566
+ let CreateViewParams {
7567
+ algorithm,
7568
+ definer,
7569
+ security,
7570
+ } = self ;
7571
+ if let Some ( algorithm) = algorithm {
7572
+ write ! ( f, "ALGORITHM = {algorithm} " ) ?;
7573
+ }
7574
+ if let Some ( definers) = definer {
7575
+ write ! ( f, "DEFINER = {definers} " ) ?;
7576
+ }
7577
+ if let Some ( security) = security {
7578
+ write ! ( f, "SQL SECURITY {security} " ) ?;
7579
+ }
7580
+ Ok ( ( ) )
7581
+ }
7582
+ }
7583
+
7472
7584
/// Engine of DB. Some warehouse has parameters of engine, e.g. [clickhouse]
7473
7585
///
7474
7586
/// [clickhouse]: https://clickhouse.com/docs/en/engines/table-engines
0 commit comments