mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-10-02 15:25:32 +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! {
|
||||
sqlx::MySql {
|
||||
bool,
|
||||
String | &str,
|
||||
String,
|
||||
i16,
|
||||
i32,
|
||||
i64,
|
||||
|
@ -1,7 +1,7 @@
|
||||
impl_database_ext! {
|
||||
sqlx::Postgres {
|
||||
bool,
|
||||
String | &str,
|
||||
String,
|
||||
i16,
|
||||
i32,
|
||||
i64,
|
||||
|
@ -61,7 +61,7 @@ pub fn quote_args<DB: DatabaseExt>(
|
||||
let args = input.args.iter();
|
||||
|
||||
Ok(quote! {
|
||||
let args = (#(#args),*,);
|
||||
let args = (#(&#args),*,);
|
||||
#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;
|
||||
}
|
||||
|
||||
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>> {
|
||||
type Cons = T;
|
||||
}
|
||||
|
@ -64,6 +64,26 @@ async fn test_query_file_as() -> sqlx::Result<()> {
|
||||
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 fn test_nullable_err() -> sqlx::Result<()> {
|
||||
#[derive(Debug)]
|
||||
|
Loading…
x
Reference in New Issue
Block a user