mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-10-03 07:45:30 +00:00
allow slices to be passed to query!()
capture args by ref
This commit is contained in:
parent
98269ddd20
commit
2c424b6d63
@ -1,7 +1,7 @@
|
|||||||
impl_database_ext! {
|
impl_database_ext! {
|
||||||
sqlx::MySql {
|
sqlx::MySql {
|
||||||
bool,
|
bool,
|
||||||
String | &str,
|
String,
|
||||||
i16,
|
i16,
|
||||||
i32,
|
i32,
|
||||||
i64,
|
i64,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
impl_database_ext! {
|
impl_database_ext! {
|
||||||
sqlx::Postgres {
|
sqlx::Postgres {
|
||||||
bool,
|
bool,
|
||||||
String | &str,
|
String,
|
||||||
i16,
|
i16,
|
||||||
i32,
|
i32,
|
||||||
i64,
|
i64,
|
||||||
|
@ -61,7 +61,7 @@ pub fn quote_args<DB: DatabaseExt>(
|
|||||||
let args = input.args.iter();
|
let args = input.args.iter();
|
||||||
|
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
let args = (#(#args),*,);
|
let args = (#(&#args),*,);
|
||||||
#args_check
|
#args_check
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -27,10 +27,19 @@ impl<T> TyCons<Option<&'_ T>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> TyConsExt for TyCons<&'_ T> {
|
// no overlap with the following impls because of the `: Sized` bound
|
||||||
|
impl<T: Sized> TyConsExt for TyCons<&'_ T> {
|
||||||
type Cons = T;
|
type Cons = T;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TyConsExt for TyCons<&'_ str> {
|
||||||
|
type Cons = String;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> TyConsExt for TyCons<&'_ [T]> {
|
||||||
|
type Cons = Vec<T>;
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> TyConsExt for TyCons<Option<T>> {
|
impl<T> TyConsExt for TyCons<Option<T>> {
|
||||||
type Cons = T;
|
type Cons = T;
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,26 @@ async fn test_query_file_as() -> sqlx::Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_std::test]
|
||||||
|
async fn query_by_string() -> sqlx::Result<()> {
|
||||||
|
let mut conn = sqlx::postgres::connect(&dotenv::var("DATABASE_URL").unwrap()).await?;
|
||||||
|
|
||||||
|
let string = "Hello, world!".to_string();
|
||||||
|
|
||||||
|
let result = sqlx::query!(
|
||||||
|
"SELECT * from (VALUES('Hello, world!')) strings(string)\
|
||||||
|
where string = $1 or string = $2",
|
||||||
|
string,
|
||||||
|
string[..]
|
||||||
|
)
|
||||||
|
.fetch_one(&mut conn)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
assert_eq!(result.string, string);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn test_nullable_err() -> sqlx::Result<()> {
|
async fn test_nullable_err() -> sqlx::Result<()> {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user