/builds/buildsrs/buildsrs/database/src/postgres/util.rs
Line | Count | Source |
1 | | #![allow(dead_code)] |
2 | | |
3 | | /// Generate SQL to call a stored procedure with the given amount of parameters. |
4 | 2 | pub fn sql_call(name: &str, count: usize) -> String { |
5 | 2 | format!( |
6 | 2 | "CALL {name}({})", |
7 | 2 | (1..=count) |
8 | 3 | .map(|c| format!("${c}")) Unexecuted instantiation: buildsrs_database::postgres::util::sql_call::{closure#0} buildsrs_database::postgres::util::sql_call::{closure#0} Line | Count | Source | 8 | 3 | .map(|c| format!("${c}")) |
|
9 | 2 | .collect::<Vec<_>>() |
10 | 2 | .join(", ") |
11 | 2 | ) |
12 | 2 | } Unexecuted instantiation: buildsrs_database::postgres::util::sql_call buildsrs_database::postgres::util::sql_call Line | Count | Source | 4 | 2 | pub fn sql_call(name: &str, count: usize) -> String { | 5 | 2 | format!( | 6 | 2 | "CALL {name}({})", | 7 | 2 | (1..=count) | 8 | 2 | .map(|c| format!("${c}")) | 9 | 2 | .collect::<Vec<_>>() | 10 | 2 | .join(", ") | 11 | 2 | ) | 12 | 2 | } |
|
13 | | |
14 | 1 | #[test] |
15 | 1 | fn sql_call_works() { |
16 | 1 | assert_eq!(sql_call("cleanup", 0), "CALL cleanup()"); |
17 | 1 | assert_eq!(sql_call("user_create", 3), "CALL user_create($1, $2, $3)"); |
18 | 1 | } |