Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/webserver/database/sqlpage_functions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Built-in SQL functions

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

```rust
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` and add it to the
[`sqlpage_functions!`](function_traits.rs) call in [`functions.rs`](functions.rs):

```rust
sqlpage_functions! {
// ...
example,
}
```

The [`sqlpage_functions!`](function_traits.rs) macro declares the modules and 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`](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.

This file was deleted.

Loading
Loading