Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit27cd3df

Browse files
committed
Upgrade to postgres 0.16.0-rc.1
1 parentb22b94c commit27cd3df

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 <sfackler@gmail.com>"]
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-
pubuse r2d2;
54
pubuse postgres;
5+
pubuse 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-
pubenumTlsMode{
14-
/// Like `postgres::TlsMode::None`.
15-
None,
16-
/// Like `postgres::TlsMode::Prefer`.
17-
Prefer(Box<dynTlsHandshake +Sync +Send>),
18-
/// Like `postgres::TlsMode::Require`.
19-
Require(Box<dynTlsHandshake +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-
/// letconn = pool.get().unwrap();
42-
///conn.execute("INSERT INTO foo (bar) VALUES ($1)", &[&i]).unwrap();
31+
/// letmut client = pool.get().unwrap();
32+
///client.execute("INSERT INTO foo (bar) VALUES ($1)", &[&i]).unwrap();
4333
/// });
4434
/// }
4535
/// }
4636
/// ```
4737
#[derive(Debug)]
48-
pubstructPostgresConnectionManager{
49-
params:ConnectParams,
50-
ssl_mode:TlsMode,
38+
pubstructPostgresConnectionManager<T>{
39+
config:Config,
40+
tls_connector:T,
5141
}
5242

53-
implPostgresConnectionManager{
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::TlsConnectasTlsConnect<Socket>>::Future:Send,
49+
{
5450
/// Creates a new `PostgresConnectionManager`.
55-
///
56-
/// See `postgres::Connection::connect` for a description of the parameter
57-
/// types.
58-
pubfnnew<T>(params:T,
59-
ssl_mode:TlsMode)
60-
->Result<PostgresConnectionManager>
61-
whereT: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+
pubfnnew(config:Config,tls_connector:T) ->PostgresConnectionManager<T>{
52+
PostgresConnectionManager{
53+
config,
54+
tls_connector,
55+
}
7056
}
7157
}
7258

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

77-
fnconnect(&self) ->Result<postgres::Connection>{
78-
let mode =matchself.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+
fnconnect(&self) ->Result<Client,Error>{
70+
self.config.connect(self.tls_connector.clone())
8471
}
8572

86-
fnis_valid(&self,conn:&mutConnection) ->Result<()>{
87-
conn.batch_execute("")
73+
fnis_valid(&self,client:&mutClient) ->Result<(),Error>{
74+
client.simple_query("").map(|_|())
8875
}
8976

90-
fnhas_broken(&self,conn:&mutConnection) ->bool{
91-
conn.is_desynchronized()
77+
fnhas_broken(&self,client:&mutClient) ->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)

[8]ページ先頭

©2009-2025 Movatter.jp