remove unused imports

This commit is contained in:
Ryan Leckey 2020-03-02 00:21:52 -08:00
parent 10232a2cdc
commit b8cd2e9388
30 changed files with 35 additions and 196 deletions

View File

@ -1,11 +1,7 @@
use std::convert::TryInto;
use std::ops::{Deref, DerefMut};
use futures_core::future::BoxFuture;
use futures_util::TryFutureExt;
use crate::database::Database;
use crate::describe::Describe;
use crate::executor::Executor;
use crate::pool::{Pool, PoolConnection};
use crate::url::Url;

View File

@ -1,13 +1,9 @@
use std::future::Future;
use futures_core::future::BoxFuture;
use futures_core::stream::BoxStream;
use crate::connection::{Connect, MaybeOwnedConnection};
use crate::database::{Database, HasRow};
use crate::executor::Execute;
use crate::pool::Pool;
use crate::row::Row;
/// Represents a result set, which is generated by executing a query against the database.
///

View File

@ -1,9 +1,8 @@
use std::fmt::Display;
use crate::arguments::Arguments;
use crate::connection::{Connect, Connection};
use crate::connection::Connect;
use crate::cursor::Cursor;
use crate::query_as::QueryAs;
use crate::row::Row;
use crate::types::TypeInfo;

View File

@ -1,9 +1,6 @@
//! Types and traits for decoding values from the database.
use std::error::Error as StdError;
use std::fmt::{self, Display};
use crate::database::{Database, HasRawValue};
use crate::database::HasRawValue;
/// Decode a single value from the database.
pub trait Decode<'de, DB>

View File

@ -1,8 +1,7 @@
use futures_core::future::BoxFuture;
use crate::database::{Database, HasCursor};
use crate::describe::Describe;
use futures_core::future::BoxFuture;
use futures_core::stream::BoxStream;
use futures_util::TryStreamExt;
/// A type that contains or can provide a database connection to use for executing queries
/// against the database.

View File

@ -55,12 +55,6 @@ where
Ok(())
}
pub fn clear_bufs(&mut self) {
self.rbuf_rindex = 0;
self.rbuf_windex = 0;
self.wbuf.clear();
}
#[inline]
pub fn consume(&mut self, cnt: usize) {
self.rbuf_rindex += cnt;

View File

@ -1,7 +1,6 @@
//! Core of SQLx, the rust SQL toolkit. Not intended to be used directly.
#![forbid(unsafe_code)]
#![allow(unused)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#[macro_use]

View File

@ -5,8 +5,6 @@ use std::time::Instant;
use super::inner::{DecrementSizeGuard, SharedPool};
use crate::connection::{Connect, Connection};
use crate::describe::Describe;
use crate::executor::Executor;
/// A connection checked out from [`Pool`][crate::Pool].
///

View File

@ -1,10 +1,7 @@
use std::ops::DerefMut;
use futures_core::{future::BoxFuture, stream::BoxStream};
use futures_util::StreamExt;
use futures_core::future::BoxFuture;
use super::PoolConnection;
use crate::connection::{Connect, Connection};
use crate::connection::Connect;
use crate::cursor::Cursor;
use crate::database::{Database, HasCursor};
use crate::describe::Describe;

View File

@ -7,7 +7,6 @@ use std::{
};
use crate::connection::Connect;
use crate::database::Database;
use crate::transaction::Transaction;
use self::inner::SharedPool;

View File

@ -1,27 +1,20 @@
use std::borrow::Cow;
use std::collections::HashMap;
use std::convert::TryInto;
use std::ops::Range;
use std::sync::Arc;
use byteorder::NetworkEndian;
use futures_core::future::BoxFuture;
use futures_core::Future;
use futures_util::TryFutureExt;
use crate::connection::{Connect, Connection};
use crate::describe::{Column, Describe};
use crate::executor::Executor;
use crate::io::{Buf, BufStream, MaybeTlsStream};
use crate::postgres::protocol::{
self, Authentication, AuthenticationMd5, AuthenticationSasl, Decode, Encode, Message,
ParameterDescription, PasswordMessage, RowDescription, StartupMessage, StatementId, Terminate,
TypeFormat,
Authentication, AuthenticationMd5, AuthenticationSasl, Message, PasswordMessage,
StartupMessage, StatementId, Terminate, TypeFormat,
};
use crate::postgres::stream::PgStream;
use crate::postgres::{sasl, tls, PgError, PgTypeInfo, Postgres};
use crate::postgres::{sasl, tls};
use crate::url::Url;
use crate::Error;
/// An asynchronous connection to a [Postgres][super::Postgres] database.
///

View File

@ -1,25 +1,14 @@
use std::collections::HashMap;
use std::future::Future;
use std::mem;
use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll};
use async_stream::try_stream;
use futures_core::future::BoxFuture;
use futures_core::stream::BoxStream;
use crate::connection::{ConnectionSource, MaybeOwnedConnection};
use crate::cursor::Cursor;
use crate::database::Database;
use crate::database::HasRow;
use crate::executor::Execute;
use crate::pool::{Pool, PoolConnection};
use crate::postgres::protocol::{
CommandComplete, DataRow, Message, RowDescription, StatementId, TypeFormat,
};
use crate::pool::Pool;
use crate::postgres::protocol::{DataRow, Message, RowDescription, StatementId, TypeFormat};
use crate::postgres::{PgArguments, PgConnection, PgRow, Postgres};
use futures_core::Stream;
pub struct PgCursor<'c, 'q> {
source: ConnectionSource<'c, PgConnection>,

View File

@ -1,17 +1,12 @@
use std::collections::HashMap;
use std::io;
use std::sync::Arc;
use futures_core::future::BoxFuture;
use crate::cursor::Cursor;
use crate::describe::{Column, Describe};
use crate::executor::{Execute, Executor, RefExecutor};
use crate::postgres::protocol::{
self, CommandComplete, Encode, Message, ParameterDescription, RowDescription, StatementId,
TypeFormat,
self, CommandComplete, Message, ParameterDescription, RowDescription, StatementId, TypeFormat,
};
use crate::postgres::{PgArguments, PgConnection, PgCursor, PgRow, PgTypeInfo, Postgres};
use crate::postgres::{PgArguments, PgConnection, PgCursor, PgTypeInfo, Postgres};
impl PgConnection {
pub(crate) fn write_simple_query(&mut self, query: &str) {

View File

@ -1,5 +1,4 @@
use crate::io::Buf;
use crate::postgres::protocol::Decode;
use byteorder::NetworkEndian;
use std::str;
@ -82,7 +81,7 @@ pub struct AuthenticationMd5 {
}
impl AuthenticationMd5 {
pub fn read(mut buf: &[u8]) -> crate::Result<Self> {
pub fn read(buf: &[u8]) -> crate::Result<Self> {
let mut salt = [0_u8; 4];
salt.copy_from_slice(buf);
@ -118,7 +117,7 @@ pub struct AuthenticationSaslContinue {
}
impl AuthenticationSaslContinue {
pub fn read(mut buf: &[u8]) -> crate::Result<Self> {
pub fn read(buf: &[u8]) -> crate::Result<Self> {
let mut salt: Vec<u8> = Vec::new();
let mut nonce: Vec<u8> = Vec::new();
let mut iter_count: u32 = 0;
@ -163,22 +162,6 @@ impl AuthenticationSaslContinue {
}
}
#[derive(Debug)]
pub struct AuthenticationSaslFinal {
pub data: Box<[u8]>,
}
impl AuthenticationSaslFinal {
pub fn read(mut buf: &[u8]) -> crate::Result<Self> {
let mut data = Vec::with_capacity(buf.len());
data.extend_from_slice(buf);
Ok(Self {
data: data.into_boxed_slice(),
})
}
}
#[cfg(test)]
mod tests {
use super::{Authentication, Decode};

View File

@ -1,51 +0,0 @@
#![allow(dead_code)]
use crate::io::BufMut;
use crate::postgres::protocol::Encode;
use byteorder::NetworkEndian;
pub enum Close<'a> {
Statement(&'a str),
Portal(&'a str),
}
impl Encode for Close<'_> {
fn encode(&self, buf: &mut Vec<u8>) {
buf.push(b'C');
let (kind, name) = match self {
Close::Statement(name) => (b'S', name),
Close::Portal(name) => (b'P', name),
};
// len + kind + nul + len(string)
buf.put_i32::<NetworkEndian>((4 + 1 + 1 + name.len()) as i32);
buf.push(kind);
buf.put_str_nul(name);
}
}
#[cfg(test)]
mod test {
use super::{Close, Encode};
#[test]
fn it_encodes_close_portal() {
let mut buf = Vec::new();
let m = Close::Portal("__sqlx_p_1");
m.encode(&mut buf);
assert_eq!(buf, b"C\0\0\0\x10P__sqlx_p_1\0");
}
#[test]
fn it_encodes_close_statement() {
let mut buf = Vec::new();
let m = Close::Statement("__sqlx_s_1");
m.encode(&mut buf);
assert_eq!(buf, b"C\0\0\0\x10S__sqlx_s_1\0");
}
}

View File

@ -1,5 +1,4 @@
use crate::io::Buf;
use crate::postgres::protocol::Decode;
#[derive(Debug)]
pub struct CommandComplete {

View File

@ -1,8 +1,5 @@
use crate::io::{Buf, ByteStr};
use crate::postgres::protocol::Decode;
use crate::postgres::PgConnection;
use crate::io::Buf;
use byteorder::NetworkEndian;
use std::fmt::{self, Debug};
use std::ops::Range;
pub struct DataRow<'c> {

View File

@ -1,10 +1,5 @@
use std::convert::TryFrom;
use crate::postgres::protocol::{
Authentication, BackendKeyData, CommandComplete, DataRow, NotificationResponse,
ParameterDescription, ParameterStatus, ReadyForQuery, Response, RowDescription,
};
#[derive(Debug, Copy, Clone)]
#[repr(u8)]
pub enum Message {

View File

@ -10,7 +10,6 @@ pub use type_id::TypeId;
// REQUESTS
mod bind;
mod cancel_request;
mod close;
mod describe;
mod encode;
mod execute;
@ -28,7 +27,6 @@ mod terminate;
pub use bind::Bind;
pub use cancel_request::CancelRequest;
pub use close::Close;
pub use describe::Describe;
pub use encode::Encode;
pub use execute::Execute;
@ -60,7 +58,6 @@ mod message;
pub use authentication::{
Authentication, AuthenticationMd5, AuthenticationSasl, AuthenticationSaslContinue,
AuthenticationSaslFinal,
};
pub use backend_key_data::BackendKeyData;
pub use command_complete::CommandComplete;

View File

@ -1,5 +1,5 @@
use crate::io::Buf;
use crate::postgres::protocol::{Decode, TypeId};
use crate::postgres::protocol::TypeId;
use byteorder::NetworkEndian;
#[derive(Debug)]

View File

@ -1,5 +1,4 @@
use crate::io::Buf;
use crate::postgres::protocol::Decode;
use std::str::{self, FromStr};
#[derive(Debug, Copy, Clone)]

View File

@ -1,5 +1,5 @@
use crate::io::Buf;
use crate::postgres::protocol::{Decode, TypeFormat, TypeId};
use crate::postgres::protocol::{TypeFormat, TypeId};
use byteorder::NetworkEndian;
#[derive(Debug)]

View File

@ -4,14 +4,10 @@ use std::collections::HashMap;
use std::convert::TryFrom;
use std::sync::Arc;
use crate::connection::MaybeOwnedConnection;
use crate::decode::Decode;
use crate::error::UnexpectedNullError;
use crate::pool::PoolConnection;
use crate::postgres::protocol::{DataRow, TypeFormat};
use crate::postgres::{PgConnection, Postgres};
use crate::postgres::Postgres;
use crate::row::{ColumnIndex, Row};
use crate::types::Type;
/// A value from Postgres. This may be in a BINARY or TEXT format depending
/// on the data type and if the query was prepared or not.

View File

@ -3,11 +3,9 @@ use rand::Rng;
use sha2::{Digest, Sha256};
use crate::postgres::protocol::{
hi, Authentication, AuthenticationSaslContinue, Encode, Message, SaslInitialResponse,
SaslResponse,
hi, Authentication, AuthenticationSaslContinue, Message, SaslInitialResponse, SaslResponse,
};
use crate::postgres::stream::PgStream;
use crate::postgres::PgConnection;
static GS2_HEADER: &'static str = "n,,";
static CHANNEL_ATTR: &'static str = "c";

View File

@ -4,7 +4,7 @@ use std::net::Shutdown;
use byteorder::NetworkEndian;
use crate::io::{Buf, BufStream, MaybeTlsStream};
use crate::postgres::protocol::{Encode, Message, Response, Severity};
use crate::postgres::protocol::{Encode, Message, Response};
use crate::postgres::PgError;
use crate::url::Url;
@ -73,13 +73,10 @@ impl PgStream {
match type_ {
Message::ErrorResponse | Message::NoticeResponse => {
let response = Response::read(self.stream.buffer())?;
match response.severity {
Severity::Error | Severity::Panic | Severity::Fatal => {
// This is an error, bubble up as one immediately
return Err(crate::Error::Database(Box::new(PgError(response))));
}
_ => {}
if response.severity.is_error() {
// This is an error, bubble up as one immediately
return Err(crate::Error::Database(Box::new(PgError(response))));
}
// TODO: Provide some way of receiving these non-critical

View File

@ -1,9 +1,6 @@
use crate::postgres::protocol::SslRequest;
use crate::postgres::stream::PgStream;
use crate::postgres::PgConnection;
use crate::url::Url;
use std::borrow::Cow;
use std::fs::read;
pub(crate) async fn request_if_needed(stream: &mut PgStream, url: &Url) -> crate::Result<()> {
// https://www.postgresql.org/docs/12/libpq-ssl.html#LIBPQ-SSL-SSLMODE-STATEMENTS

View File

@ -40,7 +40,7 @@ impl Encode<Postgres> for Vec<u8> {
impl<'de> Decode<'de, Postgres> for Vec<u8> {
fn decode(value: Option<PgValue<'de>>) -> crate::Result<Self> {
match value.try_into()? {
PgValue::Binary(mut buf) => Ok(buf.to_vec()),
PgValue::Binary(buf) => Ok(buf.to_vec()),
PgValue::Text(s) => {
// BYTEA is formatted as \x followed by hex characters
hex::decode(&s[2..]).map_err(crate::Error::decode)
@ -52,8 +52,8 @@ impl<'de> Decode<'de, Postgres> for Vec<u8> {
impl<'de> Decode<'de, Postgres> for &'de [u8] {
fn decode(value: Option<PgValue<'de>>) -> crate::Result<Self> {
match value.try_into()? {
PgValue::Binary(mut buf) => Ok(buf),
PgValue::Text(s) => Err(crate::Error::Decode(
PgValue::Binary(buf) => Ok(buf),
PgValue::Text(_s) => Err(crate::Error::Decode(
"unsupported decode to `&[u8]` of BYTEA in a simple query; \
use a prepared query or decode to `Vec<u8>`"
.into(),

View File

@ -1,7 +1,7 @@
use std::convert::TryInto;
use std::str::FromStr;
use byteorder::{ByteOrder, NetworkEndian, ReadBytesExt};
use byteorder::{NetworkEndian, ReadBytesExt};
use crate::decode::Decode;
use crate::encode::Encode;

View File

@ -1,27 +1,16 @@
use std::future::Future;
use std::marker::PhantomData;
use std::mem;
use std::pin::Pin;
use std::task::{Context, Poll};
use async_stream::try_stream;
use futures_core::future::BoxFuture;
use futures_core::stream::BoxStream;
use futures_core::Stream;
use futures_util::future::ready;
use futures_util::ready;
use futures_util::stream::try_unfold;
use futures_util::TryFutureExt;
use futures_util::TryStreamExt;
use crate::arguments::Arguments;
use crate::cursor::Cursor;
use crate::database::{Database, HasCursor, HasRow};
use crate::encode::Encode;
use crate::executor::{Execute, Executor, RefExecutor};
use crate::row::FromRow;
use crate::types::Type;
use crate::Error;
/// Raw SQL query with bind parameters. Returned by [`query`][crate::query::query].
pub struct Query<'q, DB, A = <DB as Database>::Arguments>
@ -163,7 +152,7 @@ where
}
/// Get the first row in the result
pub async fn fetch_optional<'e, E>(mut self, executor: E) -> crate::Result<Option<F::Mapped>>
pub async fn fetch_optional<'e, E>(self, executor: E) -> crate::Result<Option<F::Mapped>>
where
E: RefExecutor<'e, Database = DB>,
'q: 'e,

View File

@ -1,17 +1,9 @@
use core::marker::PhantomData;
use async_stream::try_stream;
use futures_core::future::BoxFuture;
use futures_core::stream::Stream;
use futures_util::future::ready;
use futures_util::future::TryFutureExt;
use crate::arguments::Arguments;
use crate::cursor::Cursor;
use crate::database::{Database, HasRow};
use crate::database::Database;
use crate::encode::Encode;
use crate::executor::{Execute, RefExecutor};
use crate::row::FromRow;
use crate::executor::Execute;
use crate::types::Type;
/// Raw SQL query with bind parameters, mapped to a concrete type
@ -118,7 +110,7 @@ macro_rules! make_query_as {
impl<'q, O> $name<'q, O> for crate::query_as::QueryAs<'q, $db, O> {
fn fetch<'e, E>(
mut self,
self,
executor: E,
) -> futures_core::stream::BoxStream<'e, crate::Result<O>>
where
@ -140,7 +132,7 @@ macro_rules! make_query_as {
}
fn fetch_optional<'e, E>(
mut self,
self,
executor: E,
) -> futures_core::future::BoxFuture<'e, crate::Result<Option<O>>>
where
@ -159,7 +151,7 @@ macro_rules! make_query_as {
}
fn fetch_one<'e, E>(
mut self,
self,
executor: E,
) -> futures_core::future::BoxFuture<'e, crate::Result<O>>
where
@ -176,7 +168,7 @@ macro_rules! make_query_as {
}
fn fetch_all<'e, E>(
mut self,
self,
executor: E,
) -> futures_core::future::BoxFuture<'e, crate::Result<Vec<O>>>
where