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