Skip to content

Commit 5cfa159

Browse files
committed
docs(tests): document inline SQL pattern rationale
Add documentation to assert_compare! macro explaining why format! is used for SQL construction instead of parameterized queries. SQLx cannot pass PostgreSQL function calls (like create_encrypted_json) as query parameters - they must be evaluated by PostgreSQL as part of the SQL string. Addresses FINAL_CODE_REVIEW.md recommendation #6 (P3).
1 parent 1be11a3 commit 5cfa159

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

tests/sqlx/tests/index_compare_tests.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ use anyhow::Result;
1818
use sqlx::PgPool;
1919

2020
// Helper macro to reduce repetition for compare tests
21+
//
22+
// Note: Uses format! for SQL construction because test data expressions
23+
// (like "create_encrypted_json(1, 'b3')") must be evaluated by PostgreSQL,
24+
// not passed as parameters. SQLx cannot pass PostgreSQL function calls as
25+
// query parameters - they must be part of the SQL string.
2126
macro_rules! assert_compare {
2227
($pool:expr, $func:expr, $a:expr, $b:expr, $expected:expr, $msg:expr) => {
2328
let result: i32 = sqlx::query_scalar(&format!("SELECT eql_v2.{}({}, {})", $func, $a, $b))

0 commit comments

Comments
 (0)