From 9ba488c831c1b556cd5e5208c44dfdaebdca5b75 Mon Sep 17 00:00:00 2001 From: nitn3lav <77448526+nitn3lav@users.noreply.github.com> Date: Thu, 14 Mar 2024 20:35:52 +0100 Subject: [PATCH] Generic Associated Types in Database, replacing HasValueRef, HasArguments, HasStatement (#2973) * HasValueRef, HasArguments, HasStatement -> Database GATs replace the associated types from the generic traits `HasValueRef<'r>`, `HasArguments<'q>` and `HasStatement<'q>` with generic associated types in `Database` * fixup after rebase --------- Co-authored-by: Austin Bonander --- sqlx-core/src/any/database.rs | 29 +++-------- sqlx-core/src/any/row.rs | 9 ++-- sqlx-core/src/any/types/blob.rs | 10 ++-- sqlx-core/src/any/types/bool.rs | 6 +-- sqlx-core/src/any/types/float.rs | 6 +-- sqlx-core/src/any/types/int.rs | 14 +++--- sqlx-core/src/any/types/str.rs | 12 ++--- sqlx-core/src/any/value.rs | 4 +- sqlx-core/src/arguments.rs | 12 ++--- sqlx-core/src/database.rs | 70 +++++--------------------- sqlx-core/src/decode.rs | 12 ++--- sqlx-core/src/encode.rs | 14 +++--- sqlx-core/src/executor.rs | 20 ++++---- sqlx-core/src/pool/executor.rs | 6 +-- sqlx-core/src/query.rs | 23 +++++---- sqlx-core/src/query_as.rs | 16 +++--- sqlx-core/src/query_builder.rs | 12 ++--- sqlx-core/src/query_scalar.rs | 16 +++--- sqlx-core/src/raw_sql.rs | 11 ++-- sqlx-core/src/row.rs | 7 +-- sqlx-core/src/statement.rs | 14 +++--- sqlx-core/src/testing/fixtures.rs | 4 +- sqlx-core/src/transaction.rs | 2 +- sqlx-core/src/types/bstr.rs | 8 +-- sqlx-core/src/types/json.rs | 8 +-- sqlx-core/src/types/text.rs | 4 +- sqlx-core/src/value.rs | 4 +- sqlx-macros-core/src/derives/decode.rs | 4 +- sqlx-macros-core/src/derives/encode.rs | 6 +-- sqlx-macros-core/src/query/args.rs | 4 +- sqlx-mysql/src/database.rs | 30 +++-------- sqlx-postgres/src/database.rs | 30 +++-------- sqlx-sqlite/src/database.rs | 30 +++-------- 33 files changed, 173 insertions(+), 284 deletions(-) diff --git a/sqlx-core/src/any/database.rs b/sqlx-core/src/any/database.rs index 1a57a77e..9c3f15bb 100644 --- a/sqlx-core/src/any/database.rs +++ b/sqlx-core/src/any/database.rs @@ -2,7 +2,7 @@ use crate::any::{ AnyArgumentBuffer, AnyArguments, AnyColumn, AnyConnection, AnyQueryResult, AnyRow, AnyStatement, AnyTransactionManager, AnyTypeInfo, AnyValue, AnyValueRef, }; -use crate::database::{Database, HasArguments, HasStatement, HasStatementCache, HasValueRef}; +use crate::database::{Database, HasStatementCache}; /// Opaque database driver. Capable of being used in place of any SQLx database driver. The actual /// driver used will be selected at runtime, from the connection url. @@ -23,30 +23,17 @@ impl Database for Any { type TypeInfo = AnyTypeInfo; type Value = AnyValue; + type ValueRef<'r> = AnyValueRef<'r>; + + type Arguments<'q> = AnyArguments<'q>; + type ArgumentBuffer<'q> = AnyArgumentBuffer<'q>; + + type Statement<'q> = AnyStatement<'q>; + const NAME: &'static str = "Any"; const URL_SCHEMES: &'static [&'static str] = &[]; } -impl<'r> HasValueRef<'r> for Any { - type Database = Any; - - type ValueRef = AnyValueRef<'r>; -} - -impl<'q> HasStatement<'q> for Any { - type Database = Any; - - type Statement = AnyStatement<'q>; -} - -impl<'q> HasArguments<'q> for Any { - type Database = Any; - - type Arguments = AnyArguments<'q>; - - type ArgumentBuffer = AnyArgumentBuffer<'q>; -} - // This _may_ be true, depending on the selected database impl HasStatementCache for Any {} diff --git a/sqlx-core/src/any/row.rs b/sqlx-core/src/any/row.rs index 23819023..18c9d57d 100644 --- a/sqlx-core/src/any/row.rs +++ b/sqlx-core/src/any/row.rs @@ -1,7 +1,7 @@ use crate::any::error::mismatched_types; use crate::any::{Any, AnyColumn, AnyTypeInfo, AnyTypeInfoKind, AnyValue, AnyValueKind}; use crate::column::{Column, ColumnIndex}; -use crate::database::{Database, HasValueRef}; +use crate::database::Database; use crate::decode::Decode; use crate::error::Error; use crate::ext::ustr::UStr; @@ -28,10 +28,7 @@ impl Row for AnyRow { &self.columns } - fn try_get_raw( - &self, - index: I, - ) -> Result<>::ValueRef, Error> + fn try_get_raw(&self, index: I) -> Result<::ValueRef<'_>, Error> where I: ColumnIndex, { @@ -141,7 +138,7 @@ impl AnyRow { } fn decode<'r, DB: Database, T: Decode<'r, DB>>( - valueref: >::ValueRef, + valueref: ::ValueRef<'r>, ) -> crate::Result { Decode::decode(valueref).map_err(Error::decode) } diff --git a/sqlx-core/src/any/types/blob.rs b/sqlx-core/src/any/types/blob.rs index 80d96026..3f33b746 100644 --- a/sqlx-core/src/any/types/blob.rs +++ b/sqlx-core/src/any/types/blob.rs @@ -1,5 +1,5 @@ use crate::any::{Any, AnyTypeInfo, AnyTypeInfoKind, AnyValueKind}; -use crate::database::{HasArguments, HasValueRef}; +use crate::database::Database; use crate::decode::Decode; use crate::encode::{Encode, IsNull}; use crate::error::BoxDynError; @@ -15,14 +15,14 @@ impl Type for [u8] { } impl<'q> Encode<'q, Any> for &'q [u8] { - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { + fn encode_by_ref(&self, buf: &mut ::ArgumentBuffer<'q>) -> IsNull { buf.0.push(AnyValueKind::Blob((*self).into())); IsNull::No } } impl<'r> Decode<'r, Any> for &'r [u8] { - fn decode(value: >::ValueRef) -> Result { + fn decode(value: ::ValueRef<'r>) -> Result { match value.kind { AnyValueKind::Blob(Cow::Borrowed(blob)) => Ok(blob), // This shouldn't happen in practice, it means the user got an `AnyValueRef` @@ -42,14 +42,14 @@ impl Type for Vec { } impl<'q> Encode<'q, Any> for Vec { - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { + fn encode_by_ref(&self, buf: &mut ::ArgumentBuffer<'q>) -> IsNull { buf.0.push(AnyValueKind::Blob(Cow::Owned(self.clone()))); IsNull::No } } impl<'r> Decode<'r, Any> for Vec { - fn decode(value: >::ValueRef) -> Result { + fn decode(value: ::ValueRef<'r>) -> Result { match value.kind { AnyValueKind::Blob(blob) => Ok(blob.into_owned()), other => other.unexpected(), diff --git a/sqlx-core/src/any/types/bool.rs b/sqlx-core/src/any/types/bool.rs index 1f2a05c9..09f7e1f7 100644 --- a/sqlx-core/src/any/types/bool.rs +++ b/sqlx-core/src/any/types/bool.rs @@ -1,5 +1,5 @@ use crate::any::{Any, AnyTypeInfo, AnyTypeInfoKind, AnyValueKind}; -use crate::database::{HasArguments, HasValueRef}; +use crate::database::Database; use crate::decode::Decode; use crate::encode::{Encode, IsNull}; use crate::error::BoxDynError; @@ -14,14 +14,14 @@ impl Type for bool { } impl<'q> Encode<'q, Any> for bool { - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { + fn encode_by_ref(&self, buf: &mut ::ArgumentBuffer<'q>) -> IsNull { buf.0.push(AnyValueKind::Bool(*self)); IsNull::No } } impl<'r> Decode<'r, Any> for bool { - fn decode(value: >::ValueRef) -> Result { + fn decode(value: ::ValueRef<'r>) -> Result { match value.kind { AnyValueKind::Bool(b) => Ok(b), other => other.unexpected(), diff --git a/sqlx-core/src/any/types/float.rs b/sqlx-core/src/any/types/float.rs index f0ba923b..47b4b24d 100644 --- a/sqlx-core/src/any/types/float.rs +++ b/sqlx-core/src/any/types/float.rs @@ -1,5 +1,5 @@ use crate::any::{Any, AnyArgumentBuffer, AnyTypeInfo, AnyTypeInfoKind, AnyValueKind, AnyValueRef}; -use crate::database::{HasArguments, HasValueRef}; +use crate::database::Database; use crate::decode::Decode; use crate::encode::{Encode, IsNull}; use crate::error::BoxDynError; @@ -38,14 +38,14 @@ impl Type for f64 { } impl<'q> Encode<'q, Any> for f64 { - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { + fn encode_by_ref(&self, buf: &mut ::ArgumentBuffer<'q>) -> IsNull { buf.0.push(AnyValueKind::Double(*self)); IsNull::No } } impl<'r> Decode<'r, Any> for f64 { - fn decode(value: >::ValueRef) -> Result { + fn decode(value: ::ValueRef<'r>) -> Result { match value.kind { // Widening is safe AnyValueKind::Real(r) => Ok(r as f64), diff --git a/sqlx-core/src/any/types/int.rs b/sqlx-core/src/any/types/int.rs index d3dfdc13..ae8d0e71 100644 --- a/sqlx-core/src/any/types/int.rs +++ b/sqlx-core/src/any/types/int.rs @@ -1,5 +1,5 @@ use crate::any::{Any, AnyTypeInfo, AnyTypeInfoKind, AnyValueKind}; -use crate::database::{HasArguments, HasValueRef}; +use crate::database::Database; use crate::decode::Decode; use crate::encode::{Encode, IsNull}; use crate::error::BoxDynError; @@ -18,14 +18,14 @@ impl Type for i16 { } impl<'q> Encode<'q, Any> for i16 { - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { + fn encode_by_ref(&self, buf: &mut ::ArgumentBuffer<'q>) -> IsNull { buf.0.push(AnyValueKind::SmallInt(*self)); IsNull::No } } impl<'r> Decode<'r, Any> for i16 { - fn decode(value: >::ValueRef) -> Result { + fn decode(value: ::ValueRef<'r>) -> Result { value.kind.try_integer() } } @@ -43,14 +43,14 @@ impl Type for i32 { } impl<'q> Encode<'q, Any> for i32 { - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { + fn encode_by_ref(&self, buf: &mut ::ArgumentBuffer<'q>) -> IsNull { buf.0.push(AnyValueKind::Integer(*self)); IsNull::No } } impl<'r> Decode<'r, Any> for i32 { - fn decode(value: >::ValueRef) -> Result { + fn decode(value: ::ValueRef<'r>) -> Result { value.kind.try_integer() } } @@ -68,14 +68,14 @@ impl Type for i64 { } impl<'q> Encode<'q, Any> for i64 { - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { + fn encode_by_ref(&self, buf: &mut ::ArgumentBuffer<'q>) -> IsNull { buf.0.push(AnyValueKind::BigInt(*self)); IsNull::No } } impl<'r> Decode<'r, Any> for i64 { - fn decode(value: >::ValueRef) -> Result { + fn decode(value: ::ValueRef<'r>) -> Result { value.kind.try_integer() } } diff --git a/sqlx-core/src/any/types/str.rs b/sqlx-core/src/any/types/str.rs index 4f519ddb..3ce6d28e 100644 --- a/sqlx-core/src/any/types/str.rs +++ b/sqlx-core/src/any/types/str.rs @@ -1,6 +1,6 @@ use crate::any::types::str; use crate::any::{Any, AnyTypeInfo, AnyTypeInfoKind, AnyValueKind}; -use crate::database::{HasArguments, HasValueRef}; +use crate::database::Database; use crate::decode::Decode; use crate::encode::{Encode, IsNull}; use crate::error::BoxDynError; @@ -16,7 +16,7 @@ impl Type for str { } impl<'a> Encode<'a, Any> for &'a str { - fn encode(self, buf: &mut >::ArgumentBuffer) -> IsNull + fn encode(self, buf: &mut ::ArgumentBuffer<'a>) -> IsNull where Self: Sized, { @@ -24,13 +24,13 @@ impl<'a> Encode<'a, Any> for &'a str { IsNull::No } - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { + fn encode_by_ref(&self, buf: &mut ::ArgumentBuffer<'a>) -> IsNull { (*self).encode(buf) } } impl<'a> Decode<'a, Any> for &'a str { - fn decode(value: >::ValueRef) -> Result { + fn decode(value: ::ValueRef<'a>) -> Result { match value.kind { AnyValueKind::Text(Cow::Borrowed(text)) => Ok(text), // This shouldn't happen in practice, it means the user got an `AnyValueRef` @@ -50,14 +50,14 @@ impl Type for String { } impl<'q> Encode<'q, Any> for String { - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { + fn encode_by_ref(&self, buf: &mut ::ArgumentBuffer<'q>) -> IsNull { buf.0.push(AnyValueKind::Text(Cow::Owned(self.clone()))); IsNull::No } } impl<'r> Decode<'r, Any> for String { - fn decode(value: >::ValueRef) -> Result { + fn decode(value: ::ValueRef<'r>) -> Result { match value.kind { AnyValueKind::Text(text) => Ok(text.into_owned()), other => other.unexpected(), diff --git a/sqlx-core/src/any/value.rs b/sqlx-core/src/any/value.rs index 075c9359..2ff63bc7 100644 --- a/sqlx-core/src/any/value.rs +++ b/sqlx-core/src/any/value.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use crate::any::{Any, AnyTypeInfo, AnyTypeInfoKind}; -use crate::database::{Database, HasValueRef}; +use crate::database::Database; use crate::error::BoxDynError; use crate::types::Type; use crate::value::{Value, ValueRef}; @@ -71,7 +71,7 @@ pub struct AnyValueRef<'a> { impl Value for AnyValue { type Database = Any; - fn as_ref(&self) -> >::ValueRef { + fn as_ref(&self) -> ::ValueRef<'_> { AnyValueRef { kind: match &self.kind { AnyValueKind::Null => AnyValueKind::Null, diff --git a/sqlx-core/src/arguments.rs b/sqlx-core/src/arguments.rs index c952d7df..d8b24d8b 100644 --- a/sqlx-core/src/arguments.rs +++ b/sqlx-core/src/arguments.rs @@ -1,6 +1,6 @@ //! Types and traits for passing arguments to SQL queries. -use crate::database::{Database, HasArguments}; +use crate::database::Database; use crate::encode::Encode; use crate::types::Type; use std::fmt::{self, Write}; @@ -23,8 +23,8 @@ pub trait Arguments<'q>: Send + Sized + Default { } } -pub trait IntoArguments<'q, DB: HasArguments<'q>>: Sized + Send { - fn into_arguments(self) -> >::Arguments; +pub trait IntoArguments<'q, DB: Database>: Sized + Send { + fn into_arguments(self) -> ::Arguments<'q>; } // NOTE: required due to lack of lazy normalization @@ -45,10 +45,10 @@ macro_rules! impl_into_arguments_for_arguments { } /// used by the query macros to prevent supernumerary `.bind()` calls -pub struct ImmutableArguments<'q, DB: HasArguments<'q>>(pub >::Arguments); +pub struct ImmutableArguments<'q, DB: Database>(pub ::Arguments<'q>); -impl<'q, DB: HasArguments<'q>> IntoArguments<'q, DB> for ImmutableArguments<'q, DB> { - fn into_arguments(self) -> >::Arguments { +impl<'q, DB: Database> IntoArguments<'q, DB> for ImmutableArguments<'q, DB> { + fn into_arguments(self) -> ::Arguments<'q> { self.0 } } diff --git a/sqlx-core/src/database.rs b/sqlx-core/src/database.rs index be629240..d17621c7 100644 --- a/sqlx-core/src/database.rs +++ b/sqlx-core/src/database.rs @@ -69,15 +69,7 @@ use crate::value::{Value, ValueRef}; /// /// This trait encapsulates a complete set of traits that implement a driver for a /// specific database (e.g., MySQL, PostgreSQL). -pub trait Database: - 'static - + Sized - + Send - + Debug - + for<'r> HasValueRef<'r, Database = Self> - + for<'q> HasArguments<'q, Database = Self> - + for<'q> HasStatement<'q, Database = Self> -{ +pub trait Database: 'static + Sized + Send + Debug { /// The concrete `Connection` implementation for this database. type Connection: Connection; @@ -99,6 +91,17 @@ pub trait Database: /// The concrete type used to hold an owned copy of the not-yet-decoded value that was /// received from the database. type Value: Value + 'static; + /// The concrete type used to hold a reference to the not-yet-decoded value that has just been + /// received from the database. + type ValueRef<'r>: ValueRef<'r, Database = Self>; + + /// The concrete `Arguments` implementation for this database. + type Arguments<'q>: Arguments<'q, Database = Self>; + /// The concrete type used as a buffer for arguments while encoding. + type ArgumentBuffer<'q>; + + /// The concrete `Statement` implementation for this database. + type Statement<'q>: Statement<'q, Database = Self>; /// The display name for this database driver. const NAME: &'static str; @@ -107,54 +110,5 @@ pub trait Database: const URL_SCHEMES: &'static [&'static str]; } -/// Associate [`Database`] with a [`ValueRef`](crate::value::ValueRef) of a generic lifetime. -/// -/// --- -/// -/// The upcoming Rust feature, [Generic Associated Types], should obviate -/// the need for this trait. -/// -/// [Generic Associated Types]: https://github.com/rust-lang/rust/issues/44265 -pub trait HasValueRef<'r> { - type Database: Database; - - /// The concrete type used to hold a reference to the not-yet-decoded value that has just been - /// received from the database. - type ValueRef: ValueRef<'r, Database = Self::Database>; -} - -/// Associate [`Database`] with an [`Arguments`](crate::arguments::Arguments) of a generic lifetime. -/// -/// --- -/// -/// The upcoming Rust feature, [Generic Associated Types], should obviate -/// the need for this trait. -/// -/// [Generic Associated Types]: https://github.com/rust-lang/rust/issues/44265 -pub trait HasArguments<'q> { - type Database: Database; - - /// The concrete `Arguments` implementation for this database. - type Arguments: Arguments<'q, Database = Self::Database>; - - /// The concrete type used as a buffer for arguments while encoding. - type ArgumentBuffer; -} - -/// Associate [`Database`] with a [`Statement`](crate::statement::Statement) of a generic lifetime. -/// -/// --- -/// -/// The upcoming Rust feature, [Generic Associated Types], should obviate -/// the need for this trait. -/// -/// [Generic Associated Types]: https://github.com/rust-lang/rust/issues/44265 -pub trait HasStatement<'q> { - type Database: Database; - - /// The concrete `Statement` implementation for this database. - type Statement: Statement<'q, Database = Self::Database>; -} - /// A [`Database`] that maintains a client-side cache of prepared statements. pub trait HasStatementCache {} diff --git a/sqlx-core/src/decode.rs b/sqlx-core/src/decode.rs index e913668e..3249c349 100644 --- a/sqlx-core/src/decode.rs +++ b/sqlx-core/src/decode.rs @@ -1,6 +1,6 @@ //! Provides [`Decode`] for decoding values from the database. -use crate::database::{Database, HasValueRef}; +use crate::database::Database; use crate::error::BoxDynError; use crate::value::ValueRef; @@ -14,10 +14,10 @@ use crate::value::ValueRef; /// /// The following showcases how to implement `Decode` to be generic over [`Database`]. The /// implementation can be marginally simpler if you remove the `DB` type parameter and explicitly -/// use the concrete [`ValueRef`](HasValueRef::ValueRef) and [`TypeInfo`](Database::TypeInfo) types. +/// use the concrete [`ValueRef`](Database::ValueRef) and [`TypeInfo`](Database::TypeInfo) types. /// /// ```rust -/// # use sqlx_core::database::{Database, HasValueRef}; +/// # use sqlx_core::database::{Database}; /// # use sqlx_core::decode::Decode; /// # use sqlx_core::types::Type; /// # use std::error::Error; @@ -42,7 +42,7 @@ use crate::value::ValueRef; /// &'r str: Decode<'r, DB> /// { /// fn decode( -/// value: >::ValueRef, +/// value: ::ValueRef<'r>, /// ) -> Result> { /// // the interface of ValueRef is largely unstable at the moment /// // so this is not directly implementable @@ -60,7 +60,7 @@ use crate::value::ValueRef; /// ``` pub trait Decode<'r, DB: Database>: Sized { /// Decode a new value of this type using a raw value from the database. - fn decode(value: >::ValueRef) -> Result; + fn decode(value: ::ValueRef<'r>) -> Result; } // implement `Decode` for Option for all SQL types @@ -69,7 +69,7 @@ where DB: Database, T: Decode<'r, DB>, { - fn decode(value: >::ValueRef) -> Result { + fn decode(value: ::ValueRef<'r>) -> Result { if value.is_null() { Ok(None) } else { diff --git a/sqlx-core/src/encode.rs b/sqlx-core/src/encode.rs index b1848beb..0ba18659 100644 --- a/sqlx-core/src/encode.rs +++ b/sqlx-core/src/encode.rs @@ -2,7 +2,7 @@ use std::mem; -use crate::database::{Database, HasArguments}; +use crate::database::Database; /// The return type of [Encode::encode]. pub enum IsNull { @@ -19,7 +19,7 @@ pub enum IsNull { pub trait Encode<'q, DB: Database> { /// Writes the value of `self` into `buf` in the expected format for the database. #[must_use] - fn encode(self, buf: &mut >::ArgumentBuffer) -> IsNull + fn encode(self, buf: &mut ::ArgumentBuffer<'q>) -> IsNull where Self: Sized, { @@ -31,7 +31,7 @@ pub trait Encode<'q, DB: Database> { /// Where possible, make use of `encode` instead as it can take advantage of re-using /// memory. #[must_use] - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull; + fn encode_by_ref(&self, buf: &mut ::ArgumentBuffer<'q>) -> IsNull; fn produces(&self) -> Option { // `produces` is inherently a hook to allow database drivers to produce value-dependent @@ -50,12 +50,12 @@ where T: Encode<'q, DB>, { #[inline] - fn encode(self, buf: &mut >::ArgumentBuffer) -> IsNull { + fn encode(self, buf: &mut ::ArgumentBuffer<'q>) -> IsNull { >::encode_by_ref(self, buf) } #[inline] - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { + fn encode_by_ref(&self, buf: &mut ::ArgumentBuffer<'q>) -> IsNull { <&T as Encode>::encode(self, buf) } @@ -89,7 +89,7 @@ macro_rules! impl_encode_for_option { #[inline] fn encode( self, - buf: &mut <$DB as $crate::database::HasArguments<'q>>::ArgumentBuffer, + buf: &mut <$DB as $crate::database::Database>::ArgumentBuffer<'q>, ) -> $crate::encode::IsNull { if let Some(v) = self { v.encode(buf) @@ -101,7 +101,7 @@ macro_rules! impl_encode_for_option { #[inline] fn encode_by_ref( &self, - buf: &mut <$DB as $crate::database::HasArguments<'q>>::ArgumentBuffer, + buf: &mut <$DB as $crate::database::Database>::ArgumentBuffer<'q>, ) -> $crate::encode::IsNull { if let Some(v) = self { v.encode_by_ref(buf) diff --git a/sqlx-core/src/executor.rs b/sqlx-core/src/executor.rs index f8222342..e3f245d9 100644 --- a/sqlx-core/src/executor.rs +++ b/sqlx-core/src/executor.rs @@ -1,4 +1,4 @@ -use crate::database::{Database, HasArguments, HasStatement}; +use crate::database::Database; use crate::describe::Describe; use crate::error::Error; @@ -149,7 +149,7 @@ pub trait Executor<'c>: Send + Debug + Sized { fn prepare<'e, 'q: 'e>( self, query: &'q str, - ) -> BoxFuture<'e, Result<>::Statement, Error>> + ) -> BoxFuture<'e, Result<::Statement<'q>, Error>> where 'c: 'e, { @@ -165,7 +165,7 @@ pub trait Executor<'c>: Send + Debug + Sized { self, sql: &'q str, parameters: &'e [::TypeInfo], - ) -> BoxFuture<'e, Result<>::Statement, Error>> + ) -> BoxFuture<'e, Result<::Statement<'q>, Error>> where 'c: 'e; @@ -195,14 +195,14 @@ pub trait Execute<'q, DB: Database>: Send + Sized { fn sql(&self) -> &'q str; /// Gets the previously cached statement, if available. - fn statement(&self) -> Option<&>::Statement>; + fn statement(&self) -> Option<&DB::Statement<'q>>; /// Returns the arguments to be bound against the query string. /// /// Returning `None` for `Arguments` indicates to use a "simple" query protocol and to not /// prepare the query. Returning `Some(Default::default())` is an empty arguments object that /// will be prepared (and cached) before execution. - fn take_arguments(&mut self) -> Option<>::Arguments>; + fn take_arguments(&mut self) -> Option<::Arguments<'q>>; /// Returns `true` if the statement should be cached. fn persistent(&self) -> bool; @@ -217,12 +217,12 @@ impl<'q, DB: Database> Execute<'q, DB> for &'q str { } #[inline] - fn statement(&self) -> Option<&>::Statement> { + fn statement(&self) -> Option<&DB::Statement<'q>> { None } #[inline] - fn take_arguments(&mut self) -> Option<>::Arguments> { + fn take_arguments(&mut self) -> Option<::Arguments<'q>> { None } @@ -232,19 +232,19 @@ impl<'q, DB: Database> Execute<'q, DB> for &'q str { } } -impl<'q, DB: Database> Execute<'q, DB> for (&'q str, Option<>::Arguments>) { +impl<'q, DB: Database> Execute<'q, DB> for (&'q str, Option<::Arguments<'q>>) { #[inline] fn sql(&self) -> &'q str { self.0 } #[inline] - fn statement(&self) -> Option<&>::Statement> { + fn statement(&self) -> Option<&DB::Statement<'q>> { None } #[inline] - fn take_arguments(&mut self) -> Option<>::Arguments> { + fn take_arguments(&mut self) -> Option<::Arguments<'q>> { self.1.take() } diff --git a/sqlx-core/src/pool/executor.rs b/sqlx-core/src/pool/executor.rs index c5c7acdd..edfaa84b 100644 --- a/sqlx-core/src/pool/executor.rs +++ b/sqlx-core/src/pool/executor.rs @@ -3,7 +3,7 @@ use futures_core::future::BoxFuture; use futures_core::stream::BoxStream; use futures_util::TryStreamExt; -use crate::database::{Database, HasStatement}; +use crate::database::Database; use crate::describe::Describe; use crate::error::Error; use crate::executor::{Execute, Executor}; @@ -52,7 +52,7 @@ where self, sql: &'q str, parameters: &'e [::TypeInfo], - ) -> BoxFuture<'e, Result<>::Statement, Error>> { + ) -> BoxFuture<'e, Result<::Statement<'q>, Error>> { let pool = self.clone(); Box::pin(async move { pool.acquire().await?.prepare_with(sql, parameters).await }) @@ -117,7 +117,7 @@ where // parameters: &'e [::TypeInfo], // ) -> futures_core::future::BoxFuture< // 'e, -// Result<>::Statement, crate::error::Error>, +// Result<::Statement<'q>, crate::error::Error>, // > // where // 'c: 'e, diff --git a/sqlx-core/src/query.rs b/sqlx-core/src/query.rs index 005c0eb4..47d884a7 100644 --- a/sqlx-core/src/query.rs +++ b/sqlx-core/src/query.rs @@ -5,7 +5,7 @@ use futures_core::stream::BoxStream; use futures_util::{future, StreamExt, TryFutureExt, TryStreamExt}; use crate::arguments::{Arguments, IntoArguments}; -use crate::database::{Database, HasArguments, HasStatement, HasStatementCache}; +use crate::database::{Database, HasStatementCache}; use crate::encode::Encode; use crate::error::Error; use crate::executor::{Execute, Executor}; @@ -15,7 +15,7 @@ use crate::types::Type; /// A single SQL query as a prepared statement. Returned by [`query()`]. #[must_use = "query must be executed to affect database"] pub struct Query<'q, DB: Database, A> { - pub(crate) statement: Either<&'q str, &'q >::Statement>, + pub(crate) statement: Either<&'q str, &'q DB::Statement<'q>>, pub(crate) arguments: Option, pub(crate) database: PhantomData, pub(crate) persistent: bool, @@ -51,7 +51,7 @@ where } } - fn statement(&self) -> Option<&>::Statement> { + fn statement(&self) -> Option<&DB::Statement<'q>> { match self.statement { Either::Right(ref statement) => Some(&statement), Either::Left(_) => None, @@ -59,7 +59,7 @@ where } #[inline] - fn take_arguments(&mut self) -> Option<>::Arguments> { + fn take_arguments(&mut self) -> Option<::Arguments<'q>> { self.arguments.take().map(IntoArguments::into_arguments) } @@ -69,7 +69,7 @@ where } } -impl<'q, DB: Database> Query<'q, DB, >::Arguments> { +impl<'q, DB: Database> Query<'q, DB, ::Arguments<'q>> { /// Bind a value for use with this SQL query. /// /// If the number of times this is called does not match the number of bind parameters that @@ -275,12 +275,12 @@ where } #[inline] - fn statement(&self) -> Option<&>::Statement> { + fn statement(&self) -> Option<&DB::Statement<'q>> { self.inner.statement() } #[inline] - fn take_arguments(&mut self) -> Option<>::Arguments> { + fn take_arguments(&mut self) -> Option<::Arguments<'q>> { self.inner.take_arguments() } @@ -465,8 +465,8 @@ where /// Execute a single SQL query as a prepared statement (explicitly created). pub fn query_statement<'q, DB>( - statement: &'q >::Statement, -) -> Query<'q, DB, >::Arguments> + statement: &'q DB::Statement<'q>, +) -> Query<'q, DB, ::Arguments<'_>> where DB: Database, { @@ -480,7 +480,7 @@ where /// Execute a single SQL query as a prepared statement (explicitly created), with the given arguments. pub fn query_statement_with<'q, DB, A>( - statement: &'q >::Statement, + statement: &'q DB::Statement<'q>, arguments: A, ) -> Query<'q, DB, A> where @@ -525,6 +525,7 @@ where /// // where `conn` is `PgConnection` or `MySqlConnection` /// // or some other type that implements `Executor`. /// let results = sqlx::query(&query).fetch_all(&mut conn).await?; +/// # Ok(()) /// # } /// ``` /// @@ -618,7 +619,7 @@ where /// /// As an additional benefit, query parameters are usually sent in a compact binary encoding instead of a human-readable /// text encoding, which saves bandwidth. -pub fn query(sql: &str) -> Query<'_, DB, >::Arguments> +pub fn query(sql: &str) -> Query<'_, DB, ::Arguments<'_>> where DB: Database, { diff --git a/sqlx-core/src/query_as.rs b/sqlx-core/src/query_as.rs index 0ec714c7..88714ea9 100644 --- a/sqlx-core/src/query_as.rs +++ b/sqlx-core/src/query_as.rs @@ -5,7 +5,7 @@ use futures_core::stream::BoxStream; use futures_util::{StreamExt, TryStreamExt}; use crate::arguments::IntoArguments; -use crate::database::{Database, HasArguments, HasStatement, HasStatementCache}; +use crate::database::{Database, HasStatementCache}; use crate::encode::Encode; use crate::error::Error; use crate::executor::{Execute, Executor}; @@ -32,12 +32,12 @@ where } #[inline] - fn statement(&self) -> Option<&>::Statement> { + fn statement(&self) -> Option<&DB::Statement<'q>> { self.inner.statement() } #[inline] - fn take_arguments(&mut self) -> Option<>::Arguments> { + fn take_arguments(&mut self) -> Option<::Arguments<'q>> { self.inner.take_arguments() } @@ -47,7 +47,7 @@ where } } -impl<'q, DB: Database, O> QueryAs<'q, DB, O, >::Arguments> { +impl<'q, DB: Database, O> QueryAs<'q, DB, O, ::Arguments<'q>> { /// Bind a value for use with this SQL query. /// /// See [`Query::bind`](Query::bind). @@ -339,7 +339,7 @@ where /// /// ``` #[inline] -pub fn query_as<'q, DB, O>(sql: &'q str) -> QueryAs<'q, DB, O, >::Arguments> +pub fn query_as<'q, DB, O>(sql: &'q str) -> QueryAs<'q, DB, O, ::Arguments<'q>> where DB: Database, O: for<'r> FromRow<'r, DB::Row>, @@ -371,8 +371,8 @@ where // Make a SQL query from a statement, that is mapped to a concrete type. pub fn query_statement_as<'q, DB, O>( - statement: &'q >::Statement, -) -> QueryAs<'q, DB, O, >::Arguments> + statement: &'q DB::Statement<'q>, +) -> QueryAs<'q, DB, O, ::Arguments<'_>> where DB: Database, O: for<'r> FromRow<'r, DB::Row>, @@ -385,7 +385,7 @@ where // Make a SQL query from a statement, with the given arguments, that is mapped to a concrete type. pub fn query_statement_as_with<'q, DB, O, A>( - statement: &'q >::Statement, + statement: &'q DB::Statement<'q>, arguments: A, ) -> QueryAs<'q, DB, O, A> where diff --git a/sqlx-core/src/query_builder.rs b/sqlx-core/src/query_builder.rs index 75c2bd99..2c9dba59 100644 --- a/sqlx-core/src/query_builder.rs +++ b/sqlx-core/src/query_builder.rs @@ -5,7 +5,7 @@ use std::fmt::Write; use std::marker::PhantomData; use crate::arguments::{Arguments, IntoArguments}; -use crate::database::{Database, HasArguments}; +use crate::database::Database; use crate::encode::Encode; use crate::from_row::FromRow; use crate::query::Query; @@ -27,7 +27,7 @@ where { query: String, init_len: usize, - arguments: Option<>::Arguments>, + arguments: Option<::Arguments<'args>>, } impl<'args, DB: Database> Default for QueryBuilder<'args, DB> { @@ -49,7 +49,7 @@ where /// Start building a query with an initial SQL fragment, which may be an empty string. pub fn new(init: impl Into) -> Self where - >::Arguments: Default, + ::Arguments<'args>: Default, { let init = init.into(); @@ -445,7 +445,7 @@ where /// to the state it was in immediately after [`new()`][Self::new]. /// /// Calling any other method but `.reset()` after `.build()` will panic for sanity reasons. - pub fn build(&mut self) -> Query<'_, DB, >::Arguments> { + pub fn build(&mut self) -> Query<'_, DB, ::Arguments<'args>> { self.sanity_check(); Query { @@ -470,7 +470,7 @@ where /// Calling any other method but `.reset()` after `.build()` will panic for sanity reasons. pub fn build_query_as<'q, T: FromRow<'q, DB::Row>>( &'q mut self, - ) -> QueryAs<'q, DB, T, >::Arguments> { + ) -> QueryAs<'q, DB, T, ::Arguments<'args>> { QueryAs { inner: self.build(), output: PhantomData, @@ -491,7 +491,7 @@ where /// Calling any other method but `.reset()` after `.build()` will panic for sanity reasons. pub fn build_query_scalar<'q, T>( &'q mut self, - ) -> QueryScalar<'q, DB, T, >::Arguments> + ) -> QueryScalar<'q, DB, T, ::Arguments<'args>> where DB: Database, (T,): for<'r> FromRow<'r, DB::Row>, diff --git a/sqlx-core/src/query_scalar.rs b/sqlx-core/src/query_scalar.rs index 9280056e..509d7e6c 100644 --- a/sqlx-core/src/query_scalar.rs +++ b/sqlx-core/src/query_scalar.rs @@ -3,7 +3,7 @@ use futures_core::stream::BoxStream; use futures_util::{StreamExt, TryFutureExt, TryStreamExt}; use crate::arguments::IntoArguments; -use crate::database::{Database, HasArguments, HasStatement, HasStatementCache}; +use crate::database::{Database, HasStatementCache}; use crate::encode::Encode; use crate::error::Error; use crate::executor::{Execute, Executor}; @@ -29,12 +29,12 @@ where self.inner.sql() } - fn statement(&self) -> Option<&>::Statement> { + fn statement(&self) -> Option<&DB::Statement<'q>> { self.inner.statement() } #[inline] - fn take_arguments(&mut self) -> Option<>::Arguments> { + fn take_arguments(&mut self) -> Option<::Arguments<'q>> { self.inner.take_arguments() } @@ -44,7 +44,7 @@ where } } -impl<'q, DB: Database, O> QueryScalar<'q, DB, O, >::Arguments> { +impl<'q, DB: Database, O> QueryScalar<'q, DB, O, ::Arguments<'q>> { /// Bind a value for use with this SQL query. /// /// See [`Query::bind`](crate::query::Query::bind). @@ -320,7 +320,7 @@ where #[inline] pub fn query_scalar<'q, DB, O>( sql: &'q str, -) -> QueryScalar<'q, DB, O, >::Arguments> +) -> QueryScalar<'q, DB, O, ::Arguments<'q>> where DB: Database, (O,): for<'r> FromRow<'r, DB::Row>, @@ -350,8 +350,8 @@ where // Make a SQL query from a statement, that is mapped to a concrete value. pub fn query_statement_scalar<'q, DB, O>( - statement: &'q >::Statement, -) -> QueryScalar<'q, DB, O, >::Arguments> + statement: &'q DB::Statement<'q>, +) -> QueryScalar<'q, DB, O, ::Arguments<'_>> where DB: Database, (O,): for<'r> FromRow<'r, DB::Row>, @@ -363,7 +363,7 @@ where // Make a SQL query from a statement, with the given arguments, that is mapped to a concrete value. pub fn query_statement_scalar_with<'q, DB, O, A>( - statement: &'q >::Statement, + statement: &'q DB::Statement<'q>, arguments: A, ) -> QueryScalar<'q, DB, O, A> where diff --git a/sqlx-core/src/raw_sql.rs b/sqlx-core/src/raw_sql.rs index 48162f2c..5617bfee 100644 --- a/sqlx-core/src/raw_sql.rs +++ b/sqlx-core/src/raw_sql.rs @@ -1,9 +1,10 @@ -use crate::database::{Database, HasArguments, HasStatement}; -use crate::executor::{Execute, Executor}; -use crate::Error; use either::Either; use futures_core::stream::BoxStream; +use crate::database::Database; +use crate::executor::{Execute, Executor}; +use crate::Error; + // AUTHOR'S NOTE: I was just going to call this API `sql()` and `Sql`, respectively, // but realized that would be extremely annoying to deal with as a SQLite user // because IDE smart completion would always recommend the `Sql` type first. @@ -121,11 +122,11 @@ impl<'q, DB: Database> Execute<'q, DB> for RawSql<'q> { self.0 } - fn statement(&self) -> Option<&>::Statement> { + fn statement(&self) -> Option<&::Statement<'q>> { None } - fn take_arguments(&mut self) -> Option<>::Arguments> { + fn take_arguments(&mut self) -> Option<::Arguments<'q>> { None } diff --git a/sqlx-core/src/row.rs b/sqlx-core/src/row.rs index ec7ca7ec..5923e25c 100644 --- a/sqlx-core/src/row.rs +++ b/sqlx-core/src/row.rs @@ -1,5 +1,5 @@ use crate::column::ColumnIndex; -use crate::database::{Database, HasValueRef}; +use crate::database::Database; use crate::decode::Decode; use crate::error::{mismatched_types, Error}; @@ -171,10 +171,7 @@ pub trait Row: Unpin + Send + Sync + 'static { /// [`ColumnNotFound`]: Error::ColumnNotFound /// [`ColumnIndexOutOfBounds`]: Error::ColumnIndexOutOfBounds /// - fn try_get_raw( - &self, - index: I, - ) -> Result<>::ValueRef, Error> + fn try_get_raw(&self, index: I) -> Result<::ValueRef<'_>, Error> where I: ColumnIndex; } diff --git a/sqlx-core/src/statement.rs b/sqlx-core/src/statement.rs index 83079a46..17dfd642 100644 --- a/sqlx-core/src/statement.rs +++ b/sqlx-core/src/statement.rs @@ -1,6 +1,6 @@ use crate::arguments::IntoArguments; use crate::column::ColumnIndex; -use crate::database::{Database, HasArguments, HasStatement}; +use crate::database::Database; use crate::error::Error; use crate::from_row::FromRow; use crate::query::Query; @@ -21,7 +21,7 @@ pub trait Statement<'q>: Send + Sync { /// Creates an owned statement from this statement reference. This copies /// the original SQL text. - fn to_owned(&self) -> >::Statement; + fn to_owned(&self) -> ::Statement<'static>; /// Get the original SQL text used to create this statement. fn sql(&self) -> &str; @@ -59,7 +59,7 @@ pub trait Statement<'q>: Send + Sync { Ok(&self.columns()[index.index(self)?]) } - fn query(&self) -> Query<'_, Self::Database, >::Arguments>; + fn query(&self) -> Query<'_, Self::Database, ::Arguments<'_>>; fn query_with<'s, A>(&'s self, arguments: A) -> Query<'s, Self::Database, A> where @@ -67,7 +67,7 @@ pub trait Statement<'q>: Send + Sync { fn query_as( &self, - ) -> QueryAs<'_, Self::Database, O, >::Arguments> + ) -> QueryAs<'_, Self::Database, O, ::Arguments<'_>> where O: for<'r> FromRow<'r, ::Row>; @@ -78,7 +78,7 @@ pub trait Statement<'q>: Send + Sync { fn query_scalar( &self, - ) -> QueryScalar<'_, Self::Database, O, >::Arguments> + ) -> QueryScalar<'_, Self::Database, O, ::Arguments<'_>> where (O,): for<'r> FromRow<'r, ::Row>; @@ -111,7 +111,7 @@ macro_rules! impl_statement_query { '_, Self::Database, O, - >::Arguments, + ::Arguments<'_>, > where O: for<'r> $crate::from_row::FromRow< @@ -144,7 +144,7 @@ macro_rules! impl_statement_query { '_, Self::Database, O, - >::Arguments, + ::Arguments<'_>, > where (O,): for<'r> $crate::from_row::FromRow< diff --git a/sqlx-core/src/testing/fixtures.rs b/sqlx-core/src/testing/fixtures.rs index fc44e5bf..58945d85 100644 --- a/sqlx-core/src/testing/fixtures.rs +++ b/sqlx-core/src/testing/fixtures.rs @@ -1,6 +1,6 @@ //! TODO: automatic test fixture capture -use crate::database::{Database, HasArguments}; +use crate::database::Database; use crate::query_builder::QueryBuilder; @@ -111,7 +111,7 @@ impl FixtureSnapshot { /// which appends to an internal string. impl ToString for Fixture where - for<'a> >::Arguments: Default, + for<'a> ::Arguments<'a>: Default, { fn to_string(&self) -> String { let mut query = QueryBuilder::::new(""); diff --git a/sqlx-core/src/transaction.rs b/sqlx-core/src/transaction.rs index 0516b6ad..e8e83df0 100644 --- a/sqlx-core/src/transaction.rs +++ b/sqlx-core/src/transaction.rs @@ -140,7 +140,7 @@ where // ) -> futures_core::future::BoxFuture< // 'e, // Result< -// >::Statement, +// ::Statement<'q>, // crate::error::Error, // >, // > diff --git a/sqlx-core/src/types/bstr.rs b/sqlx-core/src/types/bstr.rs index bb3a3b88..ef571a9b 100644 --- a/sqlx-core/src/types/bstr.rs +++ b/sqlx-core/src/types/bstr.rs @@ -1,5 +1,5 @@ /// Conversions between `bstr` types and SQL types. -use crate::database::{Database, HasArguments, HasValueRef}; +use crate::database::Database; use crate::decode::Decode; use crate::encode::{Encode, IsNull}; use crate::error::BoxDynError; @@ -27,7 +27,7 @@ where DB: Database, Vec: Decode<'r, DB>, { - fn decode(value: >::ValueRef) -> Result { + fn decode(value: ::ValueRef<'r>) -> Result { as Decode>::decode(value).map(BString::from) } } @@ -37,7 +37,7 @@ where DB: Database, &'q [u8]: Encode<'q, DB>, { - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { + fn encode_by_ref(&self, buf: &mut ::ArgumentBuffer<'q>) -> IsNull { <&[u8] as Encode>::encode(self.as_bytes(), buf) } } @@ -47,7 +47,7 @@ where DB: Database, Vec: Encode<'q, DB>, { - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { + fn encode_by_ref(&self, buf: &mut ::ArgumentBuffer<'q>) -> IsNull { as Encode>::encode(self.as_bytes().to_vec(), buf) } } diff --git a/sqlx-core/src/types/json.rs b/sqlx-core/src/types/json.rs index d1c8c0ec..f2b58e70 100644 --- a/sqlx-core/src/types/json.rs +++ b/sqlx-core/src/types/json.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; pub use serde_json::value::RawValue as JsonRawValue; pub use serde_json::Value as JsonValue; -use crate::database::{Database, HasArguments, HasValueRef}; +use crate::database::Database; use crate::decode::Decode; use crate::encode::{Encode, IsNull}; use crate::error::BoxDynError; @@ -141,7 +141,7 @@ where for<'a> Json<&'a Self>: Encode<'q, DB>, DB: Database, { - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { + fn encode_by_ref(&self, buf: &mut ::ArgumentBuffer<'q>) -> IsNull { as Encode<'q, DB>>::encode(Json(self), buf) } } @@ -151,7 +151,7 @@ where Json: Decode<'r, DB>, DB: Database, { - fn decode(value: >::ValueRef) -> Result { + fn decode(value: ::ValueRef<'r>) -> Result { as Decode>::decode(value).map(|item| item.0) } } @@ -177,7 +177,7 @@ where Json: Decode<'r, DB>, DB: Database, { - fn decode(value: >::ValueRef) -> Result { + fn decode(value: ::ValueRef<'r>) -> Result { as Decode>::decode(value).map(|item| item.0) } } diff --git a/sqlx-core/src/types/text.rs b/sqlx-core/src/types/text.rs index 90480e6d..9ef865ad 100644 --- a/sqlx-core/src/types/text.rs +++ b/sqlx-core/src/types/text.rs @@ -115,7 +115,7 @@ where String: Encode<'q, DB>, DB: Database, { - fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { + fn encode_by_ref(&self, buf: &mut ::ArgumentBuffer<'q>) -> IsNull { self.0.to_string().encode(buf) } } @@ -127,7 +127,7 @@ where &'r str: Decode<'r, DB>, DB: Database, { - fn decode(value: >::ValueRef) -> Result { + fn decode(value: ::ValueRef<'r>) -> Result { Ok(Text(<&'r str as Decode<'r, DB>>::decode(value)?.parse()?)) } } diff --git a/sqlx-core/src/value.rs b/sqlx-core/src/value.rs index 0176e8d1..d7996561 100644 --- a/sqlx-core/src/value.rs +++ b/sqlx-core/src/value.rs @@ -1,4 +1,4 @@ -use crate::database::{Database, HasValueRef}; +use crate::database::Database; use crate::decode::Decode; use crate::error::{mismatched_types, Error}; use crate::type_info::TypeInfo; @@ -10,7 +10,7 @@ pub trait Value { type Database: Database; /// Get this value as a reference. - fn as_ref(&self) -> >::ValueRef; + fn as_ref(&self) -> ::ValueRef<'_>; /// Get the type information for this value. fn type_info(&self) -> Cow<'_, ::TypeInfo>; diff --git a/sqlx-macros-core/src/derives/decode.rs b/sqlx-macros-core/src/derives/decode.rs index f926718f..78ce45a7 100644 --- a/sqlx-macros-core/src/derives/decode.rs +++ b/sqlx-macros-core/src/derives/decode.rs @@ -76,7 +76,7 @@ fn expand_derive_decode_transparent( #[automatically_derived] impl #impl_generics ::sqlx::decode::Decode<'r, DB> for #ident #ty_generics #where_clause { fn decode( - value: >::ValueRef, + value: ::ValueRef<'r>, ) -> ::std::result::Result< Self, ::std::boxed::Box< @@ -118,7 +118,7 @@ fn expand_derive_decode_weak_enum( #repr: ::sqlx::decode::Decode<'r, DB>, { fn decode( - value: >::ValueRef, + value: ::ValueRef<'r>, ) -> ::std::result::Result< Self, ::std::boxed::Box< diff --git a/sqlx-macros-core/src/derives/encode.rs b/sqlx-macros-core/src/derives/encode.rs index 823af65a..df370717 100644 --- a/sqlx-macros-core/src/derives/encode.rs +++ b/sqlx-macros-core/src/derives/encode.rs @@ -84,7 +84,7 @@ fn expand_derive_encode_transparent( { fn encode_by_ref( &self, - buf: &mut >::ArgumentBuffer, + buf: &mut ::ArgumentBuffer<#lifetime>, ) -> ::sqlx::encode::IsNull { <#ty as ::sqlx::encode::Encode<#lifetime, DB>>::encode_by_ref(&self.0, buf) } @@ -123,7 +123,7 @@ fn expand_derive_encode_weak_enum( { fn encode_by_ref( &self, - buf: &mut >::ArgumentBuffer, + buf: &mut ::ArgumentBuffer<'q>, ) -> ::sqlx::encode::IsNull { let value = match self { #(#values)* @@ -173,7 +173,7 @@ fn expand_derive_encode_strong_enum( { fn encode_by_ref( &self, - buf: &mut >::ArgumentBuffer, + buf: &mut ::ArgumentBuffer<'q>, ) -> ::sqlx::encode::IsNull { let val = match self { #(#value_arms)* diff --git a/sqlx-macros-core/src/query/args.rs b/sqlx-macros-core/src/query/args.rs index 194a444a..579309c4 100644 --- a/sqlx-macros-core/src/query/args.rs +++ b/sqlx-macros-core/src/query/args.rs @@ -17,7 +17,7 @@ pub fn quote_args( if input.arg_exprs.is_empty() { return Ok(quote! { - let query_args = <#db_path as ::sqlx::database::HasArguments>::Arguments::default(); + let query_args = <#db_path as ::sqlx::database::Database>::Arguments::<'_>::default(); }); } @@ -104,7 +104,7 @@ pub fn quote_args( #args_check - let mut query_args = <#db_path as ::sqlx::database::HasArguments>::Arguments::default(); + let mut query_args = <#db_path as ::sqlx::database::Database>::Arguments::<'_>::default(); query_args.reserve( #args_count, 0 #(+ ::sqlx::encode::Encode::<#db_path>::size_hint(#arg_name))* diff --git a/sqlx-mysql/src/database.rs b/sqlx-mysql/src/database.rs index 08040d27..d03a5672 100644 --- a/sqlx-mysql/src/database.rs +++ b/sqlx-mysql/src/database.rs @@ -3,9 +3,7 @@ use crate::{ MySqlArguments, MySqlColumn, MySqlConnection, MySqlQueryResult, MySqlRow, MySqlStatement, MySqlTransactionManager, MySqlTypeInfo, }; -pub(crate) use sqlx_core::database::{ - Database, HasArguments, HasStatement, HasStatementCache, HasValueRef, -}; +pub(crate) use sqlx_core::database::{Database, HasStatementCache}; /// MySQL database driver. #[derive(Debug)] @@ -25,30 +23,16 @@ impl Database for MySql { type TypeInfo = MySqlTypeInfo; type Value = MySqlValue; + type ValueRef<'r> = MySqlValueRef<'r>; + + type Arguments<'q> = MySqlArguments; + type ArgumentBuffer<'q> = Vec; + + type Statement<'q> = MySqlStatement<'q>; const NAME: &'static str = "MySQL"; const URL_SCHEMES: &'static [&'static str] = &["mysql", "mariadb"]; } -impl<'r> HasValueRef<'r> for MySql { - type Database = MySql; - - type ValueRef = MySqlValueRef<'r>; -} - -impl HasArguments<'_> for MySql { - type Database = MySql; - - type Arguments = MySqlArguments; - - type ArgumentBuffer = Vec; -} - -impl<'q> HasStatement<'q> for MySql { - type Database = MySql; - - type Statement = MySqlStatement<'q>; -} - impl HasStatementCache for MySql {} diff --git a/sqlx-postgres/src/database.rs b/sqlx-postgres/src/database.rs index c082aafe..876e2958 100644 --- a/sqlx-postgres/src/database.rs +++ b/sqlx-postgres/src/database.rs @@ -5,9 +5,7 @@ use crate::{ PgTypeInfo, }; -pub(crate) use sqlx_core::database::{ - Database, HasArguments, HasStatement, HasStatementCache, HasValueRef, -}; +pub(crate) use sqlx_core::database::{Database, HasStatementCache}; /// PostgreSQL database driver. #[derive(Debug)] @@ -27,30 +25,16 @@ impl Database for Postgres { type TypeInfo = PgTypeInfo; type Value = PgValue; + type ValueRef<'r> = PgValueRef<'r>; + + type Arguments<'q> = PgArguments; + type ArgumentBuffer<'q> = PgArgumentBuffer; + + type Statement<'q> = PgStatement<'q>; const NAME: &'static str = "PostgreSQL"; const URL_SCHEMES: &'static [&'static str] = &["postgres", "postgresql"]; } -impl<'r> HasValueRef<'r> for Postgres { - type Database = Postgres; - - type ValueRef = PgValueRef<'r>; -} - -impl HasArguments<'_> for Postgres { - type Database = Postgres; - - type Arguments = PgArguments; - - type ArgumentBuffer = PgArgumentBuffer; -} - -impl<'q> HasStatement<'q> for Postgres { - type Database = Postgres; - - type Statement = PgStatement<'q>; -} - impl HasStatementCache for Postgres {} diff --git a/sqlx-sqlite/src/database.rs b/sqlx-sqlite/src/database.rs index 739200fa..c89c7b83 100644 --- a/sqlx-sqlite/src/database.rs +++ b/sqlx-sqlite/src/database.rs @@ -1,6 +1,4 @@ -pub(crate) use sqlx_core::database::{ - Database, HasArguments, HasStatement, HasStatementCache, HasValueRef, -}; +pub(crate) use sqlx_core::database::{Database, HasStatementCache}; use crate::{ SqliteArgumentValue, SqliteArguments, SqliteColumn, SqliteConnection, SqliteQueryResult, @@ -26,30 +24,16 @@ impl Database for Sqlite { type TypeInfo = SqliteTypeInfo; type Value = SqliteValue; + type ValueRef<'r> = SqliteValueRef<'r>; + + type Arguments<'q> = SqliteArguments<'q>; + type ArgumentBuffer<'q> = Vec>; + + type Statement<'q> = SqliteStatement<'q>; const NAME: &'static str = "SQLite"; const URL_SCHEMES: &'static [&'static str] = &["sqlite"]; } -impl<'r> HasValueRef<'r> for Sqlite { - type Database = Sqlite; - - type ValueRef = SqliteValueRef<'r>; -} - -impl<'q> HasArguments<'q> for Sqlite { - type Database = Sqlite; - - type Arguments = SqliteArguments<'q>; - - type ArgumentBuffer = Vec>; -} - -impl<'q> HasStatement<'q> for Sqlite { - type Database = Sqlite; - - type Statement = SqliteStatement<'q>; -} - impl HasStatementCache for Sqlite {}