From 88532ffc28c3f464795cbd8125a3674629e18710 Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Tue, 26 May 2020 05:00:07 -0700 Subject: [PATCH] refactor: clean up warnings --- Cargo.toml | 6 +++--- sqlx-core/src/mysql/types/bigdecimal.rs | 3 +-- sqlx-core/src/mysql/types/chrono.rs | 7 +++---- sqlx-core/src/mysql/types/json.rs | 2 +- sqlx-core/src/mysql/types/time.rs | 2 +- sqlx-core/src/postgres/types/bigdecimal.rs | 3 +-- sqlx-core/src/postgres/types/chrono.rs | 2 -- sqlx-core/src/postgres/types/ipnetwork.rs | 1 - sqlx-core/src/postgres/types/json.rs | 6 ++---- sqlx-core/src/postgres/types/numeric.rs | 3 +-- sqlx-core/src/postgres/types/time.rs | 6 +----- sqlx-core/src/postgres/types/uuid.rs | 1 - src/lib.rs | 17 ++++------------- 13 files changed, 18 insertions(+), 41 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 80d4765f..98e1c108 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,9 +44,9 @@ tls = [ "sqlx-core/tls" ] offline = ["sqlx-macros/offline", "sqlx-core/offline"] # intended mainly for CI and docs -all = [ "tls", "all-database", "all-type" ] -all-database = [ "mysql", "sqlite", "postgres" ] -all-type = [ "bigdecimal", "json", "time", "chrono", "ipnetwork", "uuid" ] +all = [ "tls", "all-databases", "all-types" ] +all-databases = [ "mysql", "sqlite", "postgres" ] +all-types = [ "bigdecimal", "json", "time", "chrono", "ipnetwork", "uuid" ] # runtime runtime-async-std = [ "sqlx-core/runtime-async-std", "sqlx-macros/runtime-async-std" ] diff --git a/sqlx-core/src/mysql/types/bigdecimal.rs b/sqlx-core/src/mysql/types/bigdecimal.rs index cef2baf7..088e9cbf 100644 --- a/sqlx-core/src/mysql/types/bigdecimal.rs +++ b/sqlx-core/src/mysql/types/bigdecimal.rs @@ -1,11 +1,10 @@ use bigdecimal::BigDecimal; -use crate::database::{Database, HasArguments}; use crate::decode::Decode; use crate::encode::{Encode, IsNull}; use crate::error::BoxDynError; use crate::mysql::io::MySqlBufMutExt; -use crate::mysql::protocol::text::{ColumnFlags, ColumnType}; +use crate::mysql::protocol::text::ColumnType; use crate::mysql::{MySql, MySqlTypeInfo, MySqlValueRef}; use crate::types::Type; diff --git a/sqlx-core/src/mysql/types/chrono.rs b/sqlx-core/src/mysql/types/chrono.rs index 1c77d4fb..816210d7 100644 --- a/sqlx-core/src/mysql/types/chrono.rs +++ b/sqlx-core/src/mysql/types/chrono.rs @@ -1,15 +1,14 @@ use std::convert::TryFrom; -use std::str::from_utf8; use bytes::Buf; use chrono::{DateTime, Datelike, NaiveDate, NaiveDateTime, NaiveTime, Timelike, Utc}; use crate::decode::Decode; use crate::encode::{Encode, IsNull}; -use crate::error::{BoxDynError, Error}; +use crate::error::BoxDynError; use crate::mysql::protocol::text::ColumnType; use crate::mysql::type_info::MySqlTypeInfo; -use crate::mysql::{MySql, MySqlValue, MySqlValueFormat, MySqlValueRef}; +use crate::mysql::{MySql, MySqlValueFormat, MySqlValueRef}; use crate::types::Type; impl Type for DateTime { @@ -181,7 +180,7 @@ impl<'r> Decode<'r, MySql> for NaiveDateTime { fn decode(value: MySqlValueRef<'r>) -> Result { match value.format() { MySqlValueFormat::Binary => { - let mut buf = value.as_bytes()?; + let buf = value.as_bytes()?; let len = buf[0]; let date = decode_date(&buf[1..]); diff --git a/sqlx-core/src/mysql/types/json.rs b/sqlx-core/src/mysql/types/json.rs index 029f2f60..ae2a7a35 100644 --- a/sqlx-core/src/mysql/types/json.rs +++ b/sqlx-core/src/mysql/types/json.rs @@ -1,5 +1,5 @@ use serde::de::DeserializeOwned; -use serde::{Deserialize, Serialize}; +use serde::Serialize; use crate::decode::Decode; use crate::encode::{Encode, IsNull}; diff --git a/sqlx-core/src/mysql/types/time.rs b/sqlx-core/src/mysql/types/time.rs index 87cfd1e9..fd979d5e 100644 --- a/sqlx-core/src/mysql/types/time.rs +++ b/sqlx-core/src/mysql/types/time.rs @@ -190,7 +190,7 @@ impl<'r> Decode<'r, MySql> for PrimitiveDateTime { fn decode(value: MySqlValueRef<'r>) -> Result { match value.format() { MySqlValueFormat::Binary => { - let mut buf = value.as_bytes()?; + let buf = value.as_bytes()?; let len = buf[0]; let date = decode_date(&buf[1..])?; diff --git a/sqlx-core/src/postgres/types/bigdecimal.rs b/sqlx-core/src/postgres/types/bigdecimal.rs index 9db24daf..cb3cfd43 100644 --- a/sqlx-core/src/postgres/types/bigdecimal.rs +++ b/sqlx-core/src/postgres/types/bigdecimal.rs @@ -4,7 +4,6 @@ use std::convert::{TryFrom, TryInto}; use bigdecimal::BigDecimal; use num_bigint::{BigInt, Sign}; -use crate::database::Database; use crate::decode::Decode; use crate::encode::{Encode, IsNull}; use crate::error::BoxDynError; @@ -81,7 +80,7 @@ impl TryFrom<&'_ BigDecimal> for PgNumeric { let base_10_to_10000 = |chunk: &[u8]| chunk.iter().fold(0i16, |a, &d| a * 10 + d as i16); // NOTE: this unfortunately copies the BigInt internally - let (mut integer, exp) = decimal.as_bigint_and_exponent(); + let (integer, exp) = decimal.as_bigint_and_exponent(); // this routine is specifically optimized for base-10 // FIXME: is there a way to iterate over the digits to avoid the Vec allocation diff --git a/sqlx-core/src/postgres/types/chrono.rs b/sqlx-core/src/postgres/types/chrono.rs index eda85e27..19ac89a8 100644 --- a/sqlx-core/src/postgres/types/chrono.rs +++ b/sqlx-core/src/postgres/types/chrono.rs @@ -1,9 +1,7 @@ -use std::borrow::Cow; use std::mem; use chrono::{DateTime, Duration, Local, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc}; -use crate::database::Database; use crate::decode::Decode; use crate::encode::{Encode, IsNull}; use crate::error::BoxDynError; diff --git a/sqlx-core/src/postgres/types/ipnetwork.rs b/sqlx-core/src/postgres/types/ipnetwork.rs index 85d0ba76..a4eb8f44 100644 --- a/sqlx-core/src/postgres/types/ipnetwork.rs +++ b/sqlx-core/src/postgres/types/ipnetwork.rs @@ -2,7 +2,6 @@ use std::net::{Ipv4Addr, Ipv6Addr}; use ipnetwork::{IpNetwork, Ipv4Network, Ipv6Network}; -use crate::database::Database; use crate::decode::Decode; use crate::encode::{Encode, IsNull}; use crate::error::BoxDynError; diff --git a/sqlx-core/src/postgres/types/json.rs b/sqlx-core/src/postgres/types/json.rs index 2a13b610..11854acf 100644 --- a/sqlx-core/src/postgres/types/json.rs +++ b/sqlx-core/src/postgres/types/json.rs @@ -1,10 +1,8 @@ use serde::{Deserialize, Serialize}; -use serde_json::value::RawValue as JsonRawValue; -use serde_json::Value as JsonValue; use crate::decode::Decode; use crate::encode::{Encode, IsNull}; -use crate::error::{BoxDynError, Error}; +use crate::error::BoxDynError; use crate::postgres::{PgArgumentBuffer, PgTypeInfo, PgValueFormat, PgValueRef, Postgres}; use crate::types::{Json, Type}; @@ -36,7 +34,7 @@ impl<'q, T> Encode<'q, Postgres> for Json where T: Serialize, { - fn encode_by_ref(&self, buf: &mut >::Arguments) -> IsNull { + fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> IsNull { // JSONB version (as of 2020-03-20) buf.push(1); diff --git a/sqlx-core/src/postgres/types/numeric.rs b/sqlx-core/src/postgres/types/numeric.rs index 815c949d..eb40262c 100644 --- a/sqlx-core/src/postgres/types/numeric.rs +++ b/sqlx-core/src/postgres/types/numeric.rs @@ -3,8 +3,7 @@ use std::convert::TryInto; use bytes::Buf; use crate::error::BoxDynError; -use crate::postgres::{PgArgumentBuffer, PgTypeInfo, Postgres}; -use crate::types::Type; +use crate::postgres::PgArgumentBuffer; /// Represents a `NUMERIC` value in the **Postgres** wire protocol. #[derive(Debug, PartialEq, Eq)] diff --git a/sqlx-core/src/postgres/types/time.rs b/sqlx-core/src/postgres/types/time.rs index 5845a713..3338680d 100644 --- a/sqlx-core/src/postgres/types/time.rs +++ b/sqlx-core/src/postgres/types/time.rs @@ -1,9 +1,5 @@ -use time::{ - date, offset, Date, Duration, NumericalDuration, OffsetDateTime, PrimitiveDateTime, Time, - UtcOffset, -}; +use time::{date, offset, Date, Duration, OffsetDateTime, PrimitiveDateTime, Time}; -use crate::database::Database; use crate::decode::Decode; use crate::encode::{Encode, IsNull}; use crate::error::BoxDynError; diff --git a/sqlx-core/src/postgres/types/uuid.rs b/sqlx-core/src/postgres/types/uuid.rs index f3bbd96a..d309a7ee 100644 --- a/sqlx-core/src/postgres/types/uuid.rs +++ b/sqlx-core/src/postgres/types/uuid.rs @@ -1,6 +1,5 @@ use uuid::Uuid; -use crate::database::Database; use crate::decode::Decode; use crate::encode::{Encode, IsNull}; use crate::error::BoxDynError; diff --git a/src/lib.rs b/src/lib.rs index 46a6ba88..6a5f9aeb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,14 +2,15 @@ pub use sqlx_core::arguments; pub use sqlx_core::connection::{Connect, Connection}; -pub use sqlx_core::cursor::{self, Cursor}; pub use sqlx_core::database::{self, Database}; pub use sqlx_core::executor::{self, Execute, Executor}; +pub use sqlx_core::from_row::FromRow; pub use sqlx_core::pool::{self, Pool}; pub use sqlx_core::query::{self, query, Query}; pub use sqlx_core::query_as::{query_as, QueryAs}; -pub use sqlx_core::row::{self, FromRow, Row}; -pub use sqlx_core::transaction::Transaction; +pub use sqlx_core::query_scalar::{query_scalar, QueryScalar}; +pub use sqlx_core::row::{self, Row}; +// pub use sqlx_core::transaction::Transaction; pub use sqlx_core::value; #[doc(hidden)] @@ -72,17 +73,7 @@ pub mod decode { pub mod prelude { pub use super::Connect; pub use super::Connection; - pub use super::Cursor; pub use super::Executor; pub use super::FromRow; pub use super::Row; - - #[cfg(feature = "postgres")] - pub use super::postgres::PgQueryAs; - - #[cfg(feature = "mysql")] - pub use super::mysql::MySqlQueryAs; - - #[cfg(feature = "sqlite")] - pub use super::sqlite::SqliteQueryAs; }