@@ -6136,3 +6136,111 @@ impl From<CreateTextSearchTemplate> for crate::ast::Statement {
61366136 crate :: ast:: Statement :: CreateTextSearchTemplate ( v)
61376137 }
61386138}
6139+
6140+ /// The target of a `CREATE PUBLICATION` statement: which rows to publish.
6141+ ///
6142+ /// See <https://www.postgresql.org/docs/current/sql-createpublication.html>
6143+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
6144+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
6145+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
6146+ pub enum PublicationTarget {
6147+ /// `FOR ALL TABLES`
6148+ AllTables ,
6149+ /// `FOR TABLE table [, ...]`
6150+ Tables ( Vec < ObjectName > ) ,
6151+ /// `FOR TABLES IN SCHEMA schema [, ...]`
6152+ TablesInSchema ( Vec < Ident > ) ,
6153+ }
6154+
6155+ impl fmt:: Display for PublicationTarget {
6156+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
6157+ match self {
6158+ PublicationTarget :: AllTables => write ! ( f, "FOR ALL TABLES" ) ,
6159+ PublicationTarget :: Tables ( tables) => {
6160+ write ! ( f, "FOR TABLE {}" , display_comma_separated( tables) )
6161+ }
6162+ PublicationTarget :: TablesInSchema ( schemas) => {
6163+ write ! (
6164+ f,
6165+ "FOR TABLES IN SCHEMA {}" ,
6166+ display_comma_separated( schemas)
6167+ )
6168+ }
6169+ }
6170+ }
6171+ }
6172+
6173+ /// A `CREATE PUBLICATION` statement.
6174+ ///
6175+ /// Note: this is a PostgreSQL-specific statement.
6176+ /// <https://www.postgresql.org/docs/current/sql-createpublication.html>
6177+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
6178+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
6179+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
6180+ pub struct CreatePublication {
6181+ /// The publication name.
6182+ pub name : Ident ,
6183+ /// Optional target specification (`FOR ALL TABLES`, `FOR TABLE ...`, or `FOR TABLES IN SCHEMA ...`).
6184+ pub target : Option < PublicationTarget > ,
6185+ /// Optional `WITH (key = value, ...)` clause.
6186+ pub with_options : Vec < SqlOption > ,
6187+ }
6188+
6189+ impl fmt:: Display for CreatePublication {
6190+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
6191+ write ! ( f, "CREATE PUBLICATION {}" , self . name) ?;
6192+ if let Some ( target) = & self . target {
6193+ write ! ( f, " {target}" ) ?;
6194+ }
6195+ if !self . with_options . is_empty ( ) {
6196+ write ! ( f, " WITH ({})" , display_comma_separated( & self . with_options) ) ?;
6197+ }
6198+ Ok ( ( ) )
6199+ }
6200+ }
6201+
6202+ impl From < CreatePublication > for crate :: ast:: Statement {
6203+ fn from ( v : CreatePublication ) -> Self {
6204+ crate :: ast:: Statement :: CreatePublication ( v)
6205+ }
6206+ }
6207+
6208+ /// A `CREATE SUBSCRIPTION` statement.
6209+ ///
6210+ /// Note: this is a PostgreSQL-specific statement.
6211+ /// <https://www.postgresql.org/docs/current/sql-createsubscription.html>
6212+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
6213+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
6214+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
6215+ pub struct CreateSubscription {
6216+ /// The subscription name.
6217+ pub name : Ident ,
6218+ /// The `CONNECTION 'conninfo'` string.
6219+ pub connection : Value ,
6220+ /// The `PUBLICATION publication_name [, ...]` list.
6221+ pub publications : Vec < Ident > ,
6222+ /// Optional `WITH (key = value, ...)` clause.
6223+ pub with_options : Vec < SqlOption > ,
6224+ }
6225+
6226+ impl fmt:: Display for CreateSubscription {
6227+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
6228+ write ! (
6229+ f,
6230+ "CREATE SUBSCRIPTION {name} CONNECTION {connection} PUBLICATION {publications}" ,
6231+ name = self . name,
6232+ connection = self . connection,
6233+ publications = display_comma_separated( & self . publications) ,
6234+ ) ?;
6235+ if !self . with_options . is_empty ( ) {
6236+ write ! ( f, " WITH ({})" , display_comma_separated( & self . with_options) ) ?;
6237+ }
6238+ Ok ( ( ) )
6239+ }
6240+ }
6241+
6242+ impl From < CreateSubscription > for crate :: ast:: Statement {
6243+ fn from ( v : CreateSubscription ) -> Self {
6244+ crate :: ast:: Statement :: CreateSubscription ( v)
6245+ }
6246+ }
0 commit comments