feat: add support for registering scalar functions - #66
Merged
Conversation
velocitysystems
requested changes
Aug 21, 2026
velocitysystems
left a comment
Contributor
There was a problem hiding this comment.
Nice work @onebytegone. Some curated review comments for your consideration.
`register_function` records a Rust scalar function in a process-global set. Both connection pools install that whole set on each connection they open, through `after_connect`, so a function is present before any caller can use the connection and remains present as the pools drop idle connections and open new ones. Registration validates the name, the arity, and the name-and-arity pair against the set, so a bad registration fails at the call site. SQLite owns one strong reference to each registration per connection and releases it through the `xDestroy` callback when the connection closes. A handler error becomes the statement's SQLite error, carrying the handler's message. A handler panic becomes an error naming the function, because an unwind across the FFI boundary would abort the process.
Asserts what a consumer depends on: a registered function resolves on a read connection and on the write connection, on every connection a growing read pool opens, and on the connection that replaces one the idle reaper dropped. Also covers the two failure paths. A handler error carries its message to the caller, and a handler panic produces an error naming the function while leaving the pool usable.
`Builder::register_function` and `SetupRegistrar::register_function` register a function for every database the plugin serves. The registrar variant exists for a handler that closes over the `app` instance; the builder variant covers everything else. Registration happens at the call rather than at `build()`, so a validation error names the offending function where a developer wrote it. The toolkit and the plugin both re-export the function types, so a consumer does not depend on the connection manager directly.
Both READMEs carry the same contract: a function belongs to a connection rather than to a database file, registration precedes the first open, and the handler runs on the connection's own thread. Also states what the mechanism cannot promise. A handler panic becomes an error only where the application unwinds on panic, and aggregate functions, window functions, collations, virtual tables, and functions defined in JavaScript are out of scope.
Registers a function on the builder, then reads a column through it with the `fetch_all` command, which is the path a consumer's frontend takes. The layers underneath have their own tests; this one asserts that the builder entry point and the pools meet.
onebytegone
force-pushed
the
function-registration
branch
from
August 21, 2026 15:03
87a8c21 to
93a8d3f
Compare
velocitysystems
approved these changes
Aug 21, 2026
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.
No description provided.