Skip to content

Commit 28d9b9b

Browse files
committed
Merge branch 'release-v0.3.0' into release
2 parents 08b54d8 + 4c6ed73 commit 28d9b9b

File tree

5 files changed

+31
-40
lines changed

5 files changed

+31
-40
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
target/
22
Cargo.lock
33
.cargo/
4+
.idea/
5+
*.iml

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
language: rust
22
rust:
33
- nightly
4-
- beta
5-
- stable
4+
- 1.10.0
65
addons:
76
postgresql: 9.4
87
script:

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[package]
22
name = "postgres-binary-copy"
3-
version = "0.2.1"
3+
version = "0.3.0"
44
authors = ["Steven Fackler <sfackler@gmail.com>"]
55
license = "MIT"
66
description = "Support for binary-format COPY query execution with postgres"
7-
documentation = "https://sfackler.github.io/rust-postgres-binary-copy/doc/v0.2.1/postgres_binary_copy"
7+
documentation = "https://sfackler.github.io/rust-postgres-binary-copy/doc/v0.3.0/postgres_binary_copy"
88
repository = "https://github.com/sfackler/rust-postgres-binary-copy"
99
readme = "README.md"
1010
keywords = ["database", "sql", "postgres", "copy"]
1111

1212
[dependencies]
1313
byteorder = "0.5"
14-
postgres = "0.11"
14+
postgres = "0.12"

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
Support for binary-format `COPY` query execution with
66
[rust-postgres](https://github.com/sfackler/rust-postgres).
77

8-
[Documentation](https://sfackler.github.io/rust-postgres-binary-copy/doc/v0.2.1/postgres_binary_copy)
8+
[Documentation](https://sfackler.github.io/rust-postgres-binary-copy/doc/v0.3.0/postgres_binary_copy)
99

1010
## Example
1111

1212
```rust
1313
extern crate postgres;
1414
extern crate postgres_binary_copy;
1515

16-
use postgres::{Connection, SslMode};
16+
use postgres::{Connection, TlsMode};
1717
use postgres::types::{Type, ToSql};
1818
use postgres_binary_copy::BinaryCopyReader;
1919

2020
fn main() {
2121
let conn = Connection::connect("postgres://postgres@localhost",
22-
SslMode::None).unwrap();
22+
TlsMode::None).unwrap();
2323

2424
conn.execute("CREATE TABLE foo (id INT PRIMARY KEY, bar VARCHAR)", &[])
2525
.unwrap();

src/lib.rs

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
//! extern crate postgres;
77
//! extern crate postgres_binary_copy;
88
//!
9-
//! use postgres::{Connection, SslMode};
9+
//! use postgres::{Connection, TlsMode};
1010
//! use postgres::types::{Type, ToSql};
1111
//! use postgres_binary_copy::BinaryCopyReader;
1212
//!
1313
//! fn main() {
1414
//! let conn = Connection::connect("postgres://postgres@localhost",
15-
//! SslMode::None).unwrap();
15+
//! TlsMode::None).unwrap();
1616
//!
1717
//! conn.execute("CREATE TABLE foo (id INT PRIMARY KEY, bar VARCHAR)", &[])
1818
//! .unwrap();
@@ -27,7 +27,7 @@
2727
//! stmt.copy_in(&[], &mut reader).unwrap();
2828
//! }
2929
//! ```
30-
#![doc(html_root_url="https://sfackler.github.io/rust-postgres-binary-copy/doc/v0.2.1")]
30+
#![doc(html_root_url="https://sfackler.github.io/rust-postgres-binary-copy/doc/v0.3.0")]
3131
#![warn(missing_docs)]
3232
extern crate byteorder;
3333
extern crate postgres;
@@ -164,11 +164,11 @@ impl<'a, I> BinaryCopyReader<'a, I>
164164
let len_pos = self.buf.position();
165165
let _ = self.buf.write_i32::<BigEndian>(0); // space for length
166166
let len = match value.to_sql_checked(&self.types[idx],
167-
&mut self.buf,
167+
self.buf.get_mut(),
168168
&info.session_info()) {
169169
Ok(IsNull::Yes) => -1,
170170
Ok(IsNull::No) => {
171-
let len = self.buf.position() - 4 - len_pos;
171+
let len = self.buf.get_ref().len() as u64 - 4 - len_pos;
172172
if len > i32::max_value() as u64 {
173173
let err: Box<error::Error + Sync + Send> = "value too large to \
174174
transmit"
@@ -206,32 +206,22 @@ impl<'a, I> ReadWithInfo for BinaryCopyReader<'a, I>
206206
}
207207
}
208208

209-
/// A `Read`er passed to `WriteValue::write_value`.
210-
pub struct WriteValueReader<'a>(&'a mut &'a [u8]);
211-
212-
impl<'a> Read for WriteValueReader<'a> {
213-
#[inline]
214-
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
215-
self.0.read(buf)
216-
}
217-
}
218-
219209
/// A trait for types that can receive values from a `BinaryCopyWriter`.
220210
///
221-
/// It is implemented for all `FnMut(Option<&mut WriteValueReader>, &CopyInfo)
211+
/// It is implemented for all `FnMut(Option<&[u8]>, &CopyInfo)
222212
/// -> io::Result<()>` closures.
223213
pub trait WriteValue {
224214
/// Processes a SQL value.
225-
fn write_value(&mut self, r: &mut WriteValueReader, info: &CopyInfo) -> io::Result<()>;
215+
fn write_value(&mut self, r: &[u8], info: &CopyInfo) -> io::Result<()>;
226216

227217
/// Processes a `NULL` SQL value.
228218
fn write_null_value(&mut self, info: &CopyInfo) -> io::Result<()>;
229219
}
230220

231221
impl<F> WriteValue for F
232-
where F: FnMut(Option<&mut WriteValueReader>, &CopyInfo) -> io::Result<()>
222+
where F: FnMut(Option<&[u8]>, &CopyInfo) -> io::Result<()>
233223
{
234-
fn write_value(&mut self, r: &mut WriteValueReader, info: &CopyInfo) -> io::Result<()> {
224+
fn write_value(&mut self, r: &[u8], info: &CopyInfo) -> io::Result<()> {
235225
self(Some(r), info)
236226
}
237227

@@ -386,7 +376,7 @@ impl<W> BinaryCopyWriter<W>
386376
return Ok(nread);
387377
}
388378

389-
try!(self.value_writer.write_value(&mut WriteValueReader(&mut &self.buf[..]), info));
379+
try!(self.value_writer.write_value(&self.buf, info));
390380
self.buf.clear();
391381
self.advance_field_state(remaining);
392382
Ok(nread)
@@ -414,13 +404,13 @@ impl<W> WriteWithInfo for BinaryCopyWriter<W>
414404
#[cfg(test)]
415405
mod test {
416406
use super::*;
417-
use postgres::{Connection, SslMode};
407+
use postgres::{Connection, TlsMode};
418408
use postgres::types::{Type, FromSql, ToSql};
419409
use postgres::stmt::CopyInfo;
420410

421411
#[test]
422412
fn write_basic() {
423-
let conn = Connection::connect("postgres://postgres@localhost", SslMode::None).unwrap();
413+
let conn = Connection::connect("postgres://postgres@localhost", TlsMode::None).unwrap();
424414
conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY, bar VARCHAR)",
425415
&[])
426416
.unwrap();
@@ -448,7 +438,7 @@ mod test {
448438

449439
#[test]
450440
fn write_many_rows() {
451-
let conn = Connection::connect("postgres://postgres@localhost", SslMode::None).unwrap();
441+
let conn = Connection::connect("postgres://postgres@localhost", TlsMode::None).unwrap();
452442
conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY, bar VARCHAR)",
453443
&[])
454444
.unwrap();
@@ -478,7 +468,7 @@ mod test {
478468

479469
#[test]
480470
fn write_big_rows() {
481-
let conn = Connection::connect("postgres://postgres@localhost", SslMode::None).unwrap();
471+
let conn = Connection::connect("postgres://postgres@localhost", TlsMode::None).unwrap();
482472
conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY, bar BYTEA)",
483473
&[])
484474
.unwrap();
@@ -508,7 +498,7 @@ mod test {
508498

509499
#[test]
510500
fn read_basic() {
511-
let conn = Connection::connect("postgres://postgres@localhost", SslMode::None).unwrap();
501+
let conn = Connection::connect("postgres://postgres@localhost", TlsMode::None).unwrap();
512502
conn.execute("CREATE TEMPORARY TABLE foo (id SERIAL PRIMARY KEY, bar INT)",
513503
&[])
514504
.unwrap();
@@ -517,7 +507,7 @@ mod test {
517507
let mut out = vec![];
518508

519509
{
520-
let writer = |r: Option<&mut WriteValueReader>, info: &CopyInfo| {
510+
let writer = |r: Option<&[u8]>, info: &CopyInfo| {
521511
match r {
522512
Some(r) => {
523513
out.push(Option::<i32>::from_sql(&Type::Int4, r, &info.session_info())
@@ -543,7 +533,7 @@ mod test {
543533

544534
#[test]
545535
fn read_many_rows() {
546-
let conn = Connection::connect("postgres://postgres@localhost", SslMode::None).unwrap();
536+
let conn = Connection::connect("postgres://postgres@localhost", TlsMode::None).unwrap();
547537
conn.execute("CREATE TEMPORARY TABLE foo (id INT)", &[]).unwrap();
548538

549539
let mut expected = vec![];
@@ -556,7 +546,7 @@ mod test {
556546
let mut out = vec![];
557547

558548
{
559-
let writer = |r: Option<&mut WriteValueReader>, info: &CopyInfo| {
549+
let writer = |r: Option<&[u8]>, info: &CopyInfo| {
560550
out.push(i32::from_sql(&Type::Int4, r.unwrap(), &info.session_info()).unwrap());
561551
Ok(())
562552
};
@@ -573,7 +563,7 @@ mod test {
573563

574564
#[test]
575565
fn read_big_rows() {
576-
let conn = Connection::connect("postgres://postgres@localhost", SslMode::None).unwrap();
566+
let conn = Connection::connect("postgres://postgres@localhost", TlsMode::None).unwrap();
577567
conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY, bar BYTEA)",
578568
&[])
579569
.unwrap();
@@ -589,7 +579,7 @@ mod test {
589579
let mut out = vec![];
590580

591581
{
592-
let writer = |r: Option<&mut WriteValueReader>, info: &CopyInfo| {
582+
let writer = |r: Option<&[u8]>, info: &CopyInfo| {
593583
out.push(Vec::<u8>::from_sql(&Type::Bytea, r.unwrap(), &info.session_info())
594584
.unwrap());
595585
Ok(())
@@ -608,15 +598,15 @@ mod test {
608598

609599
#[test]
610600
fn read_with_oids() {
611-
let conn = Connection::connect("postgres://postgres@localhost", SslMode::None).unwrap();
601+
let conn = Connection::connect("postgres://postgres@localhost", TlsMode::None).unwrap();
612602
conn.execute("CREATE TEMPORARY TABLE foo (id INT) WITH OIDS", &[]).unwrap();
613603
conn.execute("INSERT INTO foo (id) VALUES (1), (2), (3), (4)", &[]).unwrap();
614604

615605
let mut oids = vec![];
616606
let mut out = vec![];
617607

618608
{
619-
let writer = |r: Option<&mut WriteValueReader>, info: &CopyInfo| {
609+
let writer = |r: Option<&[u8]>, info: &CopyInfo| {
620610
if oids.len() > out.len() {
621611
out.push(i32::from_sql(&Type::Bytea, r.unwrap(), &info.session_info())
622612
.unwrap());

0 commit comments

Comments
 (0)