Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #105, allow trailing commas in query macros #109

Merged
merged 3 commits into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ macro_rules! query (
}
macro_result!()
});
($query:literal, $($args:expr),*) => ({
($query:literal, $($args:expr),*$(,)?) => ({
#[macro_use]
mod _macro_result {
$crate::sqlx_macros::query!($query, $($args),*);
Expand Down Expand Up @@ -155,7 +155,7 @@ macro_rules! query_file (
}
macro_result!()
});
($query:literal, $($args:expr),*) => (#[allow(dead_code)]{
($query:literal, $($args:expr),*$(,)?) => (#[allow(dead_code)]{
#[macro_use]
mod _macro_result {
$crate::sqlx_macros::query_file!($query, $($args),*);
Expand Down Expand Up @@ -221,7 +221,7 @@ macro_rules! query_as (
}
macro_result!()
});
($out_struct:path, $query:literal, $($args:expr),*) => (#[allow(dead_code)] {
($out_struct:path, $query:literal, $($args:expr),*$(,)?) => (#[allow(dead_code)] {
#[macro_use]
mod _macro_result {
$crate::sqlx_macros::query_as!($out_struct, $query, $($args),*);
Expand Down Expand Up @@ -272,7 +272,7 @@ macro_rules! query_file_as (
}
macro_result!()
});
($out_struct:path, $query:literal, $($args:expr),*) => (#[allow(dead_code)] {
($out_struct:path, $query:literal, $($args:expr),*$(,)?) => (#[allow(dead_code)] {
#[macro_use]
mod _macro_result {
$crate::sqlx_macros::query_file_as!($out_struct, $query, $($args),*);
Expand Down
8 changes: 4 additions & 4 deletions tests/postgres-macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ async fn test_query() -> anyhow::Result<()> {

let account = sqlx::query!(
"SELECT * from (VALUES (1, 'Herp Derpinson')) accounts(id, name) where id = $1",
1i32
1i32,
)
.fetch_one(&mut conn)
.await?;
Expand All @@ -34,7 +34,7 @@ async fn test_no_result() -> anyhow::Result<()> {
async fn _file() -> anyhow::Result<()> {
let mut conn = connect().await?;

let account = sqlx::query_file!("tests/test-query.sql")
let account = sqlx::query_file!("tests/test-query.sql",)
.fetch_one(&mut conn)
.await?;

Expand All @@ -56,7 +56,7 @@ async fn test_query_as() -> anyhow::Result<()> {

let account = sqlx::query_as!(
Account,
"SELECT * from (VALUES (1, null)) accounts(id, name)"
"SELECT * from (VALUES (1, null)) accounts(id, name)",
)
.fetch_one(&mut conn)
.await?;
Expand Down Expand Up @@ -99,7 +99,7 @@ async fn test_query_as_raw() -> anyhow::Result<()> {
async fn test_query_file_as() -> anyhow::Result<()> {
let mut conn = connect().await?;

let account = sqlx::query_file_as!(Account, "tests/test-query.sql")
let account = sqlx::query_file_as!(Account, "tests/test-query.sql",)
.fetch_one(&mut conn)
.await?;

Expand Down