Refactor SQLPage functions into convention-driven modules#1328
Merged
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
9fd55e8 to
0efbbfa
Compare
Each built-in `sqlpage.*` function is now a plain `async fn` in its own file under `sqlpage_functions/functions/`, with an ordinary Rust signature and no marker comments or macros inside it. Registration is automatic: `build.rs` lists the files in `functions/` into a `sqlpage_functions!` call (the only generated code, one line per function), and that macro declares the modules and builds the `SqlPageFunctionName` enum the SQL engine dispatches on. There is no marker-comment parsing and no per-argument codegen. Argument extraction, dispatch and return-value conversion are ordinary generic code in function_traits.rs (`Extract`, `Handler`, `IntoCowResult`), using the same `Fn`-arity trick axum uses for handlers, so a function's argument and return types are read straight from its signature. Also folds in main's FileAccess centralization (#1327) for the file-reading functions. Verified: `cargo test` passes (148 lib + 70 integration tests, including run_all_sql_test_files, the hmac webhook tests, the upload tests and test_file_upload_through_runsql which exercises the &mut DbConn path). `cargo clippy` and `cargo fmt --check` are clean.
0efbbfa to
d3673c5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
functions.rsby isolating unrelated and security-sensitive implementations into their own files.fetchandfetch_with_meta.Description
src/webserver/database/sqlpage_functions/functions/and addedREADME.mddocumenting the one-file-per-function convention and required marker comment// sqlpage-function: ....build.rs(generate_sqlpage_functions) that scansfunctions/, validates each file's marker against its filename, generates moduleuselines and thesqlpage_functions!registry intoOUT_DIRand the lightweightfunctions.rsnow includes the generated registry (include!(concat!(env!("OUT_DIR"), "/sqlpage_functions.rs"));).exec.rs,run_sql.rs,hash_password.rs,hmac.rs,fetch.rs,fetch_with_meta.rs, etc.).fetchandfetch_with_meta(helpers live alongsidefetch).Testing
cargo fmt --all -- --checkand it passed.cargo testand all tests passed (reported run: 147 unit tests and 70 integration tests passed).cargo clippy --all-targets --all-features -- -D warningsand it passed.Codex Task