From d5d418396df60c0c21efe4161087b25f0ede9601 Mon Sep 17 00:00:00 2001 From: Valentin Leistner Date: Sun, 7 Jan 2024 22:40:38 +0100 Subject: [PATCH] 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` --- sqlx-core/src/any/database.rs | 27 +++------- 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 | 68 +++++--------------------- 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 | 22 ++++----- sqlx-core/src/query_as.rs | 16 +++--- sqlx-core/src/query_builder.rs | 12 ++--- sqlx-core/src/query_scalar.rs | 16 +++--- 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 +++--------- 32 files changed, 164 insertions(+), 277 deletions(-) diff --git a/sqlx-core/src/any/database.rs b/sqlx-core/src/any/database.rs index 1a57a77e2e..9c3f15bb1f 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,29 +23,16 @@ impl Database for Any { type TypeInfo = AnyTypeInfo; type Value = AnyValue; - const NAME: &'static str = "Any"; - - const URL_SCHEMES: &'static [&'static str] = &[]; -} - -impl<'r> HasValueRef<'r> for Any { - type Database = Any; + type ValueRef<'r> = AnyValueRef<'r>; - type ValueRef = AnyValueRef<'r>; -} + type Arguments<'q> = AnyArguments<'q>; + type ArgumentBuffer<'q> = AnyArgumentBuffer<'q>; -impl<'q> HasStatement<'q> for Any { - type Database = Any; + type Statement<'q> = AnyStatement<'q>; - type Statement = AnyStatement<'q>; -} - -impl<'q> HasArguments<'q> for Any { - type Database = Any; - - type Arguments = AnyArguments<'q>; + const NAME: &'static str = "Any"; - type ArgumentBuffer = AnyArgumentBuffer<'q>; + const URL_SCHEMES: &'static [&'static str] = &[]; } // This _may_ be true, depending on the selected database diff --git a/sqlx-core/src/any/row.rs b/sqlx-core/src/any/row.rs index 2381902311..18c9d57daa 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 80d9602694..3f33b746f7 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 1f2a05c91a..09f7e1f792 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 f0ba923b7a..47b4b24d36 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 d3dfdc136e..ae8d0e71f0 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 4f519ddbc3..3ce6d28e57 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 075c935929..2ff63bc7d5 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 c952d7df9f..d8b24d8b9e 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 be62924077..d17621c719 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,61 +91,23 @@ 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 display name for this database driver. - const NAME: &'static str; - - /// The schemes for database URLs that should match this driver. - 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; + type ValueRef<'r>: ValueRef<'r, Database = Self>; /// The concrete `Arguments` implementation for this database. - type Arguments: Arguments<'q, Database = Self::Database>; - + type Arguments<'q>: Arguments<'q, Database = Self>; /// 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; + type ArgumentBuffer<'q>; /// The concrete `Statement` implementation for this database. - type Statement: Statement<'q, Database = Self::Database>; + type Statement<'q>: Statement<'q, Database = Self>; + + /// The display name for this database driver. + const NAME: &'static str; + + /// The schemes for database URLs that should match this driver. + const URL_SCHEMES: &'static [&'static str]; } /// A [`Database`] that maintains a client-side cache of prepared statements. diff --git a/sqlx-core/src/decode.rs b/sqlx-core/src/decode.rs index e913668e07..3249c349cc 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 b1848bebc4..0ba1865947 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 f8222342e4..e3f245d923 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 c5c7acdd39..edfaa84b73 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 2d7a1c9b15..413a9f5f1c 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; /// Raw SQL query with bind parameters. Returned by [`query`][crate::query::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, @@ -49,7 +49,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, @@ -57,7 +57,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) } @@ -67,7 +67,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 @@ -238,12 +238,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() } @@ -396,8 +396,8 @@ where // Make a SQL query from a statement. 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, { @@ -411,7 +411,7 @@ where // Make a SQL query from a statement, 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 @@ -427,7 +427,7 @@ where } /// Make a SQL query. -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 43a611cf65..ebea743f03 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). @@ -168,7 +168,7 @@ where /// Make a SQL query that is mapped to a concrete type /// using [`FromRow`]. #[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>, @@ -196,8 +196,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>, @@ -210,7 +210,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 75c2bd995c..2c9dba591f 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 0ef8cbde30..3a7e0f6d94 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). @@ -163,7 +163,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>, @@ -189,8 +189,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>, @@ -202,7 +202,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/row.rs b/sqlx-core/src/row.rs index ec7ca7ec16..5923e25c03 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 83079a46a4..17dfd6428d 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 fc44e5bf75..58945d859f 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 0516b6adc3..e8e83df0f7 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 bb3a3b883d..ef571a9bf8 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 d1c8c0ec0d..f2b58e70af 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 90480e6db7..9ef865ad06 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 0176e8d12a..d7996561b7 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 f926718f6c..78ce45a79d 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 7bb568210f..cddd79569c 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 3a07b1b303..f6b9b08bea 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(); }); } @@ -107,7 +107,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 08040d2783..d03a567284 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>; - const NAME: &'static str = "MySQL"; + type Arguments<'q> = MySqlArguments; + type ArgumentBuffer<'q> = Vec; - const URL_SCHEMES: &'static [&'static str] = &["mysql", "mariadb"]; -} - -impl<'r> HasValueRef<'r> for MySql { - type Database = MySql; - - type ValueRef = MySqlValueRef<'r>; -} + type Statement<'q> = MySqlStatement<'q>; -impl HasArguments<'_> for MySql { - type Database = MySql; - - type Arguments = MySqlArguments; - - type ArgumentBuffer = Vec; -} - -impl<'q> HasStatement<'q> for MySql { - type Database = MySql; + const NAME: &'static str = "MySQL"; - type Statement = MySqlStatement<'q>; + const URL_SCHEMES: &'static [&'static str] = &["mysql", "mariadb"]; } impl HasStatementCache for MySql {} diff --git a/sqlx-postgres/src/database.rs b/sqlx-postgres/src/database.rs index c082aafe5f..876e295899 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>; - const NAME: &'static str = "PostgreSQL"; + type Arguments<'q> = PgArguments; + type ArgumentBuffer<'q> = PgArgumentBuffer; - const URL_SCHEMES: &'static [&'static str] = &["postgres", "postgresql"]; -} - -impl<'r> HasValueRef<'r> for Postgres { - type Database = Postgres; - - type ValueRef = PgValueRef<'r>; -} + type Statement<'q> = PgStatement<'q>; -impl HasArguments<'_> for Postgres { - type Database = Postgres; - - type Arguments = PgArguments; - - type ArgumentBuffer = PgArgumentBuffer; -} - -impl<'q> HasStatement<'q> for Postgres { - type Database = Postgres; + const NAME: &'static str = "PostgreSQL"; - type Statement = PgStatement<'q>; + const URL_SCHEMES: &'static [&'static str] = &["postgres", "postgresql"]; } impl HasStatementCache for Postgres {} diff --git a/sqlx-sqlite/src/database.rs b/sqlx-sqlite/src/database.rs index 739200fa9f..c89c7b8322 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>; - const NAME: &'static str = "SQLite"; + type Arguments<'q> = SqliteArguments<'q>; + type ArgumentBuffer<'q> = Vec>; - const URL_SCHEMES: &'static [&'static str] = &["sqlite"]; -} - -impl<'r> HasValueRef<'r> for Sqlite { - type Database = Sqlite; - - type ValueRef = SqliteValueRef<'r>; -} + type Statement<'q> = SqliteStatement<'q>; -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; + const NAME: &'static str = "SQLite"; - type Statement = SqliteStatement<'q>; + const URL_SCHEMES: &'static [&'static str] = &["sqlite"]; } impl HasStatementCache for Sqlite {}