Skip to content

Commit

Permalink
Allow visibility modifiers to be used in write query declarations
Browse files Browse the repository at this point in the history
Summary: Previously, the `queries` macro's match arms for write queries would take in a `vis` fragment specifier, but would fail to pass the visibility modifier to the next continuation. This commit should fix that.

Reviewed By: edward-shen

Differential Revision: D45340571

fbshipit-source-id: 06ddf99411a6bba67fee84c0fd208a2eba231e34
  • Loading branch information
Alyssa Verkade authored and facebook-github-bot committed Apr 28, 2023
1 parent fe8c18a commit ef641c6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions shed/sql/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ macro_rules! queries {
$( $tt:tt )*
) => (
$crate::queries! {
write $name (
$vi write $name (
values: ($( $vname: $vtype ),*)
$( , $pname: $ptype )*
) { $qtype, mysql($q) sqlite($q) }
Expand Down Expand Up @@ -247,7 +247,7 @@ macro_rules! queries {
$( $tt:tt )*
) => (
$crate::queries! {
write $name (
$vi write $name (
$( $pname: $ptype ),*
$( >list $lname: $ltype )*
) { $qtype, mysql($q) sqlite($q) }
Expand Down
6 changes: 6 additions & 0 deletions shed/sql/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#![deny(warnings)]

use sql_tests_lib::test_datetime_query;
use sql_tests_lib::test_query_visibility_modifiers_compile;
use sql_tests_lib::test_read_query;
use sql_tests_lib::test_transaction_commit;
use sql_tests_lib::test_transaction_rollback;
Expand Down Expand Up @@ -69,6 +70,11 @@ async fn test_transaction_commit_with_sqlite() {
test_transaction_commit(prepare_sqlite_con(), TestSemantics::Sqlite).await;
}

#[tokio::test]
async fn test_visibility_modifiers_compile_with_sqlite() {
test_query_visibility_modifiers_compile(prepare_sqlite_con()).await;
}

#[cfg(fbcode_build)]
#[cfg(test)]
mod mysql {
Expand Down
22 changes: 22 additions & 0 deletions shed/sql/tests_lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,25 @@ pub async fn test_transaction_commit(conn: Connection, semantics: TestSemantics)
vec![(123,), (72,), (53,)]
);
}

pub async fn test_query_visibility_modifiers_compile(conn: Connection) {
mod b {
use crate::queries;

queries! {
pub read ASelect() -> (u64) {
"SELECT 1"
}

pub write AnInsert(values: (x: i64)) {
none,
"INSERT INTO foo (x) VALUES ({values})"
}
}
}

assert_eq!(b::ASelect::query(&conn).await.unwrap(), vec![(1u64,)]);
let res = b::AnInsert::query(&conn, &[(&44i64,)]).await.unwrap();
assert_eq!(res.affected_rows(), 1);
assert_eq!(res.last_insert_id(), Some(1));
}

0 comments on commit ef641c6

Please sign in to comment.