From bddb2e560f74800875c4ccf14d8f5000da4d79e4 Mon Sep 17 00:00:00 2001 From: Austin Bonander Date: Fri, 5 Jun 2020 20:28:21 -0700 Subject: [PATCH] fix(macros): fix macros for Postgres --- Cargo.toml | 5 +++++ sqlx-macros/src/query/mod.rs | 2 +- sqlx-macros/src/query/output.rs | 2 +- tests/postgres/macros.rs | 5 +++-- tests/postgres/test-query.sql | 1 + 5 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 tests/postgres/test-query.sql diff --git a/Cargo.toml b/Cargo.toml index aed501a6..e23fbdc1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -144,3 +144,8 @@ required-features = [ "postgres" ] name = "postgres-describe" path = "tests/postgres/describe.rs" required-features = [ "postgres" ] + +[[test]] +name = "postgres-macros" +path = "tests/postgres/macros.rs" +required-features = [ "postgres", "macros" ] diff --git a/sqlx-macros/src/query/mod.rs b/sqlx-macros/src/query/mod.rs index 1300b024..2daed064 100644 --- a/sqlx-macros/src/query/mod.rs +++ b/sqlx-macros/src/query/mod.rs @@ -183,7 +183,7 @@ where let sql = &input.src; quote! { - sqlx::query::<#db_path>(#sql).bind_all(#query_args) + sqlx::query_with::<#db_path, _>(#sql, #query_args) } } else { let columns = output::columns_to_rust::(&data.describe)?; diff --git a/sqlx-macros/src/query/output.rs b/sqlx-macros/src/query/output.rs index 09c78cd9..cdc6c738 100644 --- a/sqlx-macros/src/query/output.rs +++ b/sqlx-macros/src/query/output.rs @@ -119,7 +119,7 @@ pub fn quote_query_as( let sql = &input.src; quote! { - sqlx::query_with::<#db_path>(#sql, #bind_args).try_map(|row: #row_path| { + sqlx::query_with::<#db_path, _>(#sql, #bind_args).try_map(|row: #row_path| { use sqlx::Row as _; use sqlx::result_ext::ResultExt as _; diff --git a/tests/postgres/macros.rs b/tests/postgres/macros.rs index f0005d0a..37d5019a 100644 --- a/tests/postgres/macros.rs +++ b/tests/postgres/macros.rs @@ -65,7 +65,8 @@ async fn test_text_var_char_char_n() -> anyhow::Result<()> { async fn _file() -> anyhow::Result<()> { let mut conn = new::().await?; - let account = sqlx::query_file!("tests/test-query.sql",) + // keep trailing comma as a test + let account = sqlx::query_file!("tests/postgres/test-query.sql",) .fetch_one(&mut conn) .await?; @@ -129,7 +130,7 @@ async fn test_query_as_raw() -> anyhow::Result<()> { async fn test_query_file_as() -> anyhow::Result<()> { let mut conn = new::().await?; - let account = sqlx::query_file_as!(Account, "tests/test-query.sql",) + let account = sqlx::query_file_as!(Account, "tests/postgres/test-query.sql",) .fetch_one(&mut conn) .await?; diff --git a/tests/postgres/test-query.sql b/tests/postgres/test-query.sql new file mode 100644 index 00000000..cb8ab010 --- /dev/null +++ b/tests/postgres/test-query.sql @@ -0,0 +1 @@ +SELECT * from (VALUES (1, null)) accounts(id, name)