@@ -11,7 +11,7 @@ use std::str::FromStr;
11
11
use std:: time:: Duration ;
12
12
use tokio:: runtime;
13
13
#[ doc( inline) ]
14
- pub use tokio_postgres:: config:: { ChannelBinding , SslMode , TargetSessionAttrs } ;
14
+ pub use tokio_postgres:: config:: { ChannelBinding , Host , SslMode , TargetSessionAttrs } ;
15
15
use tokio_postgres:: tls:: { MakeTlsConnect , TlsConnect } ;
16
16
use tokio_postgres:: { Error , Socket } ;
17
17
@@ -123,6 +123,12 @@ impl Config {
123
123
self
124
124
}
125
125
126
+ /// Gets the user to authenticate with, if one has been configured with
127
+ /// the `user` method.
128
+ pub fn get_user ( & self ) -> Option < & str > {
129
+ self . config . get_user ( )
130
+ }
131
+
126
132
/// Sets the password to authenticate with.
127
133
pub fn password < T > ( & mut self , password : T ) -> & mut Config
128
134
where
@@ -132,6 +138,12 @@ impl Config {
132
138
self
133
139
}
134
140
141
+ /// Gets the password to authenticate with, if one has been configured with
142
+ /// the `password` method.
143
+ pub fn get_password ( & self ) -> Option < & [ u8 ] > {
144
+ self . config . get_password ( )
145
+ }
146
+
135
147
/// Sets the name of the database to connect to.
136
148
///
137
149
/// Defaults to the user.
@@ -140,18 +152,36 @@ impl Config {
140
152
self
141
153
}
142
154
155
+ /// Gets the name of the database to connect to, if one has been configured
156
+ /// with the `dbname` method.
157
+ pub fn get_dbname ( & self ) -> Option < & str > {
158
+ self . config . get_dbname ( )
159
+ }
160
+
143
161
/// Sets command line options used to configure the server.
144
162
pub fn options ( & mut self , options : & str ) -> & mut Config {
145
163
self . config . options ( options) ;
146
164
self
147
165
}
148
166
167
+ /// Gets the command line options used to configure the server, if the
168
+ /// options have been set with the `options` method.
169
+ pub fn get_options ( & self ) -> Option < & str > {
170
+ self . config . get_options ( )
171
+ }
172
+
149
173
/// Sets the value of the `application_name` runtime parameter.
150
174
pub fn application_name ( & mut self , application_name : & str ) -> & mut Config {
151
175
self . config . application_name ( application_name) ;
152
176
self
153
177
}
154
178
179
+ /// Gets the value of the `application_name` runtime parameter, if it has
180
+ /// been set with the `application_name` method.
181
+ pub fn get_application_name ( & self ) -> Option < & str > {
182
+ self . config . get_application_name ( )
183
+ }
184
+
155
185
/// Sets the SSL configuration.
156
186
///
157
187
/// Defaults to `prefer`.
@@ -160,6 +190,11 @@ impl Config {
160
190
self
161
191
}
162
192
193
+ /// Gets the SSL configuration.
194
+ pub fn get_ssl_mode ( & self ) -> SslMode {
195
+ self . config . get_ssl_mode ( )
196
+ }
197
+
163
198
/// Adds a host to the configuration.
164
199
///
165
200
/// Multiple hosts can be specified by calling this method multiple times, and each will be tried in order. On Unix
@@ -169,6 +204,11 @@ impl Config {
169
204
self
170
205
}
171
206
207
+ /// Gets the hosts that have been added to the configuration with `host`.
208
+ pub fn get_hosts ( & self ) -> & [ Host ] {
209
+ self . config . get_hosts ( )
210
+ }
211
+
172
212
/// Adds a Unix socket host to the configuration.
173
213
///
174
214
/// Unlike `host`, this method allows non-UTF8 paths.
@@ -191,6 +231,11 @@ impl Config {
191
231
self
192
232
}
193
233
234
+ /// Gets the ports that have been added to the configuration with `port`.
235
+ pub fn get_ports ( & self ) -> & [ u16 ] {
236
+ self . config . get_ports ( )
237
+ }
238
+
194
239
/// Sets the timeout applied to socket-level connection attempts.
195
240
///
196
241
/// Note that hostnames can resolve to multiple IP addresses, and this timeout will apply to each address of each
@@ -200,6 +245,12 @@ impl Config {
200
245
self
201
246
}
202
247
248
+ /// Gets the connection timeout, if one has been set with the
249
+ /// `connect_timeout` method.
250
+ pub fn get_connect_timeout ( & self ) -> Option < & Duration > {
251
+ self . config . get_connect_timeout ( )
252
+ }
253
+
203
254
/// Controls the use of TCP keepalive.
204
255
///
205
256
/// This is ignored for Unix domain socket connections. Defaults to `true`.
@@ -208,6 +259,11 @@ impl Config {
208
259
self
209
260
}
210
261
262
+ /// Reports whether TCP keepalives will be used.
263
+ pub fn get_keepalives ( & self ) -> bool {
264
+ self . config . get_keepalives ( )
265
+ }
266
+
211
267
/// Sets the amount of idle time before a keepalive packet is sent on the connection.
212
268
///
213
269
/// This is ignored for Unix domain sockets, or if the `keepalives` option is disabled. Defaults to 2 hours.
@@ -216,6 +272,12 @@ impl Config {
216
272
self
217
273
}
218
274
275
+ /// Gets the configured amount of idle time before a keepalive packet will
276
+ /// be sent on the connection.
277
+ pub fn get_keepalives_idle ( & self ) -> Duration {
278
+ self . config . get_keepalives_idle ( )
279
+ }
280
+
219
281
/// Sets the requirements of the session.
220
282
///
221
283
/// This can be used to connect to the primary server in a clustered database rather than one of the read-only
@@ -228,6 +290,11 @@ impl Config {
228
290
self
229
291
}
230
292
293
+ /// Gets the requirements of the session.
294
+ pub fn get_target_session_attrs ( & self ) -> TargetSessionAttrs {
295
+ self . config . get_target_session_attrs ( )
296
+ }
297
+
231
298
/// Sets the channel binding behavior.
232
299
///
233
300
/// Defaults to `prefer`.
@@ -236,6 +303,11 @@ impl Config {
236
303
self
237
304
}
238
305
306
+ /// Gets the channel binding behavior.
307
+ pub fn get_channel_binding ( & self ) -> ChannelBinding {
308
+ self . config . get_channel_binding ( )
309
+ }
310
+
239
311
/// Opens a connection to a PostgreSQL database.
240
312
pub fn connect < T > ( & self , tls : T ) -> Result < Client , Error >
241
313
where
0 commit comments