Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions sqlx-core/src/any/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ pub struct AnyArguments {
pub values: AnyArgumentBuffer,
}

impl<'q> Arguments<'q> for AnyArguments {
impl Arguments for AnyArguments {
type Database = Any;

fn reserve(&mut self, additional: usize, _size: usize) {
self.values.0.reserve(additional);
}

fn add<T>(&mut self, value: T) -> Result<(), BoxDynError>
fn add<'t, T>(&mut self, value: T) -> Result<(), BoxDynError>
where
T: 'q + Encode<'q, Self::Database> + Type<Self::Database>,
T: Encode<'t, Self::Database> + Type<Self::Database>,
{
let _: IsNull = value.encode(&mut self.values)?;
Ok(())
Expand All @@ -37,7 +37,7 @@ pub struct AnyArgumentBuffer(#[doc(hidden)] pub Vec<AnyValueKind>);

impl AnyArguments {
#[doc(hidden)]
pub fn convert_into<'a, A: Arguments<'a>>(self) -> Result<A, BoxDynError>
pub fn convert_into<'a, A: Arguments>(self) -> Result<A, BoxDynError>
where
Option<i32>: Type<A::Database> + Encode<'a, A::Database>,
Option<bool>: Type<A::Database> + Encode<'a, A::Database>,
Expand Down
4 changes: 2 additions & 2 deletions sqlx-core/src/any/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ impl Database for Any {
type Value = AnyValue;
type ValueRef<'r> = AnyValueRef<'r>;

type Arguments<'q> = AnyArguments;
type ArgumentBuffer<'q> = AnyArgumentBuffer;
type Arguments = AnyArguments;
type ArgumentBuffer = AnyArgumentBuffer;

type Statement = AnyStatement;

Expand Down
6 changes: 3 additions & 3 deletions sqlx-core/src/any/types/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl Type<Any> for [u8] {
impl<'q> Encode<'q, Any> for &'q [u8] {
fn encode_by_ref(
&self,
buf: &mut <Any as Database>::ArgumentBuffer<'q>,
buf: &mut <Any as Database>::ArgumentBuffer,
) -> Result<IsNull, BoxDynError> {
buf.0.push(AnyValueKind::Blob(Arc::new(self.to_vec())));
Ok(IsNull::No)
Expand All @@ -39,10 +39,10 @@ impl Type<Any> for Vec<u8> {
}
}

impl<'q> Encode<'q, Any> for Vec<u8> {
impl Encode<'_, Any> for Vec<u8> {
fn encode_by_ref(
&self,
buf: &mut <Any as Database>::ArgumentBuffer<'q>,
buf: &mut <Any as Database>::ArgumentBuffer,
) -> Result<IsNull, BoxDynError> {
buf.0.push(AnyValueKind::Blob(Arc::new(self.clone())));
Ok(IsNull::No)
Expand Down
4 changes: 2 additions & 2 deletions sqlx-core/src/any/types/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ impl Type<Any> for bool {
}
}

impl<'q> Encode<'q, Any> for bool {
impl Encode<'_, Any> for bool {
fn encode_by_ref(
&self,
buf: &mut <Any as Database>::ArgumentBuffer<'q>,
buf: &mut <Any as Database>::ArgumentBuffer,
) -> Result<IsNull, BoxDynError> {
buf.0.push(AnyValueKind::Bool(*self));
Ok(IsNull::No)
Expand Down
4 changes: 2 additions & 2 deletions sqlx-core/src/any/types/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ impl Type<Any> for f64 {
}
}

impl<'q> Encode<'q, Any> for f64 {
impl Encode<'_, Any> for f64 {
fn encode_by_ref(
&self,
buf: &mut <Any as Database>::ArgumentBuffer<'q>,
buf: &mut <Any as Database>::ArgumentBuffer,
) -> Result<IsNull, BoxDynError> {
buf.0.push(AnyValueKind::Double(*self));
Ok(IsNull::No)
Expand Down
12 changes: 6 additions & 6 deletions sqlx-core/src/any/types/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ impl Type<Any> for i16 {
}
}

impl<'q> Encode<'q, Any> for i16 {
impl Encode<'_, Any> for i16 {
fn encode_by_ref(
&self,
buf: &mut <Any as Database>::ArgumentBuffer<'q>,
buf: &mut <Any as Database>::ArgumentBuffer,
) -> Result<IsNull, BoxDynError> {
buf.0.push(AnyValueKind::SmallInt(*self));
Ok(IsNull::No)
Expand All @@ -45,10 +45,10 @@ impl Type<Any> for i32 {
}
}

impl<'q> Encode<'q, Any> for i32 {
impl Encode<'_, Any> for i32 {
fn encode_by_ref(
&self,
buf: &mut <Any as Database>::ArgumentBuffer<'q>,
buf: &mut <Any as Database>::ArgumentBuffer,
) -> Result<IsNull, BoxDynError> {
buf.0.push(AnyValueKind::Integer(*self));
Ok(IsNull::No)
Expand All @@ -73,10 +73,10 @@ impl Type<Any> for i64 {
}
}

impl<'q> Encode<'q, Any> for i64 {
impl Encode<'_, Any> for i64 {
fn encode_by_ref(
&self,
buf: &mut <Any as Database>::ArgumentBuffer<'q>,
buf: &mut <Any as Database>::ArgumentBuffer,
) -> Result<IsNull, BoxDynError> {
buf.0.push(AnyValueKind::BigInt(*self));
Ok(IsNull::No)
Expand Down
13 changes: 5 additions & 8 deletions sqlx-core/src/any/types/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Type<Any> for str {
}

impl<'a> Encode<'a, Any> for &'a str {
fn encode(self, buf: &mut <Any as Database>::ArgumentBuffer<'a>) -> Result<IsNull, BoxDynError>
fn encode(self, buf: &mut <Any as Database>::ArgumentBuffer) -> Result<IsNull, BoxDynError>
where
Self: Sized,
{
Expand All @@ -26,7 +26,7 @@ impl<'a> Encode<'a, Any> for &'a str {

fn encode_by_ref(
&self,
buf: &mut <Any as Database>::ArgumentBuffer<'a>,
buf: &mut <Any as Database>::ArgumentBuffer,
) -> Result<IsNull, BoxDynError> {
(*self).encode(buf)
}
Expand All @@ -47,18 +47,15 @@ impl Type<Any> for String {
}
}

impl<'q> Encode<'q, Any> for String {
fn encode(
self,
buf: &mut <Any as Database>::ArgumentBuffer<'q>,
) -> Result<IsNull, BoxDynError> {
impl Encode<'_, Any> for String {
fn encode(self, buf: &mut <Any as Database>::ArgumentBuffer) -> Result<IsNull, BoxDynError> {
buf.0.push(AnyValueKind::Text(Arc::new(self)));
Ok(IsNull::No)
}

fn encode_by_ref(
&self,
buf: &mut <Any as Database>::ArgumentBuffer<'q>,
buf: &mut <Any as Database>::ArgumentBuffer,
) -> Result<IsNull, BoxDynError> {
buf.0.push(AnyValueKind::Text(Arc::new(self.clone())));
Ok(IsNull::No)
Expand Down
27 changes: 11 additions & 16 deletions sqlx-core/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ use std::fmt::{self, Write};
/// A tuple of arguments to be sent to the database.
// This lint is designed for general collections, but `Arguments` is not meant to be as such.
#[allow(clippy::len_without_is_empty)]
pub trait Arguments<'q>: Send + Sized + Default {
pub trait Arguments: Send + Sized + Default {
type Database: Database;

/// Reserves the capacity for at least `additional` more values (of `size` total bytes) to
/// be added to the arguments without a reallocation.
fn reserve(&mut self, additional: usize, size: usize);

/// Add the value to the end of the arguments.
fn add<T>(&mut self, value: T) -> Result<(), BoxDynError>
fn add<'t, T>(&mut self, value: T) -> Result<(), BoxDynError>
where
T: 'q + Encode<'q, Self::Database> + Type<Self::Database>;
T: Encode<'t, Self::Database> + Type<Self::Database>;

/// The number of arguments that were already added.
fn len(&self) -> usize;
Expand All @@ -29,19 +29,17 @@ pub trait Arguments<'q>: Send + Sized + Default {
}
}

pub trait IntoArguments<'q, DB: Database>: Sized + Send {
fn into_arguments(self) -> <DB as Database>::Arguments<'q>;
pub trait IntoArguments<DB: Database>: Sized + Send {
fn into_arguments(self) -> <DB as Database>::Arguments;
}

// NOTE: required due to lack of lazy normalization
#[macro_export]
macro_rules! impl_into_arguments_for_arguments {
($Arguments:path) => {
impl<'q>
$crate::arguments::IntoArguments<
'q,
<$Arguments as $crate::arguments::Arguments<'q>>::Database,
> for $Arguments
impl
$crate::arguments::IntoArguments<<$Arguments as $crate::arguments::Arguments>::Database>
for $Arguments
{
fn into_arguments(self) -> $Arguments {
self
Expand All @@ -51,13 +49,10 @@ macro_rules! impl_into_arguments_for_arguments {
}

/// used by the query macros to prevent supernumerary `.bind()` calls
pub struct ImmutableArguments<'q, DB: Database>(pub <DB as Database>::Arguments<'q>);
pub struct ImmutableArguments<DB: Database>(pub <DB as Database>::Arguments);

impl<'q, DB: Database> IntoArguments<'q, DB> for ImmutableArguments<'q, DB> {
fn into_arguments(self) -> <DB as Database>::Arguments<'q> {
impl<DB: Database> IntoArguments<DB> for ImmutableArguments<DB> {
fn into_arguments(self) -> <DB as Database>::Arguments {
self.0
}
}

// TODO: Impl `IntoArguments` for &[&dyn Encode]
// TODO: Impl `IntoArguments` for (impl Encode, ...) x16
4 changes: 2 additions & 2 deletions sqlx-core/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ pub trait Database: 'static + Sized + Send + Debug {
type ValueRef<'r>: ValueRef<'r, Database = Self>;

/// The concrete `Arguments` implementation for this database.
type Arguments<'q>: Arguments<'q, Database = Self>;
type Arguments: Arguments<Database = Self>;
/// The concrete type used as a buffer for arguments while encoding.
type ArgumentBuffer<'q>;
type ArgumentBuffer;

/// The concrete `Statement` implementation for this database.
type Statement: Statement<Database = Self>;
Expand Down
22 changes: 11 additions & 11 deletions sqlx-core/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl IsNull {
/// Encode a single value to be sent to the database.
pub trait Encode<'q, DB: Database> {
/// Writes the value of `self` into `buf` in the expected format for the database.
fn encode(self, buf: &mut <DB as Database>::ArgumentBuffer<'q>) -> Result<IsNull, BoxDynError>
fn encode(self, buf: &mut <DB as Database>::ArgumentBuffer) -> Result<IsNull, BoxDynError>
where
Self: Sized,
{
Expand All @@ -42,7 +42,7 @@ pub trait Encode<'q, DB: Database> {
/// memory.
fn encode_by_ref(
&self,
buf: &mut <DB as Database>::ArgumentBuffer<'q>,
buf: &mut <DB as Database>::ArgumentBuffer,
) -> Result<IsNull, BoxDynError>;

fn produces(&self) -> Option<DB::TypeInfo> {
Expand All @@ -62,14 +62,14 @@ where
T: Encode<'q, DB>,
{
#[inline]
fn encode(self, buf: &mut <DB as Database>::ArgumentBuffer<'q>) -> Result<IsNull, BoxDynError> {
fn encode(self, buf: &mut <DB as Database>::ArgumentBuffer) -> Result<IsNull, BoxDynError> {
<T as Encode<DB>>::encode_by_ref(self, buf)
}

#[inline]
fn encode_by_ref(
&self,
buf: &mut <DB as Database>::ArgumentBuffer<'q>,
buf: &mut <DB as Database>::ArgumentBuffer,
) -> Result<IsNull, BoxDynError> {
<&T as Encode<DB>>::encode(self, buf)
}
Expand Down Expand Up @@ -104,7 +104,7 @@ macro_rules! impl_encode_for_option {
#[inline]
fn encode(
self,
buf: &mut <$DB as $crate::database::Database>::ArgumentBuffer<'q>,
buf: &mut <$DB as $crate::database::Database>::ArgumentBuffer,
) -> Result<$crate::encode::IsNull, $crate::error::BoxDynError> {
if let Some(v) = self {
v.encode(buf)
Expand All @@ -116,7 +116,7 @@ macro_rules! impl_encode_for_option {
#[inline]
fn encode_by_ref(
&self,
buf: &mut <$DB as $crate::database::Database>::ArgumentBuffer<'q>,
buf: &mut <$DB as $crate::database::Database>::ArgumentBuffer,
) -> Result<$crate::encode::IsNull, $crate::error::BoxDynError> {
if let Some(v) = self {
v.encode_by_ref(buf)
Expand All @@ -142,15 +142,15 @@ macro_rules! impl_encode_for_smartpointer {
#[inline]
fn encode(
self,
buf: &mut <DB as Database>::ArgumentBuffer<'q>,
buf: &mut <DB as Database>::ArgumentBuffer,
) -> Result<IsNull, BoxDynError> {
<T as Encode<DB>>::encode_by_ref(self.as_ref(), buf)
}

#[inline]
fn encode_by_ref(
&self,
buf: &mut <DB as Database>::ArgumentBuffer<'q>,
buf: &mut <DB as Database>::ArgumentBuffer,
) -> Result<IsNull, BoxDynError> {
<&T as Encode<DB>>::encode(self, buf)
}
Expand Down Expand Up @@ -178,14 +178,14 @@ where
T: ToOwned,
{
#[inline]
fn encode(self, buf: &mut <DB as Database>::ArgumentBuffer<'q>) -> Result<IsNull, BoxDynError> {
fn encode(self, buf: &mut <DB as Database>::ArgumentBuffer) -> Result<IsNull, BoxDynError> {
<&T as Encode<DB>>::encode_by_ref(&self.as_ref(), buf)
}

#[inline]
fn encode_by_ref(
&self,
buf: &mut <DB as Database>::ArgumentBuffer<'q>,
buf: &mut <DB as Database>::ArgumentBuffer,
) -> Result<IsNull, BoxDynError> {
<&T as Encode<DB>>::encode_by_ref(&self.as_ref(), buf)
}
Expand All @@ -207,7 +207,7 @@ macro_rules! forward_encode_impl {
impl<'q> Encode<'q, $db> for $for_type {
fn encode_by_ref(
&self,
buf: &mut <$db as sqlx_core::database::Database>::ArgumentBuffer<'q>,
buf: &mut <$db as sqlx_core::database::Database>::ArgumentBuffer,
) -> Result<IsNull, BoxDynError> {
<$forward_to as Encode<$db>>::encode(self.as_ref(), buf)
}
Expand Down
10 changes: 5 additions & 5 deletions sqlx-core/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,13 @@ pub trait Execute<'q, DB: Database>: Send + Sized {
/// will be prepared (and cached) before execution.
///
/// Returns `Err` if encoding any of the arguments failed.
fn take_arguments(&mut self) -> Result<Option<<DB as Database>::Arguments<'q>>, BoxDynError>;
fn take_arguments(&mut self) -> Result<Option<<DB as Database>::Arguments>, BoxDynError>;

/// Returns `true` if the statement should be cached.
fn persistent(&self) -> bool;
}

impl<'q, DB: Database, T> Execute<'q, DB> for T
impl<DB: Database, T> Execute<'_, DB> for T
where
T: SqlSafeStr + Send,
{
Expand All @@ -225,7 +225,7 @@ where
}

#[inline]
fn take_arguments(&mut self) -> Result<Option<<DB as Database>::Arguments<'q>>, BoxDynError> {
fn take_arguments(&mut self) -> Result<Option<<DB as Database>::Arguments>, BoxDynError> {
Ok(None)
}

Expand All @@ -235,7 +235,7 @@ where
}
}

impl<'q, DB: Database, T> Execute<'q, DB> for (T, Option<<DB as Database>::Arguments<'q>>)
impl<DB: Database, T> Execute<'_, DB> for (T, Option<<DB as Database>::Arguments>)
where
T: SqlSafeStr + Send,
{
Expand All @@ -250,7 +250,7 @@ where
}

#[inline]
fn take_arguments(&mut self) -> Result<Option<<DB as Database>::Arguments<'q>>, BoxDynError> {
fn take_arguments(&mut self) -> Result<Option<<DB as Database>::Arguments>, BoxDynError> {
Ok(self.1.take())
}

Expand Down
Loading
Loading