dyedgreen / deno-sqlite

Deno SQLite module
https://deno.land/x/sqlite
MIT License
409 stars 36 forks source link

Support user defined functions #186

Closed lrowe closed 1 year ago

lrowe commented 2 years ago

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:

dyedgreen commented 2 years 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 🤔

dyedgreen commented 2 years ago

Just to capture some recent thoughts here: This is definitely possible (see https://www.sqlite.org/c3ref/create_function.html):

While 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!

dyedgreen commented 1 year ago

Closing this since the basic functionality now exists.