mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-09-28 05:21:45 +00:00
fix: get MatchBorrow type check working for references 3 deep
This commit is contained in:
parent
fe04a1b612
commit
d06de149a0
@ -83,6 +83,7 @@ pub fn quote_args<DB: DatabaseExt>(
|
||||
|
||||
// if `_expr` is `Option<T>`, get `Option<$ty>`, otherwise `$ty`
|
||||
let ty_check = sqlx::ty_match::WrapSame::<#param_ty, _>::new(&_expr).wrap_same();
|
||||
|
||||
// if `_expr` is `&str`, convert `String` to `&str`
|
||||
let (mut _ty_check, match_borrow) = sqlx::ty_match::MatchBorrow::new(ty_check, &_expr);
|
||||
|
||||
|
@ -81,10 +81,38 @@ impl<'a> MatchBorrowExt for MatchBorrow<&'a [u8], Vec<u8>> {
|
||||
type Matched = &'a [u8];
|
||||
}
|
||||
|
||||
impl<'a, T> MatchBorrowExt for MatchBorrow<&'a T, T> {
|
||||
impl<T> MatchBorrowExt for MatchBorrow<&'_ T, T> {
|
||||
type Matched = T;
|
||||
}
|
||||
|
||||
impl<T> MatchBorrowExt for MatchBorrow<&'_ &'_ T, T> {
|
||||
type Matched = T;
|
||||
}
|
||||
|
||||
impl<T> MatchBorrowExt for MatchBorrow<T, &'_ T> {
|
||||
type Matched = T;
|
||||
}
|
||||
|
||||
impl<T> MatchBorrowExt for MatchBorrow<T, &'_ &'_ T> {
|
||||
type Matched = T;
|
||||
}
|
||||
|
||||
impl<T> MatchBorrowExt for MatchBorrow<Option<&'_ T>, Option<T>> {
|
||||
type Matched = Option<T>;
|
||||
}
|
||||
|
||||
impl<T> MatchBorrowExt for MatchBorrow<Option<&'_ &'_ T>, Option<T>> {
|
||||
type Matched = Option<T>;
|
||||
}
|
||||
|
||||
impl<T> MatchBorrowExt for MatchBorrow<Option<T>, Option<&'_ T>> {
|
||||
type Matched = Option<T>;
|
||||
}
|
||||
|
||||
impl<T> MatchBorrowExt for MatchBorrow<Option<T>, Option<&'_ &'_ T>> {
|
||||
type Matched = Option<T>;
|
||||
}
|
||||
|
||||
impl<T, U> MatchBorrowExt for &'_ MatchBorrow<T, U> {
|
||||
type Matched = U;
|
||||
}
|
||||
@ -125,5 +153,11 @@ fn test_match_borrow() {
|
||||
|
||||
let (_, match_borrow) = MatchBorrow::new(&&0i64, &0i64);
|
||||
let _: i64 = match_borrow.match_borrow();
|
||||
|
||||
let (_, match_borrow) = MatchBorrow::new(&0i64, &0i64);
|
||||
let _: i64 = match_borrow.match_borrow();
|
||||
|
||||
let (_, match_borrow) = MatchBorrow::new(0i64, &0i64);
|
||||
let _: i64 = match_borrow.match_borrow();
|
||||
}
|
||||
}
|
||||
|
@ -211,7 +211,7 @@ async fn query_by_bigdecimal() -> anyhow::Result<()> {
|
||||
// this tests querying by a non-`Copy` type that doesn't have special reborrow semantics
|
||||
|
||||
let decimal = "1234".parse::<BigDecimal>()?;
|
||||
let ref tuple = ("Hello, world!".to_string(),);
|
||||
let ref tuple = ("51245.121232".parse::<BigDecimal>()?,);
|
||||
|
||||
let result = sqlx::query!(
|
||||
"SELECT * from (VALUES(1234.0)) decimals(decimal)\
|
||||
@ -424,21 +424,20 @@ async fn test_bind_arg_override_exact() -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// we can't test this yet but will want to when 1.45 drops and we can strip casts to `_`
|
||||
// #[sqlx_macros::test]
|
||||
// async fn test_bind_arg_override_wildcard() -> anyhow::Result<()> {
|
||||
// let mut conn = new::<Postgres>().await?;
|
||||
//
|
||||
// let my_int = MyInt4(1);
|
||||
//
|
||||
// let record = sqlx::query!(
|
||||
// "select * from (select 1::int4) records(id) where id = $1",
|
||||
// my_int as _
|
||||
// )
|
||||
// .fetch_one(&mut conn)
|
||||
// .await?;
|
||||
//
|
||||
// assert_eq!(record.id, 1i32);
|
||||
//
|
||||
// Ok(())
|
||||
// }
|
||||
#[sqlx_macros::test]
|
||||
async fn test_bind_arg_override_wildcard() -> anyhow::Result<()> {
|
||||
let mut conn = new::<Postgres>().await?;
|
||||
|
||||
let my_int = MyInt4(1);
|
||||
|
||||
let record = sqlx::query!(
|
||||
"select * from (select 1::int4) records(id) where id = $1",
|
||||
my_int as _
|
||||
)
|
||||
.fetch_one(&mut conn)
|
||||
.await?;
|
||||
|
||||
assert_eq!(record.id, Some(1i32));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user