Skip to content

Commit

Permalink
Merge pull request #109 from timmythetiny/ab/trailing-comma-fix
Browse files Browse the repository at this point in the history
Fix #105, allow trailing commas in query macros
  • Loading branch information
abonander authored Feb 21, 2020
2 parents f8e112f + 93001cf commit 18a925f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
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

0 comments on commit 18a925f

Please sign in to comment.