Upgrade tokio-postgres to 2018 edition
This commit is contained in:
parent
4d16fbb906
commit
b4ce9c38e5
@ -2,6 +2,7 @@
|
||||
name = "tokio-postgres"
|
||||
version = "0.3.0"
|
||||
authors = ["Steven Fackler <sfackler@gmail.com>"]
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
description = "A native PostgreSQL driver using Tokio"
|
||||
repository = "https://github.com/sfackler/rust-postgres"
|
||||
|
@ -1,8 +1,8 @@
|
||||
use std::collections::HashMap;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use proto::ConnectFuture;
|
||||
use {Connect, TlsMode};
|
||||
use crate::proto::ConnectFuture;
|
||||
use crate::{Connect, TlsMode};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Builder {
|
||||
|
@ -32,7 +32,7 @@ pub enum Severity {
|
||||
}
|
||||
|
||||
impl fmt::Display for Severity {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let s = match *self {
|
||||
Severity::Panic => "PANIC",
|
||||
Severity::Fatal => "FATAL",
|
||||
@ -85,7 +85,7 @@ pub struct DbError {
|
||||
}
|
||||
|
||||
impl DbError {
|
||||
pub(crate) fn new(fields: &mut ErrorFields) -> io::Result<DbError> {
|
||||
pub(crate) fn new(fields: &mut ErrorFields<'_>) -> io::Result<DbError> {
|
||||
let mut severity = None;
|
||||
let mut parsed_severity = None;
|
||||
let mut code = None;
|
||||
@ -307,7 +307,7 @@ impl DbError {
|
||||
}
|
||||
|
||||
impl fmt::Display for DbError {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(fmt, "{}: {}", self.severity, self.message)
|
||||
}
|
||||
}
|
||||
@ -348,14 +348,14 @@ enum Kind {
|
||||
|
||||
struct ErrorInner {
|
||||
kind: Kind,
|
||||
cause: Option<Box<error::Error + Sync + Send>>,
|
||||
cause: Option<Box<dyn error::Error + Sync + Send>>,
|
||||
}
|
||||
|
||||
/// An error communicating with the Postgres server.
|
||||
pub struct Error(Box<ErrorInner>);
|
||||
|
||||
impl fmt::Debug for Error {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt.debug_struct("Error")
|
||||
.field("kind", &self.0.kind)
|
||||
.field("cause", &self.0.cause)
|
||||
@ -364,7 +364,7 @@ impl fmt::Debug for Error {
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let s = match self.0.kind {
|
||||
Kind::Io => "error communicating with the server",
|
||||
Kind::UnexpectedMessage => "unexpected message from server",
|
||||
@ -390,14 +390,14 @@ impl fmt::Display for Error {
|
||||
}
|
||||
|
||||
impl error::Error for Error {
|
||||
fn source(&self) -> Option<&(error::Error + 'static)> {
|
||||
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
||||
self.0.cause.as_ref().map(|e| &**e as _)
|
||||
}
|
||||
}
|
||||
|
||||
impl Error {
|
||||
/// Consumes the error, returning its cause.
|
||||
pub fn into_cause(self) -> Option<Box<error::Error + Sync + Send>> {
|
||||
pub fn into_cause(self) -> Option<Box<dyn error::Error + Sync + Send>> {
|
||||
self.0.cause
|
||||
}
|
||||
|
||||
@ -411,7 +411,7 @@ impl Error {
|
||||
.map(|e| e.code())
|
||||
}
|
||||
|
||||
fn new(kind: Kind, cause: Option<Box<error::Error + Sync + Send>>) -> Error {
|
||||
fn new(kind: Kind, cause: Option<Box<dyn error::Error + Sync + Send>>) -> Error {
|
||||
Error(Box::new(ErrorInner { kind, cause }))
|
||||
}
|
||||
|
||||
@ -438,17 +438,17 @@ impl Error {
|
||||
Error::new(Kind::Encode, Some(Box::new(e)))
|
||||
}
|
||||
|
||||
pub(crate) fn to_sql(e: Box<error::Error + Sync + Send>) -> Error {
|
||||
pub(crate) fn to_sql(e: Box<dyn error::Error + Sync + Send>) -> Error {
|
||||
Error::new(Kind::ToSql, Some(e))
|
||||
}
|
||||
|
||||
pub(crate) fn from_sql(e: Box<error::Error + Sync + Send>) -> Error {
|
||||
pub(crate) fn from_sql(e: Box<dyn error::Error + Sync + Send>) -> Error {
|
||||
Error::new(Kind::FromSql, Some(e))
|
||||
}
|
||||
|
||||
pub(crate) fn copy_in_stream<E>(e: E) -> Error
|
||||
where
|
||||
E: Into<Box<error::Error + Sync + Send>>,
|
||||
E: Into<Box<dyn error::Error + Sync + Send>>,
|
||||
{
|
||||
Error::new(Kind::CopyInStream, Some(e.into()))
|
||||
}
|
||||
@ -465,7 +465,7 @@ impl Error {
|
||||
Error::new(Kind::UnsupportedAuthentication, None)
|
||||
}
|
||||
|
||||
pub(crate) fn tls(e: Box<error::Error + Sync + Send>) -> Error {
|
||||
pub(crate) fn tls(e: Box<dyn error::Error + Sync + Send>) -> Error {
|
||||
Error::new(Kind::Tls, Some(e))
|
||||
}
|
||||
|
||||
|
@ -1,34 +1,19 @@
|
||||
extern crate antidote;
|
||||
extern crate bytes;
|
||||
extern crate fallible_iterator;
|
||||
extern crate futures_cpupool;
|
||||
extern crate phf;
|
||||
extern crate postgres_protocol;
|
||||
extern crate tokio_codec;
|
||||
extern crate tokio_io;
|
||||
extern crate void;
|
||||
|
||||
#[macro_use]
|
||||
extern crate futures;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[macro_use]
|
||||
extern crate state_machine_future;
|
||||
#![warn(rust_2018_idioms)]
|
||||
|
||||
use bytes::{Bytes, IntoBuf};
|
||||
use futures::{Async, Future, Poll, Stream};
|
||||
use futures::{try_ready, Async, Future, Poll, Stream};
|
||||
use std::error::Error as StdError;
|
||||
use std::fmt;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
pub use builder::*;
|
||||
pub use error::*;
|
||||
use proto::CancelFuture;
|
||||
use rows::RowIndex;
|
||||
pub use stmt::Column;
|
||||
pub use tls::*;
|
||||
use types::{FromSql, ToSql, Type};
|
||||
pub use crate::builder::*;
|
||||
pub use crate::error::*;
|
||||
use crate::proto::CancelFuture;
|
||||
use crate::rows::RowIndex;
|
||||
pub use crate::stmt::Column;
|
||||
pub use crate::tls::*;
|
||||
use crate::types::{FromSql, ToSql, Type};
|
||||
|
||||
mod builder;
|
||||
pub mod error;
|
||||
@ -67,15 +52,15 @@ impl Client {
|
||||
Prepare(self.0.prepare(next_statement(), query, param_types))
|
||||
}
|
||||
|
||||
pub fn execute(&mut self, statement: &Statement, params: &[&ToSql]) -> Execute {
|
||||
pub fn execute(&mut self, statement: &Statement, params: &[&dyn ToSql]) -> Execute {
|
||||
Execute(self.0.execute(&statement.0, params))
|
||||
}
|
||||
|
||||
pub fn query(&mut self, statement: &Statement, params: &[&ToSql]) -> Query {
|
||||
pub fn query(&mut self, statement: &Statement, params: &[&dyn ToSql]) -> Query {
|
||||
Query(self.0.query(&statement.0, params))
|
||||
}
|
||||
|
||||
pub fn bind(&mut self, statement: &Statement, params: &[&ToSql]) -> Bind {
|
||||
pub fn bind(&mut self, statement: &Statement, params: &[&dyn ToSql]) -> Bind {
|
||||
Bind(self.0.bind(&statement.0, next_portal(), params))
|
||||
}
|
||||
|
||||
@ -83,18 +68,23 @@ impl Client {
|
||||
QueryPortal(self.0.query_portal(&portal.0, max_rows))
|
||||
}
|
||||
|
||||
pub fn copy_in<S>(&mut self, statement: &Statement, params: &[&ToSql], stream: S) -> CopyIn<S>
|
||||
pub fn copy_in<S>(
|
||||
&mut self,
|
||||
statement: &Statement,
|
||||
params: &[&dyn ToSql],
|
||||
stream: S,
|
||||
) -> CopyIn<S>
|
||||
where
|
||||
S: Stream,
|
||||
S::Item: IntoBuf,
|
||||
<S::Item as IntoBuf>::Buf: Send,
|
||||
// FIXME error type?
|
||||
S::Error: Into<Box<StdError + Sync + Send>>,
|
||||
S::Error: Into<Box<dyn StdError + Sync + Send>>,
|
||||
{
|
||||
CopyIn(self.0.copy_in(&statement.0, params, stream))
|
||||
}
|
||||
|
||||
pub fn copy_out(&mut self, statement: &Statement, params: &[&ToSql]) -> CopyOut {
|
||||
pub fn copy_out(&mut self, statement: &Statement, params: &[&dyn ToSql]) -> CopyOut {
|
||||
CopyOut(self.0.copy_out(&statement.0, params))
|
||||
}
|
||||
|
||||
@ -282,14 +272,14 @@ where
|
||||
S: Stream,
|
||||
S::Item: IntoBuf,
|
||||
<S::Item as IntoBuf>::Buf: Send,
|
||||
S::Error: Into<Box<StdError + Sync + Send>>;
|
||||
S::Error: Into<Box<dyn StdError + Sync + Send>>;
|
||||
|
||||
impl<S> Future for CopyIn<S>
|
||||
where
|
||||
S: Stream,
|
||||
S::Item: IntoBuf,
|
||||
<S::Item as IntoBuf>::Buf: Send,
|
||||
S::Error: Into<Box<StdError + Sync + Send>>,
|
||||
S::Error: Into<Box<dyn StdError + Sync + Send>>,
|
||||
{
|
||||
type Item = u64;
|
||||
type Error = Error;
|
||||
|
@ -1,11 +1,12 @@
|
||||
use futures::sync::mpsc;
|
||||
use futures::{Poll, Stream};
|
||||
use postgres_protocol::message::backend::Message;
|
||||
use proto::client::{Client, PendingRequest};
|
||||
use proto::portal::Portal;
|
||||
use proto::statement::Statement;
|
||||
use state_machine_future::RentToOwn;
|
||||
use Error;
|
||||
use state_machine_future::{transition, RentToOwn, StateMachineFuture};
|
||||
|
||||
use crate::proto::client::{Client, PendingRequest};
|
||||
use crate::proto::portal::Portal;
|
||||
use crate::proto::statement::Statement;
|
||||
use crate::Error;
|
||||
|
||||
#[derive(StateMachineFuture)]
|
||||
pub enum Bind {
|
||||
|
@ -1,12 +1,12 @@
|
||||
use futures::{Future, Poll};
|
||||
use futures::{try_ready, Future, Poll};
|
||||
use postgres_protocol::message::frontend;
|
||||
use state_machine_future::RentToOwn;
|
||||
use state_machine_future::{transition, RentToOwn, StateMachineFuture};
|
||||
use tokio_io::io::{self, Flush, WriteAll};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use error::Error;
|
||||
use proto::TlsFuture;
|
||||
use {CancelData, TlsMode};
|
||||
use crate::error::Error;
|
||||
use crate::proto::TlsFuture;
|
||||
use crate::{CancelData, TlsMode};
|
||||
|
||||
#[derive(StateMachineFuture)]
|
||||
pub enum Cancel<S, T>
|
||||
|
@ -9,18 +9,18 @@ use std::collections::HashMap;
|
||||
use std::error::Error as StdError;
|
||||
use std::sync::{Arc, Weak};
|
||||
|
||||
use proto::bind::BindFuture;
|
||||
use proto::connection::{Request, RequestMessages};
|
||||
use proto::copy_in::{CopyInFuture, CopyInReceiver, CopyMessage};
|
||||
use proto::copy_out::CopyOutStream;
|
||||
use proto::execute::ExecuteFuture;
|
||||
use proto::portal::Portal;
|
||||
use proto::prepare::PrepareFuture;
|
||||
use proto::query::QueryStream;
|
||||
use proto::simple_query::SimpleQueryFuture;
|
||||
use proto::statement::Statement;
|
||||
use types::{IsNull, Oid, ToSql, Type};
|
||||
use Error;
|
||||
use crate::proto::bind::BindFuture;
|
||||
use crate::proto::connection::{Request, RequestMessages};
|
||||
use crate::proto::copy_in::{CopyInFuture, CopyInReceiver, CopyMessage};
|
||||
use crate::proto::copy_out::CopyOutStream;
|
||||
use crate::proto::execute::ExecuteFuture;
|
||||
use crate::proto::portal::Portal;
|
||||
use crate::proto::prepare::PrepareFuture;
|
||||
use crate::proto::query::QueryStream;
|
||||
use crate::proto::simple_query::SimpleQueryFuture;
|
||||
use crate::proto::statement::Statement;
|
||||
use crate::types::{IsNull, Oid, ToSql, Type};
|
||||
use crate::Error;
|
||||
|
||||
pub struct PendingRequest(Result<RequestMessages, Error>);
|
||||
|
||||
@ -127,7 +127,7 @@ impl Client {
|
||||
PrepareFuture::new(self.clone(), pending, name)
|
||||
}
|
||||
|
||||
pub fn execute(&self, statement: &Statement, params: &[&ToSql]) -> ExecuteFuture {
|
||||
pub fn execute(&self, statement: &Statement, params: &[&dyn ToSql]) -> ExecuteFuture {
|
||||
let pending = PendingRequest(
|
||||
self.excecute_message(statement, params)
|
||||
.map(RequestMessages::Single),
|
||||
@ -135,7 +135,7 @@ impl Client {
|
||||
ExecuteFuture::new(self.clone(), pending, statement.clone())
|
||||
}
|
||||
|
||||
pub fn query(&self, statement: &Statement, params: &[&ToSql]) -> QueryStream<Statement> {
|
||||
pub fn query(&self, statement: &Statement, params: &[&dyn ToSql]) -> QueryStream<Statement> {
|
||||
let pending = PendingRequest(
|
||||
self.excecute_message(statement, params)
|
||||
.map(RequestMessages::Single),
|
||||
@ -143,7 +143,7 @@ impl Client {
|
||||
QueryStream::new(self.clone(), pending, statement.clone())
|
||||
}
|
||||
|
||||
pub fn bind(&self, statement: &Statement, name: String, params: &[&ToSql]) -> BindFuture {
|
||||
pub fn bind(&self, statement: &Statement, name: String, params: &[&dyn ToSql]) -> BindFuture {
|
||||
let mut buf = self.bind_message(statement, &name, params);
|
||||
if let Ok(ref mut buf) = buf {
|
||||
frontend::sync(buf);
|
||||
@ -161,12 +161,12 @@ impl Client {
|
||||
QueryStream::new(self.clone(), pending, portal.clone())
|
||||
}
|
||||
|
||||
pub fn copy_in<S>(&self, statement: &Statement, params: &[&ToSql], stream: S) -> CopyInFuture<S>
|
||||
pub fn copy_in<S>(&self, statement: &Statement, params: &[&dyn ToSql], stream: S) -> CopyInFuture<S>
|
||||
where
|
||||
S: Stream,
|
||||
S::Item: IntoBuf,
|
||||
<S::Item as IntoBuf>::Buf: Send,
|
||||
S::Error: Into<Box<StdError + Sync + Send>>,
|
||||
S::Error: Into<Box<dyn StdError + Sync + Send>>,
|
||||
{
|
||||
let (mut sender, receiver) = mpsc::channel(0);
|
||||
let pending = PendingRequest(self.excecute_message(statement, params).map(|buf| {
|
||||
@ -182,7 +182,7 @@ impl Client {
|
||||
CopyInFuture::new(self.clone(), pending, statement.clone(), stream, sender)
|
||||
}
|
||||
|
||||
pub fn copy_out(&self, statement: &Statement, params: &[&ToSql]) -> CopyOutStream {
|
||||
pub fn copy_out(&self, statement: &Statement, params: &[&dyn ToSql]) -> CopyOutStream {
|
||||
let pending = PendingRequest(
|
||||
self.excecute_message(statement, params)
|
||||
.map(RequestMessages::Single),
|
||||
@ -213,7 +213,7 @@ impl Client {
|
||||
&self,
|
||||
statement: &Statement,
|
||||
name: &str,
|
||||
params: &[&ToSql],
|
||||
params: &[&dyn ToSql],
|
||||
) -> Result<Vec<u8>, Error> {
|
||||
let mut buf = vec![];
|
||||
let r = frontend::bind(
|
||||
@ -236,7 +236,7 @@ impl Client {
|
||||
}
|
||||
}
|
||||
|
||||
fn excecute_message(&self, statement: &Statement, params: &[&ToSql]) -> Result<Vec<u8>, Error> {
|
||||
fn excecute_message(&self, statement: &Statement, params: &[&dyn ToSql]) -> Result<Vec<u8>, Error> {
|
||||
let mut buf = self.bind_message(statement, "", params)?;
|
||||
frontend::execute("", 0, &mut buf).map_err(Error::parse)?;
|
||||
frontend::sync(&mut buf);
|
||||
|
@ -1,19 +1,19 @@
|
||||
use fallible_iterator::FallibleIterator;
|
||||
use futures::sink;
|
||||
use futures::sync::mpsc;
|
||||
use futures::{Future, Poll, Sink, Stream};
|
||||
use futures::{try_ready, Future, Poll, Sink, Stream};
|
||||
use postgres_protocol::authentication;
|
||||
use postgres_protocol::authentication::sasl::{self, ScramSha256};
|
||||
use postgres_protocol::message::backend::Message;
|
||||
use postgres_protocol::message::frontend;
|
||||
use state_machine_future::RentToOwn;
|
||||
use state_machine_future::{transition, RentToOwn, StateMachineFuture};
|
||||
use std::collections::HashMap;
|
||||
use std::io;
|
||||
use tokio_codec::Framed;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use proto::{Client, Connection, PostgresCodec, TlsFuture};
|
||||
use {CancelData, ChannelBinding, Error, TlsMode};
|
||||
use crate::proto::{Client, Connection, PostgresCodec, TlsFuture};
|
||||
use crate::{CancelData, ChannelBinding, Error, TlsMode};
|
||||
|
||||
#[derive(StateMachineFuture)]
|
||||
pub enum Connect<S, T>
|
||||
@ -180,7 +180,7 @@ where
|
||||
return Err(Error::unsupported_authentication());
|
||||
};
|
||||
|
||||
let mut scram = ScramSha256::new(pass.as_bytes(), channel_binding);
|
||||
let scram = ScramSha256::new(pass.as_bytes(), channel_binding);
|
||||
|
||||
let mut buf = vec![];
|
||||
frontend::sasl_initial_response(mechanism, scram.message(), &mut buf)
|
||||
|
@ -1,5 +1,6 @@
|
||||
use futures::sync::mpsc;
|
||||
use futures::{Async, AsyncSink, Future, Poll, Sink, Stream};
|
||||
use futures::{try_ready, Async, AsyncSink, Future, Poll, Sink, Stream};
|
||||
use log::trace;
|
||||
use postgres_protocol::message::backend::Message;
|
||||
use postgres_protocol::message::frontend;
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
@ -7,10 +8,10 @@ use std::io;
|
||||
use tokio_codec::Framed;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use proto::codec::PostgresCodec;
|
||||
use proto::copy_in::CopyInReceiver;
|
||||
use {AsyncMessage, CancelData, Notification};
|
||||
use {DbError, Error};
|
||||
use crate::proto::codec::PostgresCodec;
|
||||
use crate::proto::copy_in::CopyInReceiver;
|
||||
use crate::{AsyncMessage, CancelData, Notification};
|
||||
use crate::{DbError, Error};
|
||||
|
||||
pub enum RequestMessages {
|
||||
Single(Vec<u8>),
|
||||
|
@ -1,15 +1,15 @@
|
||||
use bytes::{Buf, IntoBuf};
|
||||
use futures::sink;
|
||||
use futures::sync::mpsc;
|
||||
use futures::{Async, AsyncSink, Future, Poll, Sink, Stream};
|
||||
use futures::{try_ready, Async, AsyncSink, Future, Poll, Sink, Stream};
|
||||
use postgres_protocol::message::backend::Message;
|
||||
use postgres_protocol::message::frontend;
|
||||
use state_machine_future::RentToOwn;
|
||||
use state_machine_future::{transition, RentToOwn, StateMachineFuture};
|
||||
use std::error::Error as StdError;
|
||||
|
||||
use proto::client::{Client, PendingRequest};
|
||||
use proto::statement::Statement;
|
||||
use Error;
|
||||
use crate::proto::client::{Client, PendingRequest};
|
||||
use crate::proto::statement::Statement;
|
||||
use crate::Error;
|
||||
|
||||
pub enum CopyMessage {
|
||||
Data(Vec<u8>),
|
||||
@ -66,7 +66,7 @@ where
|
||||
S: Stream,
|
||||
S::Item: IntoBuf,
|
||||
<S::Item as IntoBuf>::Buf: Send,
|
||||
S::Error: Into<Box<StdError + Sync + Send>>,
|
||||
S::Error: Into<Box<dyn StdError + Sync + Send>>,
|
||||
{
|
||||
#[state_machine_future(start, transitions(ReadCopyInResponse))]
|
||||
Start {
|
||||
@ -107,7 +107,7 @@ where
|
||||
S: Stream,
|
||||
S::Item: IntoBuf,
|
||||
<S::Item as IntoBuf>::Buf: Send,
|
||||
S::Error: Into<Box<StdError + Sync + Send>>,
|
||||
S::Error: Into<Box<dyn StdError + Sync + Send>>,
|
||||
{
|
||||
fn poll_start<'a>(state: &'a mut RentToOwn<'a, Start<S>>) -> Poll<AfterStart<S>, Error> {
|
||||
let state = state.take();
|
||||
@ -220,7 +220,7 @@ where
|
||||
S: Stream,
|
||||
S::Item: IntoBuf,
|
||||
<S::Item as IntoBuf>::Buf: Send,
|
||||
S::Error: Into<Box<StdError + Sync + Send>>,
|
||||
S::Error: Into<Box<dyn StdError + Sync + Send>>,
|
||||
{
|
||||
pub fn new(
|
||||
client: Client,
|
||||
|
@ -4,9 +4,9 @@ use futures::{Async, Poll, Stream};
|
||||
use postgres_protocol::message::backend::Message;
|
||||
use std::mem;
|
||||
|
||||
use proto::client::{Client, PendingRequest};
|
||||
use proto::statement::Statement;
|
||||
use Error;
|
||||
use crate::proto::client::{Client, PendingRequest};
|
||||
use crate::proto::statement::Statement;
|
||||
use crate::Error;
|
||||
|
||||
enum State {
|
||||
Start {
|
||||
|
@ -1,11 +1,11 @@
|
||||
use futures::sync::mpsc;
|
||||
use futures::{Poll, Stream};
|
||||
use postgres_protocol::message::backend::Message;
|
||||
use state_machine_future::RentToOwn;
|
||||
use state_machine_future::{transition, RentToOwn, StateMachineFuture};
|
||||
|
||||
use proto::client::{Client, PendingRequest};
|
||||
use proto::statement::Statement;
|
||||
use Error;
|
||||
use crate::proto::client::{Client, PendingRequest};
|
||||
use crate::proto::statement::Statement;
|
||||
use crate::Error;
|
||||
|
||||
#[derive(StateMachineFuture)]
|
||||
pub enum Execute {
|
||||
|
@ -13,7 +13,7 @@ macro_rules! try_ready_closed {
|
||||
match $e {
|
||||
Ok(::futures::Async::Ready(v)) => v,
|
||||
Ok(::futures::Async::NotReady) => return Ok(::futures::Async::NotReady),
|
||||
Err(_) => return Err(::Error::closed()),
|
||||
Err(_) => return Err(crate::Error::closed()),
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -39,20 +39,20 @@ mod typeinfo;
|
||||
mod typeinfo_composite;
|
||||
mod typeinfo_enum;
|
||||
|
||||
pub use proto::bind::BindFuture;
|
||||
pub use proto::cancel::CancelFuture;
|
||||
pub use proto::client::Client;
|
||||
pub use proto::codec::PostgresCodec;
|
||||
pub use proto::connect::ConnectFuture;
|
||||
pub use proto::connection::Connection;
|
||||
pub use proto::copy_in::CopyInFuture;
|
||||
pub use proto::copy_out::CopyOutStream;
|
||||
pub use proto::execute::ExecuteFuture;
|
||||
pub use proto::portal::Portal;
|
||||
pub use proto::prepare::PrepareFuture;
|
||||
pub use proto::query::QueryStream;
|
||||
pub use proto::row::Row;
|
||||
pub use proto::simple_query::SimpleQueryFuture;
|
||||
pub use proto::statement::Statement;
|
||||
pub use proto::tls::TlsFuture;
|
||||
pub use proto::transaction::TransactionFuture;
|
||||
pub use crate::proto::bind::BindFuture;
|
||||
pub use crate::proto::cancel::CancelFuture;
|
||||
pub use crate::proto::client::Client;
|
||||
pub use crate::proto::codec::PostgresCodec;
|
||||
pub use crate::proto::connect::ConnectFuture;
|
||||
pub use crate::proto::connection::Connection;
|
||||
pub use crate::proto::copy_in::CopyInFuture;
|
||||
pub use crate::proto::copy_out::CopyOutStream;
|
||||
pub use crate::proto::execute::ExecuteFuture;
|
||||
pub use crate::proto::portal::Portal;
|
||||
pub use crate::proto::prepare::PrepareFuture;
|
||||
pub use crate::proto::query::QueryStream;
|
||||
pub use crate::proto::row::Row;
|
||||
pub use crate::proto::simple_query::SimpleQueryFuture;
|
||||
pub use crate::proto::statement::Statement;
|
||||
pub use crate::proto::tls::TlsFuture;
|
||||
pub use crate::proto::transaction::TransactionFuture;
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use proto::client::WeakClient;
|
||||
use proto::statement::Statement;
|
||||
use crate::proto::client::WeakClient;
|
||||
use crate::proto::statement::Statement;
|
||||
|
||||
struct Inner {
|
||||
client: WeakClient,
|
||||
|
@ -1,16 +1,16 @@
|
||||
use fallible_iterator::FallibleIterator;
|
||||
use futures::sync::mpsc;
|
||||
use futures::{Future, Poll, Stream};
|
||||
use futures::{try_ready, Future, Poll, Stream};
|
||||
use postgres_protocol::message::backend::Message;
|
||||
use state_machine_future::RentToOwn;
|
||||
use state_machine_future::{transition, RentToOwn, StateMachineFuture};
|
||||
use std::mem;
|
||||
use std::vec;
|
||||
|
||||
use proto::client::{Client, PendingRequest};
|
||||
use proto::statement::Statement;
|
||||
use proto::typeinfo::TypeinfoFuture;
|
||||
use types::{Oid, Type};
|
||||
use {Column, Error};
|
||||
use crate::proto::client::{Client, PendingRequest};
|
||||
use crate::proto::statement::Statement;
|
||||
use crate::proto::typeinfo::TypeinfoFuture;
|
||||
use crate::types::{Oid, Type};
|
||||
use crate::{Column, Error};
|
||||
|
||||
#[derive(StateMachineFuture)]
|
||||
pub enum Prepare {
|
||||
|
@ -3,11 +3,11 @@ use futures::{Async, Poll, Stream};
|
||||
use postgres_protocol::message::backend::Message;
|
||||
use std::mem;
|
||||
|
||||
use proto::client::{Client, PendingRequest};
|
||||
use proto::portal::Portal;
|
||||
use proto::row::Row;
|
||||
use proto::statement::Statement;
|
||||
use Error;
|
||||
use crate::proto::client::{Client, PendingRequest};
|
||||
use crate::proto::portal::Portal;
|
||||
use crate::proto::row::Row;
|
||||
use crate::proto::statement::Statement;
|
||||
use crate::Error;
|
||||
|
||||
pub trait StatementHolder {
|
||||
fn statement(&self) -> &Statement;
|
||||
|
@ -1,10 +1,10 @@
|
||||
use postgres_protocol::message::backend::DataRowBody;
|
||||
use std::fmt;
|
||||
|
||||
use proto::statement::Statement;
|
||||
use rows::{RowData, RowIndex};
|
||||
use types::{FromSql, WrongType};
|
||||
use {Column, Error};
|
||||
use crate::proto::statement::Statement;
|
||||
use crate::rows::{RowData, RowIndex};
|
||||
use crate::types::{FromSql, WrongType};
|
||||
use crate::{Column, Error};
|
||||
|
||||
pub struct Row {
|
||||
statement: Statement,
|
||||
|
@ -1,10 +1,10 @@
|
||||
use futures::sync::mpsc;
|
||||
use futures::{Poll, Stream};
|
||||
use postgres_protocol::message::backend::Message;
|
||||
use state_machine_future::RentToOwn;
|
||||
use state_machine_future::{transition, RentToOwn, StateMachineFuture};
|
||||
|
||||
use proto::client::{Client, PendingRequest};
|
||||
use Error;
|
||||
use crate::proto::client::{Client, PendingRequest};
|
||||
use crate::Error;
|
||||
|
||||
#[derive(StateMachineFuture)]
|
||||
pub enum SimpleQuery {
|
||||
|
@ -1,8 +1,8 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use proto::client::WeakClient;
|
||||
use types::Type;
|
||||
use Column;
|
||||
use crate::proto::client::WeakClient;
|
||||
use crate::types::Type;
|
||||
use crate::Column;
|
||||
|
||||
pub struct StatementInner {
|
||||
client: WeakClient,
|
||||
|
@ -1,10 +1,10 @@
|
||||
use futures::{Future, Poll};
|
||||
use futures::{try_ready, Future, Poll};
|
||||
use postgres_protocol::message::frontend;
|
||||
use state_machine_future::RentToOwn;
|
||||
use state_machine_future::{transition, RentToOwn, StateMachineFuture};
|
||||
use tokio_io::io::{self, ReadExact, WriteAll};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use {ChannelBinding, Error, TlsMode};
|
||||
use crate::{ChannelBinding, Error, TlsMode};
|
||||
|
||||
#[derive(StateMachineFuture)]
|
||||
pub enum Tls<S, T>
|
||||
|
@ -1,9 +1,9 @@
|
||||
use futures::{Async, Future, Poll};
|
||||
use proto::client::Client;
|
||||
use proto::simple_query::SimpleQueryFuture;
|
||||
use state_machine_future::RentToOwn;
|
||||
use crate::proto::client::Client;
|
||||
use crate::proto::simple_query::SimpleQueryFuture;
|
||||
use futures::{try_ready, Async, Future, Poll};
|
||||
use state_machine_future::{transition, RentToOwn, StateMachineFuture};
|
||||
|
||||
use Error;
|
||||
use crate::Error;
|
||||
|
||||
#[derive(StateMachineFuture)]
|
||||
pub enum Transaction<F, T, E>
|
||||
|
@ -1,16 +1,16 @@
|
||||
use futures::stream::{self, Stream};
|
||||
use futures::{Async, Future, Poll};
|
||||
use state_machine_future::RentToOwn;
|
||||
use futures::{try_ready, Async, Future, Poll};
|
||||
use state_machine_future::{transition, RentToOwn, StateMachineFuture};
|
||||
|
||||
use error::{Error, SqlState};
|
||||
use next_statement;
|
||||
use proto::client::Client;
|
||||
use proto::prepare::PrepareFuture;
|
||||
use proto::query::QueryStream;
|
||||
use proto::statement::Statement;
|
||||
use proto::typeinfo_composite::TypeinfoCompositeFuture;
|
||||
use proto::typeinfo_enum::TypeinfoEnumFuture;
|
||||
use types::{Kind, Oid, Type};
|
||||
use crate::error::{Error, SqlState};
|
||||
use crate::next_statement;
|
||||
use crate::proto::client::Client;
|
||||
use crate::proto::prepare::PrepareFuture;
|
||||
use crate::proto::query::QueryStream;
|
||||
use crate::proto::statement::Statement;
|
||||
use crate::proto::typeinfo_composite::TypeinfoCompositeFuture;
|
||||
use crate::proto::typeinfo_enum::TypeinfoEnumFuture;
|
||||
use crate::types::{Kind, Oid, Type};
|
||||
|
||||
const TYPEINFO_QUERY: &'static str = "
|
||||
SELECT t.typname, t.typtype, t.typelem, r.rngsubtype, t.typbasetype, n.nspname, t.typrelid
|
||||
@ -30,10 +30,7 @@ WHERE t.oid = $1
|
||||
|
||||
#[derive(StateMachineFuture)]
|
||||
pub enum Typeinfo {
|
||||
#[state_machine_future(
|
||||
start,
|
||||
transitions(PreparingTypeinfo, QueryingTypeinfo, Finished)
|
||||
)]
|
||||
#[state_machine_future(start, transitions(PreparingTypeinfo, QueryingTypeinfo, Finished))]
|
||||
Start { oid: Oid, client: Client },
|
||||
#[state_machine_future(transitions(PreparingTypeinfoFallback, QueryingTypeinfo))]
|
||||
PreparingTypeinfo {
|
||||
@ -136,7 +133,7 @@ impl PollTypeinfo for Typeinfo {
|
||||
Ok(Async::Ready(statement)) => statement,
|
||||
Ok(Async::NotReady) => return Ok(Async::NotReady),
|
||||
Err(ref e) if e.code() == Some(&SqlState::UNDEFINED_TABLE) => {
|
||||
let mut state = state.take();
|
||||
let state = state.take();
|
||||
|
||||
transition!(PreparingTypeinfoFallback {
|
||||
future: Box::new(state.client.prepare(
|
||||
|
@ -1,17 +1,17 @@
|
||||
use futures::stream::{self, Stream};
|
||||
use futures::{Future, Poll};
|
||||
use state_machine_future::RentToOwn;
|
||||
use futures::{try_ready, Future, Poll};
|
||||
use state_machine_future::{transition, RentToOwn, StateMachineFuture};
|
||||
use std::mem;
|
||||
use std::vec;
|
||||
|
||||
use error::Error;
|
||||
use next_statement;
|
||||
use proto::client::Client;
|
||||
use proto::prepare::PrepareFuture;
|
||||
use proto::query::QueryStream;
|
||||
use proto::statement::Statement;
|
||||
use proto::typeinfo::TypeinfoFuture;
|
||||
use types::{Field, Oid};
|
||||
use crate::error::Error;
|
||||
use crate::next_statement;
|
||||
use crate::proto::client::Client;
|
||||
use crate::proto::prepare::PrepareFuture;
|
||||
use crate::proto::query::QueryStream;
|
||||
use crate::proto::statement::Statement;
|
||||
use crate::proto::typeinfo::TypeinfoFuture;
|
||||
use crate::types::{Field, Oid};
|
||||
|
||||
const TYPEINFO_COMPOSITE_QUERY: &'static str = "
|
||||
SELECT attname, atttypid
|
||||
@ -99,7 +99,8 @@ impl PollTypeinfoComposite for TypeinfoComposite {
|
||||
let name = row.try_get(0)?.ok_or_else(Error::unexpected_message)?;
|
||||
let oid = row.try_get(1)?.ok_or_else(Error::unexpected_message)?;
|
||||
Ok((name, oid))
|
||||
}).collect::<Result<Vec<(String, Oid)>, Error>>()?;
|
||||
})
|
||||
.collect::<Result<Vec<(String, Oid)>, Error>>()?;
|
||||
|
||||
let mut remaining_fields = fields.into_iter();
|
||||
match remaining_fields.next() {
|
||||
|
@ -1,14 +1,14 @@
|
||||
use futures::stream::{self, Stream};
|
||||
use futures::{Async, Future, Poll};
|
||||
use state_machine_future::RentToOwn;
|
||||
use futures::{try_ready, Async, Future, Poll};
|
||||
use state_machine_future::{transition, RentToOwn, StateMachineFuture};
|
||||
|
||||
use error::{Error, SqlState};
|
||||
use next_statement;
|
||||
use proto::client::Client;
|
||||
use proto::prepare::PrepareFuture;
|
||||
use proto::query::QueryStream;
|
||||
use proto::statement::Statement;
|
||||
use types::Oid;
|
||||
use crate::error::{Error, SqlState};
|
||||
use crate::next_statement;
|
||||
use crate::proto::client::Client;
|
||||
use crate::proto::prepare::PrepareFuture;
|
||||
use crate::proto::query::QueryStream;
|
||||
use crate::proto::statement::Statement;
|
||||
use crate::types::Oid;
|
||||
|
||||
const TYPEINFO_ENUM_QUERY: &'static str = "
|
||||
SELECT enumlabel
|
||||
@ -27,10 +27,7 @@ ORDER BY oid
|
||||
|
||||
#[derive(StateMachineFuture)]
|
||||
pub enum TypeinfoEnum {
|
||||
#[state_machine_future(
|
||||
start,
|
||||
transitions(PreparingTypeinfoEnum, QueryingEnumVariants)
|
||||
)]
|
||||
#[state_machine_future(start, transitions(PreparingTypeinfoEnum, QueryingEnumVariants))]
|
||||
Start { oid: Oid, client: Client },
|
||||
#[state_machine_future(transitions(PreparingTypeinfoEnumFallback, QueryingEnumVariants))]
|
||||
PreparingTypeinfoEnum {
|
||||
@ -83,7 +80,7 @@ impl PollTypeinfoEnum for TypeinfoEnum {
|
||||
Ok(Async::Ready(statement)) => statement,
|
||||
Ok(Async::NotReady) => return Ok(Async::NotReady),
|
||||
Err(ref e) if e.code() == Some(&SqlState::UNDEFINED_COLUMN) => {
|
||||
let mut state = state.take();
|
||||
let state = state.take();
|
||||
|
||||
transition!(PreparingTypeinfoEnumFallback {
|
||||
future: Box::new(state.client.prepare(
|
||||
|
@ -3,11 +3,11 @@ use postgres_protocol::message::backend::DataRowBody;
|
||||
use std::io;
|
||||
use std::ops::Range;
|
||||
|
||||
use rows::sealed::Sealed;
|
||||
use stmt::Column;
|
||||
use crate::rows::sealed::Sealed;
|
||||
use crate::stmt::Column;
|
||||
|
||||
mod sealed {
|
||||
use stmt::Column;
|
||||
use crate::stmt::Column;
|
||||
|
||||
pub trait Sealed {
|
||||
fn __idx(&self, stmt: &[Column]) -> Option<usize>;
|
||||
|
@ -1,4 +1,4 @@
|
||||
use types::Type;
|
||||
use crate::types::Type;
|
||||
|
||||
/// Information about a column of a Postgres query.
|
||||
#[derive(Debug)]
|
||||
|
@ -1,6 +1,6 @@
|
||||
use bytes::{Buf, BufMut};
|
||||
use futures::future::{self, FutureResult};
|
||||
use futures::{Async, Future, Poll};
|
||||
use futures::{try_ready, Async, Future, Poll};
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::io::{self, Read, Write};
|
||||
@ -27,7 +27,7 @@ impl ChannelBinding {
|
||||
|
||||
pub trait TlsMode<S> {
|
||||
type Stream: AsyncRead + AsyncWrite;
|
||||
type Error: Into<Box<Error + Sync + Send>>;
|
||||
type Error: Into<Box<dyn Error + Sync + Send>>;
|
||||
type Future: Future<Item = (Self::Stream, ChannelBinding), Error = Self::Error>;
|
||||
|
||||
fn request_tls(&self) -> bool;
|
||||
@ -37,7 +37,7 @@ pub trait TlsMode<S> {
|
||||
|
||||
pub trait TlsConnect<S> {
|
||||
type Stream: AsyncRead + AsyncWrite;
|
||||
type Error: Into<Box<Error + Sync + Send>>;
|
||||
type Error: Into<Box<dyn Error + Sync + Send>>;
|
||||
type Future: Future<Item = (Self::Stream, ChannelBinding), Error = Self::Error>;
|
||||
|
||||
fn connect(self, stream: S) -> Self::Future;
|
||||
@ -212,7 +212,7 @@ where
|
||||
T: TlsConnect<S>,
|
||||
{
|
||||
type Stream = T::Stream;
|
||||
type Error = Box<Error + Sync + Send>;
|
||||
type Error = Box<dyn Error + Sync + Send>;
|
||||
type Future = RequireTlsFuture<T::Future>;
|
||||
|
||||
fn request_tls(&self) -> bool {
|
||||
@ -234,7 +234,7 @@ where
|
||||
pub struct TlsUnsupportedError(());
|
||||
|
||||
impl fmt::Display for TlsUnsupportedError {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt.write_str("TLS was required but not supported by the server")
|
||||
}
|
||||
}
|
||||
@ -242,18 +242,18 @@ impl fmt::Display for TlsUnsupportedError {
|
||||
impl Error for TlsUnsupportedError {}
|
||||
|
||||
pub struct RequireTlsFuture<T> {
|
||||
f: Option<Result<T, Box<Error + Sync + Send>>>,
|
||||
f: Option<Result<T, Box<dyn Error + Sync + Send>>>,
|
||||
}
|
||||
|
||||
impl<T> Future for RequireTlsFuture<T>
|
||||
where
|
||||
T: Future,
|
||||
T::Error: Into<Box<Error + Sync + Send>>,
|
||||
T::Error: Into<Box<dyn Error + Sync + Send>>,
|
||||
{
|
||||
type Item = T::Item;
|
||||
type Error = Box<Error + Sync + Send>;
|
||||
type Error = Box<dyn Error + Sync + Send>;
|
||||
|
||||
fn poll(&mut self) -> Poll<T::Item, Box<Error + Sync + Send>> {
|
||||
fn poll(&mut self) -> Poll<T::Item, Box<dyn Error + Sync + Send>> {
|
||||
match self.f.take().expect("future polled after completion") {
|
||||
Ok(mut f) => match f.poll().map_err(Into::into)? {
|
||||
Async::Ready(r) => Ok(Async::Ready(r)),
|
||||
|
@ -1,6 +1,4 @@
|
||||
extern crate bit_vec;
|
||||
|
||||
use self::bit_vec::BitVec;
|
||||
use bit_vec::BitVec;
|
||||
use postgres_protocol::types;
|
||||
use std::error::Error;
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
extern crate chrono;
|
||||
|
||||
use self::chrono::{
|
||||
use chrono::{
|
||||
DateTime, Duration, FixedOffset, Local, NaiveDate, NaiveDateTime, NaiveTime, Utc,
|
||||
};
|
||||
use postgres_protocol::types;
|
||||
|
@ -1,6 +1,4 @@
|
||||
extern crate eui48;
|
||||
|
||||
use self::eui48::MacAddress;
|
||||
use eui48::MacAddress;
|
||||
use postgres_protocol::types;
|
||||
use std::error::Error;
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
extern crate geo;
|
||||
|
||||
use self::geo::{Coordinate, LineString, Point, Rect};
|
||||
use geo::{Coordinate, LineString, Point, Rect};
|
||||
use fallible_iterator::FallibleIterator;
|
||||
use postgres_protocol::types;
|
||||
use std::error::Error;
|
||||
|
@ -10,12 +10,12 @@ use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
|
||||
use types::type_gen::{Inner, Other};
|
||||
use crate::types::type_gen::{Inner, Other};
|
||||
|
||||
#[doc(inline)]
|
||||
pub use postgres_protocol::Oid;
|
||||
|
||||
pub use types::special::{Date, Timestamp};
|
||||
pub use crate::types::special::{Date, Timestamp};
|
||||
|
||||
// Number of seconds from 1970-01-01 to 2000-01-01
|
||||
const TIME_SEC_CONVERSION: u64 = 946684800;
|
||||
@ -46,7 +46,7 @@ macro_rules! to_sql_checked {
|
||||
ty: &$crate::types::Type,
|
||||
out: &mut ::std::vec::Vec<u8>)
|
||||
-> ::std::result::Result<$crate::types::IsNull,
|
||||
Box<::std::error::Error +
|
||||
Box<dyn ::std::error::Error +
|
||||
::std::marker::Sync +
|
||||
::std::marker::Send>> {
|
||||
$crate::types::__to_sql_checked(self, ty, out)
|
||||
@ -61,7 +61,7 @@ pub fn __to_sql_checked<T>(
|
||||
v: &T,
|
||||
ty: &Type,
|
||||
out: &mut Vec<u8>,
|
||||
) -> Result<IsNull, Box<Error + Sync + Send>>
|
||||
) -> Result<IsNull, Box<dyn Error + Sync + Send>>
|
||||
where
|
||||
T: ToSql,
|
||||
{
|
||||
@ -95,7 +95,7 @@ pub use self::serde_json::Json;
|
||||
pub struct Type(Inner);
|
||||
|
||||
impl fmt::Display for Type {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self.schema() {
|
||||
"public" | "pg_catalog" => {}
|
||||
schema => write!(fmt, "{}.", schema)?,
|
||||
@ -202,7 +202,7 @@ impl Field {
|
||||
pub struct WasNull;
|
||||
|
||||
impl fmt::Display for WasNull {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt.write_str(self.description())
|
||||
}
|
||||
}
|
||||
@ -219,7 +219,7 @@ impl Error for WasNull {
|
||||
pub struct WrongType(Type);
|
||||
|
||||
impl fmt::Display for WrongType {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
fmt,
|
||||
"cannot convert to or from a Postgres value of type `{}`",
|
||||
@ -301,7 +301,7 @@ pub trait FromSql<'a>: Sized {
|
||||
///
|
||||
/// The caller of this method is responsible for ensuring that this type
|
||||
/// is compatible with the Postgres `Type`.
|
||||
fn from_sql(ty: &Type, raw: &'a [u8]) -> Result<Self, Box<Error + Sync + Send>>;
|
||||
fn from_sql(ty: &Type, raw: &'a [u8]) -> Result<Self, Box<dyn Error + Sync + Send>>;
|
||||
|
||||
/// Creates a new value of this type from a `NULL` SQL value.
|
||||
///
|
||||
@ -311,7 +311,7 @@ pub trait FromSql<'a>: Sized {
|
||||
/// The default implementation returns
|
||||
/// `Err(Box::new(WasNull))`.
|
||||
#[allow(unused_variables)]
|
||||
fn from_sql_null(ty: &Type) -> Result<Self, Box<Error + Sync + Send>> {
|
||||
fn from_sql_null(ty: &Type) -> Result<Self, Box<dyn Error + Sync + Send>> {
|
||||
Err(Box::new(WasNull))
|
||||
}
|
||||
|
||||
@ -320,7 +320,7 @@ pub trait FromSql<'a>: Sized {
|
||||
fn from_sql_nullable(
|
||||
ty: &Type,
|
||||
raw: Option<&'a [u8]>,
|
||||
) -> Result<Self, Box<Error + Sync + Send>> {
|
||||
) -> Result<Self, Box<dyn Error + Sync + Send>> {
|
||||
match raw {
|
||||
Some(raw) => Self::from_sql(ty, raw),
|
||||
None => Self::from_sql_null(ty),
|
||||
@ -340,11 +340,11 @@ pub trait FromSqlOwned: for<'a> FromSql<'a> {}
|
||||
impl<T> FromSqlOwned for T where T: for<'a> FromSql<'a> {}
|
||||
|
||||
impl<'a, T: FromSql<'a>> FromSql<'a> for Option<T> {
|
||||
fn from_sql(ty: &Type, raw: &'a [u8]) -> Result<Option<T>, Box<Error + Sync + Send>> {
|
||||
fn from_sql(ty: &Type, raw: &'a [u8]) -> Result<Option<T>, Box<dyn Error + Sync + Send>> {
|
||||
<T as FromSql>::from_sql(ty, raw).map(Some)
|
||||
}
|
||||
|
||||
fn from_sql_null(_: &Type) -> Result<Option<T>, Box<Error + Sync + Send>> {
|
||||
fn from_sql_null(_: &Type) -> Result<Option<T>, Box<dyn Error + Sync + Send>> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
@ -354,7 +354,7 @@ impl<'a, T: FromSql<'a>> FromSql<'a> for Option<T> {
|
||||
}
|
||||
|
||||
impl<'a, T: FromSql<'a>> FromSql<'a> for Vec<T> {
|
||||
fn from_sql(ty: &Type, raw: &'a [u8]) -> Result<Vec<T>, Box<Error + Sync + Send>> {
|
||||
fn from_sql(ty: &Type, raw: &'a [u8]) -> Result<Vec<T>, Box<dyn Error + Sync + Send>> {
|
||||
let member_type = match *ty.kind() {
|
||||
Kind::Array(ref member) => member,
|
||||
_ => panic!("expected array type"),
|
||||
@ -380,7 +380,7 @@ impl<'a, T: FromSql<'a>> FromSql<'a> for Vec<T> {
|
||||
}
|
||||
|
||||
impl<'a> FromSql<'a> for Vec<u8> {
|
||||
fn from_sql(_: &Type, raw: &'a [u8]) -> Result<Vec<u8>, Box<Error + Sync + Send>> {
|
||||
fn from_sql(_: &Type, raw: &'a [u8]) -> Result<Vec<u8>, Box<dyn Error + Sync + Send>> {
|
||||
Ok(types::bytea_from_sql(raw).to_owned())
|
||||
}
|
||||
|
||||
@ -388,7 +388,7 @@ impl<'a> FromSql<'a> for Vec<u8> {
|
||||
}
|
||||
|
||||
impl<'a> FromSql<'a> for &'a [u8] {
|
||||
fn from_sql(_: &Type, raw: &'a [u8]) -> Result<&'a [u8], Box<Error + Sync + Send>> {
|
||||
fn from_sql(_: &Type, raw: &'a [u8]) -> Result<&'a [u8], Box<dyn Error + Sync + Send>> {
|
||||
Ok(types::bytea_from_sql(raw))
|
||||
}
|
||||
|
||||
@ -396,7 +396,7 @@ impl<'a> FromSql<'a> for &'a [u8] {
|
||||
}
|
||||
|
||||
impl<'a> FromSql<'a> for String {
|
||||
fn from_sql(_: &Type, raw: &'a [u8]) -> Result<String, Box<Error + Sync + Send>> {
|
||||
fn from_sql(_: &Type, raw: &'a [u8]) -> Result<String, Box<dyn Error + Sync + Send>> {
|
||||
types::text_from_sql(raw).map(|b| b.to_owned())
|
||||
}
|
||||
|
||||
@ -406,7 +406,7 @@ impl<'a> FromSql<'a> for String {
|
||||
}
|
||||
|
||||
impl<'a> FromSql<'a> for &'a str {
|
||||
fn from_sql(_: &Type, raw: &'a [u8]) -> Result<&'a str, Box<Error + Sync + Send>> {
|
||||
fn from_sql(_: &Type, raw: &'a [u8]) -> Result<&'a str, Box<dyn Error + Sync + Send>> {
|
||||
types::text_from_sql(raw)
|
||||
}
|
||||
|
||||
@ -422,7 +422,7 @@ impl<'a> FromSql<'a> for &'a str {
|
||||
macro_rules! simple_from {
|
||||
($t:ty, $f:ident, $($expected:ident),+) => {
|
||||
impl<'a> FromSql<'a> for $t {
|
||||
fn from_sql(_: &Type, raw: &'a [u8]) -> Result<$t, Box<Error + Sync + Send>> {
|
||||
fn from_sql(_: &Type, raw: &'a [u8]) -> Result<$t, Box<dyn Error + Sync + Send>> {
|
||||
types::$f(raw)
|
||||
}
|
||||
|
||||
@ -444,7 +444,7 @@ impl<'a> FromSql<'a> for HashMap<String, Option<String>> {
|
||||
fn from_sql(
|
||||
_: &Type,
|
||||
raw: &'a [u8],
|
||||
) -> Result<HashMap<String, Option<String>>, Box<Error + Sync + Send>> {
|
||||
) -> Result<HashMap<String, Option<String>>, Box<dyn Error + Sync + Send>> {
|
||||
types::hstore_from_sql(raw)?
|
||||
.map(|(k, v)| (k.to_owned(), v.map(str::to_owned)))
|
||||
.collect()
|
||||
@ -456,7 +456,7 @@ impl<'a> FromSql<'a> for HashMap<String, Option<String>> {
|
||||
}
|
||||
|
||||
impl<'a> FromSql<'a> for SystemTime {
|
||||
fn from_sql(_: &Type, raw: &'a [u8]) -> Result<SystemTime, Box<Error + Sync + Send>> {
|
||||
fn from_sql(_: &Type, raw: &'a [u8]) -> Result<SystemTime, Box<dyn Error + Sync + Send>> {
|
||||
let time = types::timestamp_from_sql(raw)?;
|
||||
let epoch = UNIX_EPOCH + Duration::from_secs(TIME_SEC_CONVERSION);
|
||||
|
||||
@ -550,7 +550,7 @@ pub trait ToSql: fmt::Debug {
|
||||
/// The return value indicates if this value should be represented as
|
||||
/// `NULL`. If this is the case, implementations **must not** write
|
||||
/// anything to `out`.
|
||||
fn to_sql(&self, ty: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>>
|
||||
fn to_sql(&self, ty: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>>
|
||||
where
|
||||
Self: Sized;
|
||||
|
||||
@ -568,14 +568,14 @@ pub trait ToSql: fmt::Debug {
|
||||
&self,
|
||||
ty: &Type,
|
||||
out: &mut Vec<u8>,
|
||||
) -> Result<IsNull, Box<Error + Sync + Send>>;
|
||||
) -> Result<IsNull, Box<dyn Error + Sync + Send>>;
|
||||
}
|
||||
|
||||
impl<'a, T> ToSql for &'a T
|
||||
where
|
||||
T: ToSql,
|
||||
{
|
||||
fn to_sql(&self, ty: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
|
||||
fn to_sql(&self, ty: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
|
||||
(*self).to_sql(ty, out)
|
||||
}
|
||||
|
||||
@ -587,7 +587,7 @@ where
|
||||
}
|
||||
|
||||
impl<T: ToSql> ToSql for Option<T> {
|
||||
fn to_sql(&self, ty: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
|
||||
fn to_sql(&self, ty: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
|
||||
match *self {
|
||||
Some(ref val) => val.to_sql(ty, out),
|
||||
None => Ok(IsNull::Yes),
|
||||
@ -602,7 +602,7 @@ impl<T: ToSql> ToSql for Option<T> {
|
||||
}
|
||||
|
||||
impl<'a, T: ToSql> ToSql for &'a [T] {
|
||||
fn to_sql(&self, ty: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
|
||||
fn to_sql(&self, ty: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
|
||||
let member_type = match *ty.kind() {
|
||||
Kind::Array(ref member) => member,
|
||||
_ => panic!("expected array type"),
|
||||
@ -637,7 +637,7 @@ impl<'a, T: ToSql> ToSql for &'a [T] {
|
||||
}
|
||||
|
||||
impl<'a> ToSql for &'a [u8] {
|
||||
fn to_sql(&self, _: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
|
||||
fn to_sql(&self, _: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
|
||||
types::bytea_to_sql(*self, w);
|
||||
Ok(IsNull::No)
|
||||
}
|
||||
@ -648,7 +648,7 @@ impl<'a> ToSql for &'a [u8] {
|
||||
}
|
||||
|
||||
impl<T: ToSql> ToSql for Vec<T> {
|
||||
fn to_sql(&self, ty: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
|
||||
fn to_sql(&self, ty: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
|
||||
<&[T] as ToSql>::to_sql(&&**self, ty, w)
|
||||
}
|
||||
|
||||
@ -660,7 +660,7 @@ impl<T: ToSql> ToSql for Vec<T> {
|
||||
}
|
||||
|
||||
impl ToSql for Vec<u8> {
|
||||
fn to_sql(&self, ty: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
|
||||
fn to_sql(&self, ty: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
|
||||
<&[u8] as ToSql>::to_sql(&&**self, ty, w)
|
||||
}
|
||||
|
||||
@ -672,7 +672,7 @@ impl ToSql for Vec<u8> {
|
||||
}
|
||||
|
||||
impl<'a> ToSql for &'a str {
|
||||
fn to_sql(&self, _: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
|
||||
fn to_sql(&self, _: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
|
||||
types::text_to_sql(*self, w);
|
||||
Ok(IsNull::No)
|
||||
}
|
||||
@ -689,7 +689,7 @@ impl<'a> ToSql for &'a str {
|
||||
}
|
||||
|
||||
impl<'a> ToSql for Cow<'a, str> {
|
||||
fn to_sql(&self, ty: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
|
||||
fn to_sql(&self, ty: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
|
||||
<&str as ToSql>::to_sql(&&self.as_ref(), ty, w)
|
||||
}
|
||||
|
||||
@ -701,7 +701,7 @@ impl<'a> ToSql for Cow<'a, str> {
|
||||
}
|
||||
|
||||
impl ToSql for String {
|
||||
fn to_sql(&self, ty: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
|
||||
fn to_sql(&self, ty: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
|
||||
<&str as ToSql>::to_sql(&&**self, ty, w)
|
||||
}
|
||||
|
||||
@ -718,7 +718,7 @@ macro_rules! simple_to {
|
||||
fn to_sql(&self,
|
||||
_: &Type,
|
||||
w: &mut Vec<u8>)
|
||||
-> Result<IsNull, Box<Error + Sync + Send>> {
|
||||
-> Result<IsNull, Box<dyn Error + Sync + Send>> {
|
||||
types::$f(*self, w);
|
||||
Ok(IsNull::No)
|
||||
}
|
||||
@ -740,7 +740,7 @@ simple_to!(f32, float4_to_sql, FLOAT4);
|
||||
simple_to!(f64, float8_to_sql, FLOAT8);
|
||||
|
||||
impl ToSql for HashMap<String, Option<String>> {
|
||||
fn to_sql(&self, _: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
|
||||
fn to_sql(&self, _: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
|
||||
types::hstore_to_sql(
|
||||
self.iter().map(|(k, v)| (&**k, v.as_ref().map(|v| &**v))),
|
||||
w,
|
||||
@ -756,7 +756,7 @@ impl ToSql for HashMap<String, Option<String>> {
|
||||
}
|
||||
|
||||
impl ToSql for SystemTime {
|
||||
fn to_sql(&self, _: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
|
||||
fn to_sql(&self, _: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
|
||||
let epoch = UNIX_EPOCH + Duration::from_secs(TIME_SEC_CONVERSION);
|
||||
|
||||
let to_usec =
|
||||
@ -776,7 +776,7 @@ impl ToSql for SystemTime {
|
||||
to_sql_checked!();
|
||||
}
|
||||
|
||||
fn downcast(len: usize) -> Result<i32, Box<Error + Sync + Send>> {
|
||||
fn downcast(len: usize) -> Result<i32, Box<dyn Error + Sync + Send>> {
|
||||
if len > i32::max_value() as usize {
|
||||
Err("value too large to transmit".into())
|
||||
} else {
|
||||
|
@ -1,8 +1,5 @@
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
|
||||
use self::serde::{Deserialize, Serialize};
|
||||
use self::serde_json::Value;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use std::error::Error;
|
||||
use std::fmt::Debug;
|
||||
use std::io::Read;
|
||||
|
@ -2,7 +2,7 @@ use postgres_protocol::types;
|
||||
use std::error::Error;
|
||||
use std::{i32, i64};
|
||||
|
||||
use types::{FromSql, IsNull, ToSql, Type};
|
||||
use crate::types::{FromSql, IsNull, ToSql, Type};
|
||||
|
||||
/// A wrapper that can be used to represent infinity with `Type::Date` types.
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
@ -16,7 +16,7 @@ pub enum Date<T> {
|
||||
}
|
||||
|
||||
impl<'a, T: FromSql<'a>> FromSql<'a> for Date<T> {
|
||||
fn from_sql(ty: &Type, raw: &'a [u8]) -> Result<Self, Box<Error + Sync + Send>> {
|
||||
fn from_sql(ty: &Type, raw: &'a [u8]) -> Result<Self, Box<dyn Error + Sync + Send>> {
|
||||
match types::date_from_sql(raw)? {
|
||||
i32::MAX => Ok(Date::PosInfinity),
|
||||
i32::MIN => Ok(Date::NegInfinity),
|
||||
@ -30,7 +30,7 @@ impl<'a, T: FromSql<'a>> FromSql<'a> for Date<T> {
|
||||
}
|
||||
|
||||
impl<T: ToSql> ToSql for Date<T> {
|
||||
fn to_sql(&self, ty: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
|
||||
fn to_sql(&self, ty: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
|
||||
let value = match *self {
|
||||
Date::PosInfinity => i32::MAX,
|
||||
Date::NegInfinity => i32::MIN,
|
||||
@ -61,7 +61,7 @@ pub enum Timestamp<T> {
|
||||
}
|
||||
|
||||
impl<'a, T: FromSql<'a>> FromSql<'a> for Timestamp<T> {
|
||||
fn from_sql(ty: &Type, raw: &'a [u8]) -> Result<Self, Box<Error + Sync + Send>> {
|
||||
fn from_sql(ty: &Type, raw: &'a [u8]) -> Result<Self, Box<dyn Error + Sync + Send>> {
|
||||
match types::timestamp_from_sql(raw)? {
|
||||
i64::MAX => Ok(Timestamp::PosInfinity),
|
||||
i64::MIN => Ok(Timestamp::NegInfinity),
|
||||
@ -78,7 +78,7 @@ impl<'a, T: FromSql<'a>> FromSql<'a> for Timestamp<T> {
|
||||
}
|
||||
|
||||
impl<T: ToSql> ToSql for Timestamp<T> {
|
||||
fn to_sql(&self, ty: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
|
||||
fn to_sql(&self, ty: &Type, out: &mut Vec<u8>) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
|
||||
let value = match *self {
|
||||
Timestamp::PosInfinity => i64::MAX,
|
||||
Timestamp::NegInfinity => i64::MIN,
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Autogenerated file - DO NOT EDIT
|
||||
use std::sync::Arc;
|
||||
|
||||
use types::{Kind, Oid, Type};
|
||||
use crate::types::{Kind, Oid, Type};
|
||||
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
pub struct Other {
|
||||
|
@ -1,6 +1,4 @@
|
||||
extern crate uuid;
|
||||
|
||||
use self::uuid::Uuid;
|
||||
use uuid::Uuid;
|
||||
use postgres_protocol::types;
|
||||
use std::error::Error;
|
||||
|
||||
|
@ -1,15 +1,8 @@
|
||||
extern crate env_logger;
|
||||
extern crate tokio;
|
||||
extern crate tokio_postgres;
|
||||
#![warn(rust_2018_idioms)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate futures;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
use futures::future;
|
||||
use futures::stream;
|
||||
use futures::sync::mpsc;
|
||||
use futures::{future, stream, try_ready};
|
||||
use log::debug;
|
||||
use std::error::Error;
|
||||
use std::time::{Duration, Instant};
|
||||
use tokio::net::TcpStream;
|
||||
@ -244,7 +237,8 @@ fn query_portal() {
|
||||
"CREATE TEMPORARY TABLE foo (id SERIAL, name TEXT);
|
||||
INSERT INTO foo (name) VALUES ('alice'), ('bob'), ('charlie');
|
||||
BEGIN;",
|
||||
)).unwrap();
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
let statement = runtime
|
||||
.block_on(client.prepare("SELECT id, name FROM foo ORDER BY id"))
|
||||
@ -292,10 +286,12 @@ fn cancel_query() {
|
||||
.then(|r| {
|
||||
r.unwrap();
|
||||
TcpStream::connect(&"127.0.0.1:5433".parse().unwrap())
|
||||
}).then(|r| {
|
||||
})
|
||||
.then(|r| {
|
||||
let s = r.unwrap();
|
||||
tokio_postgres::cancel_query(s, NoTls, cancel_data)
|
||||
}).then(|r| {
|
||||
})
|
||||
.then(|r| {
|
||||
r.unwrap();
|
||||
Ok::<(), ()>(())
|
||||
});
|
||||
@ -321,7 +317,8 @@ fn custom_enum() {
|
||||
'ok',
|
||||
'happy'
|
||||
)",
|
||||
)).unwrap();
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
let select = client.prepare("SELECT $1::mood");
|
||||
let select = runtime.block_on(select).unwrap();
|
||||
@ -352,7 +349,8 @@ fn custom_domain() {
|
||||
runtime
|
||||
.block_on(client.batch_execute(
|
||||
"CREATE DOMAIN pg_temp.session_id AS bytea CHECK(octet_length(VALUE) = 16)",
|
||||
)).unwrap();
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
let select = client.prepare("SELECT $1::session_id");
|
||||
let select = runtime.block_on(select).unwrap();
|
||||
@ -405,7 +403,8 @@ fn custom_composite() {
|
||||
supplier INTEGER,
|
||||
price NUMERIC
|
||||
)",
|
||||
)).unwrap();
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
let select = client.prepare("SELECT $1::inventory_item");
|
||||
let select = runtime.block_on(select).unwrap();
|
||||
@ -442,7 +441,8 @@ fn custom_range() {
|
||||
subtype = float8,
|
||||
subtype_diff = float8mi
|
||||
)",
|
||||
)).unwrap();
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
let select = client.prepare("SELECT $1::floatrange");
|
||||
let select = runtime.block_on(select).unwrap();
|
||||
@ -534,7 +534,8 @@ fn transaction_commit() {
|
||||
id SERIAL,
|
||||
name TEXT
|
||||
)",
|
||||
)).unwrap();
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
let f = client.batch_execute("INSERT INTO foo (name) VALUES ('steven')");
|
||||
runtime.block_on(client.transaction().build(f)).unwrap();
|
||||
@ -544,7 +545,8 @@ fn transaction_commit() {
|
||||
client
|
||||
.prepare("SELECT name FROM foo")
|
||||
.and_then(|s| client.query(&s, &[]).collect()),
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(rows.len(), 1);
|
||||
assert_eq!(rows[0].get::<_, &str>(0), "steven");
|
||||
@ -567,12 +569,13 @@ fn transaction_abort() {
|
||||
id SERIAL,
|
||||
name TEXT
|
||||
)",
|
||||
)).unwrap();
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
let f = client
|
||||
.batch_execute("INSERT INTO foo (name) VALUES ('steven')")
|
||||
.map_err(|e| Box::new(e) as Box<Error>)
|
||||
.and_then(|_| Err::<(), _>(Box::<Error>::from("")));
|
||||
.map_err(|e| Box::new(e) as Box<dyn Error>)
|
||||
.and_then(|_| Err::<(), _>(Box::<dyn Error>::from("")));
|
||||
runtime.block_on(client.transaction().build(f)).unwrap_err();
|
||||
|
||||
let rows = runtime
|
||||
@ -580,7 +583,8 @@ fn transaction_abort() {
|
||||
client
|
||||
.prepare("SELECT name FROM foo")
|
||||
.and_then(|s| client.query(&s, &[]).collect()),
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(rows.len(), 0);
|
||||
}
|
||||
@ -602,7 +606,8 @@ fn copy_in() {
|
||||
id INTEGER,
|
||||
name TEXT
|
||||
)",
|
||||
)).unwrap();
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
let stream = stream::iter_ok::<_, String>(vec![b"1\tjim\n".to_vec(), b"2\tjoe\n".to_vec()]);
|
||||
let rows = runtime
|
||||
@ -610,7 +615,8 @@ fn copy_in() {
|
||||
client
|
||||
.prepare("COPY foo FROM STDIN")
|
||||
.and_then(|s| client.copy_in(&s, &[], stream)),
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(rows, 2);
|
||||
|
||||
let rows = runtime
|
||||
@ -618,7 +624,8 @@ fn copy_in() {
|
||||
client
|
||||
.prepare("SELECT id, name FROM foo ORDER BY id")
|
||||
.and_then(|s| client.query(&s, &[]).collect()),
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(rows.len(), 2);
|
||||
assert_eq!(rows[0].get::<_, i32>(0), 1);
|
||||
@ -644,7 +651,8 @@ fn copy_in_error() {
|
||||
id INTEGER,
|
||||
name TEXT
|
||||
)",
|
||||
)).unwrap();
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
let stream = stream::iter_result(vec![Ok(b"1\tjim\n".to_vec()), Err("asdf")]);
|
||||
let error = runtime
|
||||
@ -652,7 +660,8 @@ fn copy_in_error() {
|
||||
client
|
||||
.prepare("COPY foo FROM STDIN")
|
||||
.and_then(|s| client.copy_in(&s, &[], stream)),
|
||||
).unwrap_err();
|
||||
)
|
||||
.unwrap_err();
|
||||
assert!(error.to_string().contains("asdf"));
|
||||
|
||||
let rows = runtime
|
||||
@ -660,7 +669,8 @@ fn copy_in_error() {
|
||||
client
|
||||
.prepare("SELECT id, name FROM foo ORDER BY id")
|
||||
.and_then(|s| client.query(&s, &[]).collect()),
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(rows.len(), 0);
|
||||
}
|
||||
@ -683,14 +693,16 @@ fn copy_out() {
|
||||
name TEXT
|
||||
);
|
||||
INSERT INTO foo (name) VALUES ('jim'), ('joe');",
|
||||
)).unwrap();
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
let data = runtime
|
||||
.block_on(
|
||||
client
|
||||
.prepare("COPY foo TO STDOUT")
|
||||
.and_then(|s| client.copy_out(&s, &[]).concat2()),
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(&data[..], b"1\tjim\n2\tjoe\n");
|
||||
}
|
||||
|
||||
@ -719,7 +731,8 @@ fn transaction_builder_around_moved_client() {
|
||||
.prepare("INSERT INTO transaction_foo (name) VALUES ($1), ($2)")
|
||||
.map(|statement| (client, statement))
|
||||
})
|
||||
}).and_then(|(mut client, statement)| {
|
||||
})
|
||||
.and_then(|(mut client, statement)| {
|
||||
client
|
||||
.query(&statement, &[&"jim", &"joe"])
|
||||
.collect()
|
||||
@ -734,7 +747,8 @@ fn transaction_builder_around_moved_client() {
|
||||
client
|
||||
.prepare("COPY transaction_foo TO STDOUT")
|
||||
.and_then(|s| client.copy_out(&s, &[]).concat2()),
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(&data[..], b"1\tjim\n2\tjoe\n");
|
||||
|
||||
drop(client);
|
||||
|
Loading…
Reference in New Issue
Block a user