Closed lrowe closed 1 year ago
I really like this idea and think something like this could work quite nicely!
Doing this from JS would probably be relatively slow, but you could build a table of functions in the VFS side, which you can register functions into, and dynamically dispatch to these on the WASM side 🤔
Just to capture some recent thoughts here: This is definitely possible (see https://www.sqlite.org/c3ref/create_function.html):
argc
and sqlite_values**
to a global variable in the WASM binarycolumn_count
, column_int
, ... functions (e.g. arg_count
, arg_int
, etc...) which we can call on the Js side of the dispatch to acquire the Js arguments to pass to the user defined functionresult_int
, etc ... functions to be able to call on the Js side after the user function returns / throwsWhile this is a little bit of work, I don't think it would be particularly difficult. I'm unsure how performant the final solution can be (we have to pay the cost of two translation layers), and it might be awkward to type (you'll essentially have to provide a variadic function that accepts any possible set of SQLite values).
Bit I think overall, this would be quite cool to have and definitely something I want to look into!
Closing this since the basic functionality now exists.
It would be useful to support loading user defined functions to use with filters and index with an expression index. Perhaps a similar mechanism to the VFS plugin could be used to hook this up?
See also: