@@ -29,12 +29,12 @@ use helpers::{
2929} ;
3030
3131use core:: cmp:: Ordering ;
32+ use core:: fmt:: Formatter ;
3233use core:: ops:: Deref ;
3334use core:: {
3435 fmt:: { self , Display } ,
3536 hash,
3637} ;
37-
3838#[ cfg( feature = "serde" ) ]
3939use serde:: { Deserialize , Serialize } ;
4040
@@ -3315,18 +3315,8 @@ pub enum Statement {
33153315 secret_type : Ident ,
33163316 options : Vec < SecretOption > ,
33173317 } ,
3318- /// ```sql
3319- /// CREATE SERVER
3320- /// ```
3321- /// See [PostgreSQL](https://www.postgresql.org/docs/current/sql-createserver.html)
3322- CreateServer {
3323- name : ObjectName ,
3324- if_not_exists : bool ,
3325- server_type : Option < Ident > ,
3326- version : Option < Ident > ,
3327- foreign_data_wrapper : ObjectName ,
3328- options : Option < Vec < ServerOption > > ,
3329- } ,
3318+ /// A `CREATE SERVER` statement.
3319+ CreateServer ( CreateServerStatement ) ,
33303320 /// ```sql
33313321 /// CREATE POLICY
33323322 /// ```
@@ -5187,35 +5177,8 @@ impl fmt::Display for Statement {
51875177 write ! ( f, " )" ) ?;
51885178 Ok ( ( ) )
51895179 }
5190- Statement :: CreateServer {
5191- name,
5192- if_not_exists,
5193- server_type,
5194- version,
5195- foreign_data_wrapper,
5196- options,
5197- } => {
5198- write ! (
5199- f,
5200- "CREATE SERVER {if_not_exists}{name} " ,
5201- if_not_exists = if * if_not_exists { "IF NOT EXISTS " } else { "" } ,
5202- ) ?;
5203-
5204- if let Some ( st) = server_type {
5205- write ! ( f, "TYPE {st} " ) ?;
5206- }
5207-
5208- if let Some ( v) = version {
5209- write ! ( f, "VERSION {v} " ) ?;
5210- }
5211-
5212- write ! ( f, "FOREIGN DATA WRAPPER {foreign_data_wrapper}" ) ?;
5213-
5214- if let Some ( o) = options {
5215- write ! ( f, " OPTIONS ({o})" , o = display_comma_separated( o) ) ?;
5216- }
5217-
5218- Ok ( ( ) )
5180+ Statement :: CreateServer ( stmt) => {
5181+ write ! ( f, "{stmt}" )
52195182 }
52205183 Statement :: CreatePolicy {
52215184 name,
@@ -8015,6 +7978,63 @@ impl fmt::Display for SecretOption {
80157978 }
80167979}
80177980
7981+ /// A `CREATE SERVER` statement.
7982+ ///
7983+ /// Examples:
7984+ /// ```sql
7985+ /// CREATE SERVER [ IF NOT EXISTS ] server_name [ TYPE 'server_type' ] [ VERSION 'server_version' ]
7986+ /// FOREIGN DATA WRAPPER fdw_name
7987+ /// [ OPTIONS ( option 'value' [, ... ] ) ]
7988+ /// ```
7989+ ///
7990+ /// [PostgreSQL Documentation](https://www.postgresql.org/docs/current/sql-createserver.html)
7991+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
7992+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
7993+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
7994+ pub struct CreateServerStatement {
7995+ pub name : ObjectName ,
7996+ pub if_not_exists : bool ,
7997+ pub server_type : Option < Ident > ,
7998+ pub version : Option < Ident > ,
7999+ pub foreign_data_wrapper : ObjectName ,
8000+ pub options : Option < Vec < CreateServerOption > > ,
8001+ }
8002+
8003+ impl fmt:: Display for CreateServerStatement {
8004+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
8005+ let CreateServerStatement {
8006+ name,
8007+ if_not_exists,
8008+ server_type,
8009+ version,
8010+ foreign_data_wrapper,
8011+ options,
8012+ } = self ;
8013+
8014+ write ! (
8015+ f,
8016+ "CREATE SERVER {if_not_exists}{name} " ,
8017+ if_not_exists = if * if_not_exists { "IF NOT EXISTS " } else { "" } ,
8018+ ) ?;
8019+
8020+ if let Some ( st) = server_type {
8021+ write ! ( f, "TYPE {st} " ) ?;
8022+ }
8023+
8024+ if let Some ( v) = version {
8025+ write ! ( f, "VERSION {v} " ) ?;
8026+ }
8027+
8028+ write ! ( f, "FOREIGN DATA WRAPPER {foreign_data_wrapper}" ) ?;
8029+
8030+ if let Some ( o) = options {
8031+ write ! ( f, " OPTIONS ({o})" , o = display_comma_separated( o) ) ?;
8032+ }
8033+
8034+ Ok ( ( ) )
8035+ }
8036+ }
8037+
80188038#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
80198039#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
80208040#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
@@ -8023,7 +8043,7 @@ pub struct CreateServerOption {
80238043 pub value : Ident ,
80248044}
80258045
8026- impl fmt:: Display for ServerOption {
8046+ impl fmt:: Display for CreateServerOption {
80278047 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
80288048 write ! ( f, "{} {}" , self . key, self . value)
80298049 }
0 commit comments