|
1 | 1 | //! Built-in `SQLPage` SQL functions. |
2 | 2 | //! |
3 | 3 | //! Every function is a plain `async fn` in its own module under [`functions/`](self). To add one, |
4 | | -//! create `functions/<name>.rs` with an `async fn <name>` and add it to the |
5 | | -//! [`sqlpage_functions!`](super::function_traits::sqlpage_functions) call below. The macro declares |
6 | | -//! the module and adds it to the dispatch enum. Argument conversion and |
7 | | -//! dispatch are handled generically in [`super::function_traits`]. |
| 4 | +//! create `functions/<name>.rs` with an `async fn <name>`, declare the module below and add it to |
| 5 | +//! the [`sqlpage_functions!`](super::function_traits::sqlpage_functions) call. Argument conversion |
| 6 | +//! and dispatch are handled generically in [`super::function_traits`]. |
8 | 7 |
|
9 | 8 | use std::fmt::Write; |
10 | 9 |
|
11 | 10 | use super::function_traits::sqlpage_functions; |
12 | 11 |
|
| 12 | +mod basic_auth_password; |
| 13 | +mod basic_auth_username; |
| 14 | +mod client_ip; |
| 15 | +mod configuration_directory; |
| 16 | +mod cookie; |
| 17 | +mod current_working_directory; |
| 18 | +mod environment_variable; |
| 19 | +mod exec; |
| 20 | +mod fetch; |
| 21 | +mod fetch_with_meta; |
| 22 | +mod hash_password; |
| 23 | +mod header; |
| 24 | +mod headers; |
| 25 | +mod hmac; |
| 26 | +mod link; |
| 27 | +mod oidc_logout_url; |
| 28 | +mod path; |
| 29 | +mod persist_uploaded_file; |
| 30 | +mod protocol; |
| 31 | +mod random_string; |
| 32 | +mod read_file_as_data_url; |
| 33 | +mod read_file_as_text; |
| 34 | +mod regex_match; |
| 35 | +mod request_body; |
| 36 | +mod request_body_base64; |
| 37 | +mod request_method; |
| 38 | +mod run_sql; |
| 39 | +mod send_mail; |
| 40 | +mod set_variable; |
| 41 | +mod uploaded_file_mime_type; |
| 42 | +mod uploaded_file_name; |
| 43 | +mod uploaded_file_path; |
| 44 | +mod url_encode; |
| 45 | +mod user_info; |
| 46 | +mod user_info_token; |
| 47 | +mod variables; |
| 48 | +mod version; |
| 49 | +mod web_root; |
| 50 | + |
13 | 51 | sqlpage_functions! { |
14 | 52 | basic_auth_password, |
15 | 53 | basic_auth_username, |
@@ -82,3 +120,33 @@ fn supported_function_list() -> String { |
82 | 120 | } |
83 | 121 | supported |
84 | 122 | } |
| 123 | + |
| 124 | +#[cfg(test)] |
| 125 | +mod tests { |
| 126 | + use super::SqlPageFunctionName; |
| 127 | + use std::collections::BTreeSet; |
| 128 | + |
| 129 | + #[test] |
| 130 | + fn functions_directory_matches_registered_functions() { |
| 131 | + let directory = concat!( |
| 132 | + env!("CARGO_MANIFEST_DIR"), |
| 133 | + "/src/webserver/database/sqlpage_functions/functions" |
| 134 | + ); |
| 135 | + let files: BTreeSet<String> = std::fs::read_dir(directory) |
| 136 | + .expect("functions directory") |
| 137 | + .map(|entry| entry.expect("directory entry").path()) |
| 138 | + .filter(|path| path.extension().is_some_and(|extension| extension == "rs")) |
| 139 | + .map(|path| { |
| 140 | + path.file_stem() |
| 141 | + .expect("file stem") |
| 142 | + .to_string_lossy() |
| 143 | + .into_owned() |
| 144 | + }) |
| 145 | + .collect(); |
| 146 | + let registered: BTreeSet<String> = SqlPageFunctionName::ALL |
| 147 | + .iter() |
| 148 | + .map(|function| function.name().to_owned()) |
| 149 | + .collect(); |
| 150 | + assert_eq!(files, registered); |
| 151 | + } |
| 152 | +} |
0 commit comments