chore(macros): add tests for bind parameter overrides

This commit is contained in:
Austin Bonander 2020-06-11 19:39:20 -07:00 committed by Ryan Leckey
parent 7d3d708d92
commit 029ba24cad
3 changed files with 50 additions and 0 deletions

View file

@ -139,3 +139,5 @@ async fn test_column_override_exact() -> anyhow::Result<()> {
Ok(())
}
// we don't emit bind parameter typechecks for MySQL so testing the overrides is redundant

View file

@ -301,3 +301,49 @@ async fn test_column_override_exact() -> anyhow::Result<()> {
Ok(())
}
#[sqlx_macros::test]
async fn test_bind_arg_override_exact() -> anyhow::Result<()> {
let mut conn = new::<Postgres>().await?;
let my_int = MyInt4(1);
// this query should require a bind parameter override as we would otherwise expect the bind
// to be the same type
let record = sqlx::query!(
"select * from (select 1::int4) records(id) where id = $1",
my_int as MyInt4
)
.fetch_one(&mut conn)
.await?;
assert_eq!(record.id, Some(1i32));
// test that we're actually emitting the typecast by requiring the bound type to be the same
let record = sqlx::query!("select $1::int8 as id", 1i32 as i64)
.fetch_one(&mut conn)
.await?;
assert_eq!(record.id, Some(1i64));
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(())
// }

View file

@ -132,3 +132,5 @@ async fn test_column_override_exact() -> anyhow::Result<()> {
Ok(())
}
// we don't emit bind parameter typechecks for SQLite so testing the overrides is redundant