Skip to content

Commit 7ff4b3a

Browse files
committed
Merge latest master into branch
2 parents 508b430 + f8d14d0 commit 7ff4b3a

File tree

34 files changed

+486
-96
lines changed

34 files changed

+486
-96
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ version: 2
2222
jobs:
2323
build:
2424
docker:
25-
- image: rust:1.39.0
25+
- image: rust:1.40.0
2626
environment:
2727
RUSTFLAGS: -D warnings
2828
- image: sfackler/rust-postgres-test:6

postgres-derive/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3-
## v0.1.0-alpha.1 - 2019-10-14
3+
## v0.4.0 - 2019-12-23
4+
5+
No changes
6+
7+
## v0.4.0-alpha.1 - 2019-10-14
48

59
* Initial release

postgres-derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "postgres-derive"
3-
version = "0.4.0-alpha.1"
3+
version = "0.4.0"
44
authors = ["Steven Fackler <sfackler@palantir.com>"]
55
license = "MIT/Apache-2.0"
66
edition = "2018"

postgres-native-tls/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## v0.3.0 - 2019-12-23
4+
5+
### Changed
6+
7+
* Upgraded to `tokio-postgres` 0.5.
8+
39
## v0.3.0-alpha.2 - 2019-11-27
410

511
### Changed

postgres-native-tls/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "postgres-native-tls"
3-
version = "0.3.0-alpha.2"
3+
version = "0.3.0"
44
authors = ["Steven Fackler <sfackler@gmail.com>"]
55
edition = "2018"
66
license = "MIT/Apache-2.0"
@@ -21,8 +21,8 @@ futures = "0.3"
2121
native-tls = "0.2"
2222
tokio = "0.2"
2323
tokio-tls = "0.3"
24-
tokio-postgres = { version = "=0.5.0-alpha.2", path = "../tokio-postgres", default-features = false }
24+
tokio-postgres = { version = "0.5.0", path = "../tokio-postgres", default-features = false }
2525

2626
[dev-dependencies]
2727
tokio = { version = "0.2", features = ["full"] }
28-
postgres = { version = "=0.17.0-alpha.2", path = "../postgres" }
28+
postgres = { version = "0.17.0", path = "../postgres" }

postgres-openssl/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## v0.3.0 - 2019-12-23
4+
5+
### Changed
6+
7+
* Upgraded to `tokio-postgres` 0.5.
8+
39
## v0.3.0-alpha.2 - 2019-11-27
410

511
### Changed

postgres-openssl/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "postgres-openssl"
3-
version = "0.3.0-alpha.2"
3+
version = "0.3.0"
44
authors = ["Steven Fackler <sfackler@gmail.com>"]
55
edition = "2018"
66
license = "MIT/Apache-2.0"
@@ -21,8 +21,8 @@ futures = "0.3"
2121
openssl = "0.10"
2222
tokio = "0.2"
2323
tokio-openssl = "0.4"
24-
tokio-postgres = { version = "=0.5.0-alpha.2", path = "../tokio-postgres", default-features = false }
24+
tokio-postgres = { version = "0.5.0", path = "../tokio-postgres", default-features = false }
2525

2626
[dev-dependencies]
2727
tokio = { version = "0.2", features = ["full"] }
28-
postgres = { version = "=0.17.0-alpha.2", path = "../postgres" }
28+
postgres = { version = "0.17.0", path = "../postgres" }

postgres-protocol/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## v0.5.0 - 2019-12-23
4+
5+
### Changed
6+
7+
* `frontend::Message` is now a true non-exhaustive enum.
8+
39
## v0.5.0-alpha.2 - 2019-11-27
410

511
### Changed

postgres-protocol/Cargo.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
[package]
22
name = "postgres-protocol"
3-
version = "0.5.0-alpha.2"
3+
version = "0.5.0"
44
authors = ["Steven Fackler <sfackler@gmail.com>"]
55
edition = "2018"
66
description = "Low level Postgres protocol APIs"
77
license = "MIT/Apache-2.0"
8-
repository = "https://github.com/sfackler/rust-postgres-protocol"
8+
repository = "https://github.com/sfackler/rust-postgres"
99
readme = "../README.md"
1010

1111
[dependencies]
12-
base64 = "0.10"
12+
base64 = "0.11"
1313
byteorder = "1.0"
1414
bytes = "0.5"
1515
fallible-iterator = "0.2"
16-
generic-array = "0.13"
1716
hmac = "0.7"
18-
md5 = "0.6"
17+
md5 = "0.7"
1918
memchr = "2.0"
2019
rand = "0.7"
2120
sha2 = "0.8"

postgres-protocol/src/authentication/sasl.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! SASL-based authentication support.
22
3-
use generic_array::typenum::U32;
4-
use generic_array::GenericArray;
53
use hmac::{Hmac, Mac};
64
use rand::{self, Rng};
75
use sha2::{Digest, Sha256};
@@ -33,13 +31,13 @@ fn normalize(pass: &[u8]) -> Vec<u8> {
3331
}
3432
}
3533

36-
fn hi(str: &[u8], salt: &[u8], i: u32) -> GenericArray<u8, U32> {
34+
fn hi(str: &[u8], salt: &[u8], i: u32) -> [u8; 32] {
3735
let mut hmac = Hmac::<Sha256>::new_varkey(str).expect("HMAC is able to accept all key sizes");
3836
hmac.input(salt);
3937
hmac.input(&[0, 0, 0, 1]);
4038
let mut prev = hmac.result().code();
4139

42-
let mut hi = GenericArray::<u8, U32>::clone_from_slice(&prev);
40+
let mut hi = prev;
4341

4442
for _ in 1..i {
4543
let mut hmac = Hmac::<Sha256>::new_varkey(str).expect("already checked above");
@@ -51,7 +49,7 @@ fn hi(str: &[u8], salt: &[u8], i: u32) -> GenericArray<u8, U32> {
5149
}
5250
}
5351

54-
hi
52+
hi.into()
5553
}
5654

5755
enum ChannelBindingInner {
@@ -103,7 +101,7 @@ enum State {
103101
channel_binding: ChannelBinding,
104102
},
105103
Finish {
106-
salted_password: GenericArray<u8, U32>,
104+
salted_password: [u8; 32],
107105
auth_message: String,
108106
},
109107
Done,
@@ -220,7 +218,7 @@ impl ScramSha256 {
220218
hmac.input(auth_message.as_bytes());
221219
let client_signature = hmac.result();
222220

223-
let mut client_proof = GenericArray::<u8, U32>::clone_from_slice(&client_key);
221+
let mut client_proof = client_key;
224222
for (proof, signature) in client_proof.iter_mut().zip(client_signature.code()) {
225223
*proof ^= signature;
226224
}

postgres-protocol/src/message/backend.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ impl Header {
7272
}
7373

7474
/// An enum representing Postgres backend messages.
75+
#[non_exhaustive]
7576
pub enum Message {
7677
AuthenticationCleartextPassword,
7778
AuthenticationGss,
@@ -104,8 +105,6 @@ pub enum Message {
104105
PortalSuspended,
105106
ReadyForQuery(ReadyForQueryBody),
106107
RowDescription(RowDescriptionBody),
107-
#[doc(hidden)]
108-
__ForExtensibility,
109108
}
110109

111110
impl Message {

postgres-types/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Change Log
22

3+
## v0.1.0 - 2019-12-23
4+
5+
### Changed
6+
7+
* `Kind` is now a true non-exhaustive enum.
8+
9+
### Removed
10+
11+
* Removed `uuid` 0.7 support.
12+
13+
### Added
14+
15+
* Added a `Hash` implementation for `Type`.
16+
317
## v0.1.0-alpha.2 - 2019-11-27
418

519
### Changed

postgres-types/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "postgres-types"
3-
version = "0.1.0-alpha.2"
3+
version = "0.1.0"
44
authors = ["Steven Fackler <sfackler@gmail.com>"]
55
edition = "2018"
66
license = "MIT/Apache-2.0"
@@ -22,8 +22,8 @@ with-uuid-0_8 = ["uuid-08"]
2222
[dependencies]
2323
bytes = "0.5"
2424
fallible-iterator = "0.2"
25-
postgres-protocol = { version = "=0.5.0-alpha.2", path = "../postgres-protocol" }
26-
postgres-derive = { version = "=0.4.0-alpha.1", optional = true, path = "../postgres-derive" }
25+
postgres-protocol = { version = "0.5.0", path = "../postgres-protocol" }
26+
postgres-derive = { version = "0.4.0", optional = true, path = "../postgres-derive" }
2727

2828
bit-vec-06 = { version = "0.6", package = "bit-vec", optional = true }
2929
chrono-04 = { version = "0.4", package = "chrono", optional = true }

postgres-types/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ impl Type {
263263

264264
/// Represents the kind of a Postgres type.
265265
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
266+
#[non_exhaustive]
266267
pub enum Kind {
267268
/// A simple type like `VARCHAR` or `INTEGER`.
268269
Simple,
@@ -278,8 +279,6 @@ pub enum Kind {
278279
Domain(Type),
279280
/// A composite type along with information about its fields.
280281
Composite(Vec<Field>),
281-
#[doc(hidden)]
282-
__ForExtensibility,
283282
}
284283

285284
/// Information about a field of a composite type.

postgres/CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
# Change Log
22

3+
## v0.17.0 - 2019-12-23
4+
5+
### Changed
6+
7+
* Each `Client` now has its own non-threaded tokio `Runtime` rather than sharing a global threaded `Runtime`. This
8+
significantly improves performance by minimizing context switches and cross-thread synchronization.
9+
* `Client::copy_in` now returns a writer rather than taking in a reader.
10+
* `Client::query_raw` now returns a named type.
11+
* `Client::copy_in` and `Client::copy_out` no longer take query parameters as PostgreSQL doesn't support them in COPY
12+
queries.
13+
14+
### Removed
15+
16+
* Removed support for `uuid` 0.7.
17+
18+
### Added
19+
20+
* Added `Client::query_opt` for queries that are expected to return zero or one rows.
21+
* Added binary copy support in the `binary_copy` module.
22+
* The `fallible-iterator` crate is now publicly reexported.
23+
324
## v0.17.0-alpha.2 - 2019-11-27
425

526
### Changed

postgres/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "postgres"
3-
version = "0.17.0-alpha.2"
3+
version = "0.17.0"
44
authors = ["Steven Fackler <sfackler@gmail.com>"]
55
edition = "2018"
66
license = "MIT/Apache-2.0"
@@ -32,11 +32,10 @@ with-uuid-0_8 = ["tokio-postgres/with-uuid-0_8"]
3232
bytes = "0.5"
3333
fallible-iterator = "0.2"
3434
futures = "0.3"
35-
tokio-postgres = { version = "=0.5.0-alpha.2", path = "../tokio-postgres" }
35+
tokio-postgres = { version = "0.5.0", path = "../tokio-postgres" }
3636

3737
tokio = { version = "0.2", features = ["rt-core"] }
3838
log = "0.4"
3939

4040
[dev-dependencies]
4141
criterion = "0.3"
42-
tokio = "0.2"

postgres/src/cancel_token.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use tokio::runtime;
2+
use tokio_postgres::tls::MakeTlsConnect;
3+
use tokio_postgres::{Error, Socket};
4+
5+
/// The capability to request cancellation of in-progress queries on a
6+
/// connection.
7+
#[derive(Clone)]
8+
pub struct CancelToken(tokio_postgres::CancelToken);
9+
10+
impl CancelToken {
11+
pub(crate) fn new(inner: tokio_postgres::CancelToken) -> CancelToken {
12+
CancelToken(inner)
13+
}
14+
15+
/// Attempts to cancel the in-progress query on the connection associated
16+
/// with this `CancelToken`.
17+
///
18+
/// The server provides no information about whether a cancellation attempt was successful or not. An error will
19+
/// only be returned if the client was unable to connect to the database.
20+
///
21+
/// Cancellation is inherently racy. There is no guarantee that the
22+
/// cancellation request will reach the server before the query terminates
23+
/// normally, or that the connection associated with this token is still
24+
/// active.
25+
pub fn cancel_query<T>(&self, tls: T) -> Result<(), Error>
26+
where
27+
T: MakeTlsConnect<Socket>,
28+
{
29+
runtime::Builder::new()
30+
.enable_all()
31+
.basic_scheduler()
32+
.build()
33+
.unwrap() // FIXME don't unwrap
34+
.block_on(self.0.cancel_query(tls))
35+
}
36+
}

postgres/src/client.rs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
2-
Config, CopyInWriter, CopyOutReader, GenericConnection, RowIter, Statement, ToStatement,
3-
Transaction,
2+
CancelToken, Config, CopyInWriter, CopyOutReader, GenericConnection, RowIter, Statement,
3+
ToStatement, Transaction,
44
};
55
use std::ops::{Deref, DerefMut};
66
use tokio::runtime::Runtime;
@@ -446,6 +446,46 @@ impl Client {
446446
Ok(Transaction::new(&mut self.runtime, transaction))
447447
}
448448

449+
/// Constructs a cancellation token that can later be used to request
450+
/// cancellation of a query running on this connection.
451+
///
452+
/// # Examples
453+
///
454+
/// ```no_run
455+
/// use postgres::{Client, NoTls};
456+
/// use postgres::error::SqlState;
457+
/// use std::thread;
458+
/// use std::time::Duration;
459+
///
460+
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
461+
/// let mut client = Client::connect("host=localhost user=postgres", NoTls)?;
462+
///
463+
/// let cancel_token = client.cancel_token();
464+
///
465+
/// thread::spawn(move || {
466+
/// // Abort the query after 5s.
467+
/// thread::sleep(Duration::from_secs(5));
468+
/// cancel_token.cancel_query(NoTls);
469+
/// });
470+
///
471+
/// match client.simple_query("SELECT long_running_query()") {
472+
/// Err(e) if e.code() == Some(&SqlState::QUERY_CANCELED) => {
473+
/// // Handle canceled query.
474+
/// }
475+
/// Err(err) => return Err(err.into()),
476+
/// Ok(rows) => {
477+
/// // ...
478+
/// }
479+
/// }
480+
/// // ...
481+
///
482+
/// # Ok(())
483+
/// # }
484+
/// ```
485+
pub fn cancel_token(&self) -> CancelToken {
486+
CancelToken::new(self.client.cancel_token())
487+
}
488+
449489
/// Determines if the client's connection has already closed.
450490
///
451491
/// If this returns `true`, the client is no longer usable.

0 commit comments

Comments
 (0)