Skip to content

Commit a2f4b5c

Browse files
committed
Upgrade to new postgres version
1 parent c68b66f commit a2f4b5c

File tree

3 files changed

+37
-41
lines changed

3 files changed

+37
-41
lines changed

Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ repository = "https://github.com/sfackler/rust-postgres-array"
99
documentation = "https://docs.rs/postgres_array/0.9.0/postgres_array"
1010

1111
[dependencies]
12-
fallible-iterator = "0.1"
13-
postgres-shared = "0.4"
14-
postgres-protocol = "0.3"
12+
bytes = "0.5"
13+
fallible-iterator = "0.2"
14+
postgres-types = "0.1"
15+
postgres-protocol = "0.5"
1516

1617
[dev-dependencies]
17-
postgres = "0.15"
18+
postgres = "0.17"

circle.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
version: 2
22
jobs:
33
build:
4-
working_directory: ~/build
54
docker:
6-
- image: jimmycuadra/rust:1.19.0
7-
- image: postgres:9.6
5+
- image: rust:1.40.0
6+
- image: postgres:12
87
environment:
98
POSTGRES_PASSWORD: password
109
steps:
@@ -15,12 +14,12 @@ jobs:
1514
- save_cache:
1615
key: registry-{{ epoch }}
1716
paths:
18-
- ~/.cargo/registry/index
17+
- /usr/local/cargo/registry/index
1918
- restore_cache:
20-
key: dependencies-1.19-{{ checksum "Cargo.lock" }}
19+
key: dependencies-1.40-{{ checksum "Cargo.lock" }}
2120
- run: cargo test
2221
- save_cache:
23-
key: dependencies-1.19-{{ checksum "Cargo.lock" }}
22+
key: dependencies-1.40-{{ checksum "Cargo.lock" }}
2423
paths:
2524
- target
26-
- ~/.cargo/registry/cache
25+
- /usr/local/cargo/registry/cache

src/impls.rs

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
use fallible_iterator::FallibleIterator;
22
use postgres_protocol;
33
use postgres_protocol::types;
4-
use postgres_shared::to_sql_checked;
5-
use postgres_shared::types::{FromSql, IsNull, Kind, ToSql, Type};
4+
use postgres_types::{to_sql_checked, FromSql, IsNull, Kind, ToSql, Type};
65
use std::error::Error;
76

87
use crate::{Array, Dimension};
8+
use postgres_types::private::BytesMut;
99

10-
impl<T> FromSql for Array<T>
10+
impl<'de, T> FromSql<'de> for Array<T>
1111
where
12-
T: FromSql,
12+
T: FromSql<'de>,
1313
{
14-
fn from_sql(ty: &Type, raw: &[u8]) -> Result<Array<T>, Box<dyn Error + Sync + Send>> {
14+
fn from_sql(ty: &Type, raw: &'de [u8]) -> Result<Array<T>, Box<dyn Error + Sync + Send>> {
1515
let element_type = match *ty.kind() {
1616
Kind::Array(ref ty) => ty,
1717
_ => unreachable!(),
@@ -21,15 +21,17 @@ where
2121

2222
let dimensions = array
2323
.dimensions()
24-
.map(|d| Dimension {
25-
len: d.len,
26-
lower_bound: d.lower_bound,
24+
.map(|d| {
25+
Ok(Dimension {
26+
len: d.len,
27+
lower_bound: d.lower_bound,
28+
})
2729
})
2830
.collect()?;
2931

3032
let elements = array
3133
.values()
32-
.and_then(|v| FromSql::from_sql_nullable(element_type, v))
34+
.map(|v| FromSql::from_sql_nullable(element_type, v))
3335
.collect()?;
3436

3537
Ok(Array::from_parts(elements, dimensions))
@@ -47,7 +49,7 @@ impl<T> ToSql for Array<T>
4749
where
4850
T: ToSql,
4951
{
50-
fn to_sql(&self, ty: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
52+
fn to_sql(&self, ty: &Type, w: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
5153
let element_type = match ty.kind() {
5254
&Kind::Array(ref ty) => ty,
5355
_ => unreachable!(),
@@ -61,7 +63,6 @@ where
6163

6264
types::array_to_sql(
6365
dimensions,
64-
true,
6566
element_type.oid(),
6667
elements,
6768
|v, w| match v.to_sql(element_type, w) {
@@ -90,24 +91,25 @@ mod test {
9091
use std::fmt;
9192

9293
use crate::Array;
93-
use postgres::types::{FromSql, ToSql};
94-
use postgres::{Connection, TlsMode};
94+
use postgres::types::{FromSqlOwned, ToSql};
95+
use postgres::{Client, NoTls};
9596

96-
fn test_type<T: PartialEq + FromSql + ToSql, S: fmt::Display>(
97+
fn test_type<T: PartialEq + FromSqlOwned + ToSql + Sync, S: fmt::Display>(
9798
sql_type: &str,
9899
checks: &[(T, S)],
99100
) {
100-
let conn =
101-
Connection::connect("postgres://postgres:password@localhost", TlsMode::None).unwrap();
101+
let mut conn = Client::connect("postgres://postgres:password@localhost", NoTls).unwrap();
102102
for &(ref val, ref repr) in checks.iter() {
103-
let stmt = conn
104-
.prepare(&format!("SELECT {}::{}", *repr, sql_type))
105-
.unwrap();
106-
let result = stmt.query(&[]).unwrap().iter().next().unwrap().get(0);
103+
let result = conn
104+
.query(&*format!("SELECT {}::{}", *repr, sql_type), &[])
105+
.unwrap()[0]
106+
.get(0);
107107
assert!(val == &result);
108108

109-
let stmt = conn.prepare(&format!("SELECT $1::{}", sql_type)).unwrap();
110-
let result = stmt.query(&[val]).unwrap().iter().next().unwrap().get(0);
109+
let result = conn
110+
.query(&*format!("SELECT $1::{}", sql_type), &[val])
111+
.unwrap()[0]
112+
.get(0);
111113
assert!(val == &result);
112114
}
113115
}
@@ -235,13 +237,7 @@ mod test {
235237

236238
#[test]
237239
fn test_empty_array() {
238-
let conn = Connection::connect("postgres://postgres@localhost", TlsMode::None).unwrap();
239-
let stmt = conn.prepare("SELECT '{}'::INT4[]").unwrap();
240-
stmt.query(&[])
241-
.unwrap()
242-
.iter()
243-
.next()
244-
.unwrap()
245-
.get::<_, Array<i32>>(0);
240+
let mut conn = Client::connect("postgres://postgres@localhost", NoTls).unwrap();
241+
conn.query("SELECT '{}'::INT4[]", &[]).unwrap()[0].get::<_, Array<i32>>(0);
246242
}
247243
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy