-
Notifications
You must be signed in to change notification settings - Fork 1.4k
sqlx-core: impl IntoArguments for Arguments #3833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,19 +37,29 @@ pub trait IntoArguments<'q, DB: Database>: Sized + Send { | |
#[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 | ||
{ | ||
fn into_arguments(self) -> $Arguments { | ||
self | ||
} | ||
} | ||
// impl<'q> | ||
// $crate::arguments::IntoArguments< | ||
// 'q, | ||
// <$Arguments as $crate::arguments::Arguments<'q>>::Database, | ||
// > for $Arguments | ||
// { | ||
// fn into_arguments(self) -> $Arguments { | ||
// self | ||
// } | ||
// } | ||
Comment on lines
+40
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this macro is obsoleted by this PR then it should just be deleted. |
||
}; | ||
} | ||
|
||
impl<'q, DB, T> IntoArguments<'q, DB> for T | ||
where | ||
DB: Database, | ||
T: Arguments<'q, Database = DB> + Into<<DB as Database>::Arguments<'q>>, | ||
{ | ||
fn into_arguments(self) -> <DB as Database>::Arguments<'q> { | ||
self.into() | ||
} | ||
} | ||
|
||
/// used by the query macros to prevent supernumerary `.bind()` calls | ||
pub struct ImmutableArguments<'q, DB: Database>(pub <DB as Database>::Arguments<'q>); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use sqlx::{ColumnIndex, Database, Decode, Executor, Row, Type}; | ||
|
||
pub async fn generic_it_connects<'conn, E>(e: E) -> sqlx::Result<i32> | ||
where | ||
E: Executor<'conn>, | ||
E::Database: Database, | ||
for<'row> i32: Type<E::Database> + Decode<'row, E::Database>, | ||
<E::Database as Database>::Row: Row<Database = E::Database>, | ||
usize: ColumnIndex<<E::Database as Database>::Row>, | ||
{ | ||
sqlx::query("select 1 + 1") | ||
.try_map(|row: <E::Database as Database>::Row| row.try_get::<i32, _>(0)) | ||
.fetch_one(e) | ||
.await | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not immediately obvious how this test relates to the purpose of this PR. Can you add a comment explaining that? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
mod ansi; | ||
|
||
use sqlx::MySql; | ||
use sqlx_test::{new, pool, setup_if_needed}; | ||
|
||
#[sqlx_macros::test] | ||
async fn it_connects() -> anyhow::Result<()> { | ||
let mut conn = new::<MySql>().await?; | ||
|
||
let value = ansi::generic_it_connects(&mut conn).await?; | ||
|
||
assert_eq!(2i32, value); | ||
|
||
Ok(()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
mod ansi; | ||
|
||
use sqlx::Postgres; | ||
use sqlx_test::{new, pool, setup_if_needed}; | ||
|
||
#[sqlx_macros::test] | ||
async fn it_connects() -> anyhow::Result<()> { | ||
let mut conn = new::<Postgres>().await?; | ||
|
||
let value = ansi::generic_it_connects(&mut conn).await?; | ||
|
||
assert_eq!(2i32, value); | ||
|
||
Ok(()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
mod ansi; | ||
|
||
use sqlx::Sqlite; | ||
use sqlx_test::{new, pool, setup_if_needed}; | ||
|
||
#[sqlx_macros::test] | ||
async fn it_connects() -> anyhow::Result<()> { | ||
let mut conn = new::<Sqlite>().await?; | ||
|
||
let value = ansi::generic_it_connects(&mut conn).await?; | ||
|
||
assert_eq!(2i32, value); | ||
|
||
Ok(()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newline at the end of this file.