@@ -56,6 +56,16 @@ pub enum ChannelBinding {
56
56
Require ,
57
57
}
58
58
59
+ /// Replication mode configuration.
60
+ #[ derive( Debug , Copy , Clone , PartialEq ) ]
61
+ #[ non_exhaustive]
62
+ pub enum ReplicationMode {
63
+ /// Physical replication.
64
+ Physical ,
65
+ /// Logical replication.
66
+ Logical ,
67
+ }
68
+
59
69
/// A host specification.
60
70
#[ derive( Debug , Clone , PartialEq ) ]
61
71
pub enum Host {
@@ -159,6 +169,7 @@ pub struct Config {
159
169
pub ( crate ) keepalives_idle : Duration ,
160
170
pub ( crate ) target_session_attrs : TargetSessionAttrs ,
161
171
pub ( crate ) channel_binding : ChannelBinding ,
172
+ pub ( crate ) replication_mode : Option < ReplicationMode > ,
162
173
}
163
174
164
175
impl Default for Config {
@@ -184,6 +195,7 @@ impl Config {
184
195
keepalives_idle : Duration :: from_secs ( 2 * 60 * 60 ) ,
185
196
target_session_attrs : TargetSessionAttrs :: Any ,
186
197
channel_binding : ChannelBinding :: Prefer ,
198
+ replication_mode : None ,
187
199
}
188
200
}
189
201
@@ -387,6 +399,17 @@ impl Config {
387
399
self . channel_binding
388
400
}
389
401
402
+ /// Set replication mode.
403
+ pub fn replication_mode ( & mut self , replication_mode : ReplicationMode ) -> & mut Config {
404
+ self . replication_mode = Some ( replication_mode) ;
405
+ self
406
+ }
407
+
408
+ /// Get replication mode.
409
+ pub fn get_replication_mode ( & self ) -> Option < ReplicationMode > {
410
+ self . replication_mode
411
+ }
412
+
390
413
fn param ( & mut self , key : & str , value : & str ) -> Result < ( ) , Error > {
391
414
match key {
392
415
"user" => {
@@ -476,6 +499,17 @@ impl Config {
476
499
} ;
477
500
self . channel_binding ( channel_binding) ;
478
501
}
502
+ "replication" => {
503
+ let mode = match value {
504
+ "off" => None ,
505
+ "true" => Some ( ReplicationMode :: Physical ) ,
506
+ "database" => Some ( ReplicationMode :: Logical ) ,
507
+ _ => return Err ( Error :: config_parse ( Box :: new ( InvalidValue ( "replication" ) ) ) ) ,
508
+ } ;
509
+ if let Some ( mode) = mode {
510
+ self . replication_mode ( mode) ;
511
+ }
512
+ }
479
513
key => {
480
514
return Err ( Error :: config_parse ( Box :: new ( UnknownOption (
481
515
key. to_string ( ) ,
@@ -548,6 +582,7 @@ impl fmt::Debug for Config {
548
582
. field ( "keepalives_idle" , & self . keepalives_idle )
549
583
. field ( "target_session_attrs" , & self . target_session_attrs )
550
584
. field ( "channel_binding" , & self . channel_binding )
585
+ . field ( "replication" , & self . replication_mode )
551
586
. finish ( )
552
587
}
553
588
}
0 commit comments