Skip to content

Commit 27cd3df

Browse files
committed
Upgrade to postgres 0.16.0-rc.1
1 parent b22b94c commit 27cd3df

File tree

3 files changed

+48
-123
lines changed

3 files changed

+48
-123
lines changed

Cargo.toml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
11
[package]
22
name = "r2d2_postgres"
3-
version = "0.14.0"
3+
version = "0.15.0-rc.1"
44
authors = ["Steven Fackler <[email protected]>"]
55
edition = "2018"
66
license = "MIT"
77
description = "Postgres support for the r2d2 connection pool"
88
repository = "https://github.com/sfackler/r2d2-postgres"
99
keywords = ["postgres", "sql", "pool", "database"]
1010

11-
[lib]
12-
name = "r2d2_postgres"
13-
path = "src/lib.rs"
14-
test = false
15-
16-
[[test]]
17-
name = "test"
18-
path = "tests/test.rs"
19-
2011
[dependencies]
2112
r2d2 = "0.8"
22-
postgres = "0.15"
23-
postgres-shared = "0.4"
13+
postgres = "0.16.0-rc.1"
14+
tokio-postgres = "0.4.0-rc.2"

src/lib.rs

Lines changed: 45 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,80 @@
11
//! Postgres support for the `r2d2` connection pool.
2-
#![doc(html_root_url="https://docs.rs/r2d2_postgres/0.14")]
2+
#![doc(html_root_url = "https://docs.rs/r2d2_postgres/0.15.0-rc.1")]
33
#![warn(missing_docs)]
4-
pub use r2d2;
54
pub use postgres;
5+
pub use r2d2;
66

7-
use postgres::{Connection, Error, Result};
8-
use postgres::params::{ConnectParams, IntoConnectParams};
9-
use postgres::tls::TlsHandshake;
7+
use postgres::tls::{MakeTlsConnect, TlsConnect};
8+
use postgres::{Client, Config, Error};
9+
use r2d2::ManageConnection;
10+
use tokio_postgres::Socket;
1011

11-
/// Like `postgres::TlsMode` except that it owns its `TlsHandshake` instance.
12-
#[derive(Debug)]
13-
pub enum TlsMode {
14-
/// Like `postgres::TlsMode::None`.
15-
None,
16-
/// Like `postgres::TlsMode::Prefer`.
17-
Prefer(Box<dyn TlsHandshake + Sync + Send>),
18-
/// Like `postgres::TlsMode::Require`.
19-
Require(Box<dyn TlsHandshake + Sync + Send>),
20-
}
21-
22-
/// An `r2d2::ManageConnection` for `postgres::Connection`s.
12+
/// An `r2d2::ManageConnection` for `postgres::Client`s.
2313
///
2414
/// ## Example
2515
///
26-
/// ```rust,no_run
27-
/// extern crate r2d2;
28-
/// extern crate r2d2_postgres;
29-
///
16+
/// ```no_run
3017
/// use std::thread;
31-
/// use r2d2_postgres::{TlsMode, PostgresConnectionManager};
18+
/// use postgres::{NoTls, Client};
19+
/// use r2d2_postgres::PostgresConnectionManager;
3220
///
3321
/// fn main() {
34-
/// let manager = PostgresConnectionManager::new("postgres://postgres@localhost",
35-
/// TlsMode::None).unwrap();
22+
/// let manager = PostgresConnectionManager::new(
23+
/// "host=localhost user=postgres".parse().unwrap(),
24+
/// NoTls,
25+
/// );
3626
/// let pool = r2d2::Pool::new(manager).unwrap();
3727
///
3828
/// for i in 0..10i32 {
3929
/// let pool = pool.clone();
4030
/// thread::spawn(move || {
41-
/// let conn = pool.get().unwrap();
42-
/// conn.execute("INSERT INTO foo (bar) VALUES ($1)", &[&i]).unwrap();
31+
/// let mut client = pool.get().unwrap();
32+
/// client.execute("INSERT INTO foo (bar) VALUES ($1)", &[&i]).unwrap();
4333
/// });
4434
/// }
4535
/// }
4636
/// ```
4737
#[derive(Debug)]
48-
pub struct PostgresConnectionManager {
49-
params: ConnectParams,
50-
ssl_mode: TlsMode,
38+
pub struct PostgresConnectionManager<T> {
39+
config: Config,
40+
tls_connector: T,
5141
}
5242

53-
impl PostgresConnectionManager {
43+
impl<T> PostgresConnectionManager<T>
44+
where
45+
T: MakeTlsConnect<Socket> + Clone + 'static + Sync + Send,
46+
T::TlsConnect: Send,
47+
T::Stream: Send,
48+
<T::TlsConnect as TlsConnect<Socket>>::Future: Send,
49+
{
5450
/// Creates a new `PostgresConnectionManager`.
55-
///
56-
/// See `postgres::Connection::connect` for a description of the parameter
57-
/// types.
58-
pub fn new<T>(params: T,
59-
ssl_mode: TlsMode)
60-
-> Result<PostgresConnectionManager>
61-
where T: IntoConnectParams
62-
{
63-
// FIXME we shouldn't be using this private constructor :(
64-
let params = params.into_connect_params().map_err(postgres_shared::error::connect)?;
65-
66-
Ok(PostgresConnectionManager {
67-
params: params,
68-
ssl_mode: ssl_mode,
69-
})
51+
pub fn new(config: Config, tls_connector: T) -> PostgresConnectionManager<T> {
52+
PostgresConnectionManager {
53+
config,
54+
tls_connector,
55+
}
7056
}
7157
}
7258

73-
impl r2d2::ManageConnection for PostgresConnectionManager {
74-
type Connection = Connection;
59+
impl<T> ManageConnection for PostgresConnectionManager<T>
60+
where
61+
T: MakeTlsConnect<Socket> + Clone + 'static + Sync + Send,
62+
T::TlsConnect: Send,
63+
T::Stream: Send,
64+
<T::TlsConnect as TlsConnect<Socket>>::Future: Send,
65+
{
66+
type Connection = Client;
7567
type Error = Error;
7668

77-
fn connect(&self) -> Result<postgres::Connection> {
78-
let mode = match self.ssl_mode {
79-
TlsMode::None => postgres::TlsMode::None,
80-
TlsMode::Prefer(ref n) => postgres::TlsMode::Prefer(&**n),
81-
TlsMode::Require(ref n) => postgres::TlsMode::Require(&**n),
82-
};
83-
postgres::Connection::connect(self.params.clone(), mode)
69+
fn connect(&self) -> Result<Client, Error> {
70+
self.config.connect(self.tls_connector.clone())
8471
}
8572

86-
fn is_valid(&self, conn: &mut Connection) -> Result<()> {
87-
conn.batch_execute("")
73+
fn is_valid(&self, client: &mut Client) -> Result<(), Error> {
74+
client.simple_query("").map(|_| ())
8875
}
8976

90-
fn has_broken(&self, conn: &mut Connection) -> bool {
91-
conn.is_desynchronized()
77+
fn has_broken(&self, client: &mut Client) -> bool {
78+
client.is_closed()
9279
}
9380
}

tests/test.rs

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)