Files
Prayag Bhakar 9690e3cf23 fix(rust) :: format the files cargo fmt could not see (#1378)
* fix(functions) :: don't use macro to import and build SqlPageFunctionName

* fix(rust) :: format codebase
2026-08-23 17:23:56 +02:00

1.3 KiB

Built-in SQL functions

Each built-in sqlpage.* function is a plain async fn in its own file in functions/. The file stem is the SQL function name and must match the Rust function it exports:

use std::borrow::Cow;

use crate::webserver::http_request_info::RequestInfo;

pub(super) async fn example(request: &RequestInfo, value: Option<Cow<'_, str>>) -> Option<String> {
    // ...
}

To add sqlpage.example, create functions/example.rs, declare its module in functions.rs and add it to the sqlpage_functions! call in the same file:

mod example;

sqlpage_functions! {
    // ...
    example,
}

The sqlpage_functions! macro generates the SqlPageFunctionName enum the SQL engine dispatches on. Per-function argument extraction, dispatch, and return-value conversion are handled generically in function_traits.rs by the Extract, Handler, and IntoCowResult traits. A function's argument and return types are read straight from its signature, so supported argument types are the types that implement Extract there. Functions can take up to five arguments.

Keep helpers and unit tests that are specific to a function in that function's file. Shared helpers can be made pub(super) and imported by name from sibling function modules.