elixir-sqlite / exqlite

An SQLite3 driver for Elixir
https://hexdocs.pm/exqlite
MIT License
208 stars 47 forks source link

[question] how can one use sqlite3_create_function() or sqlite3_create_window_function() #206

Closed ruslandoga closed 2 years ago

ruslandoga commented 2 years ago

👋

I'd like to try defining a custom aggregate / window function in a NIF and I wonder if there is some easy way to do that. Like

Exqlite.Sqlite3NIF.with_conn_resource(fn ref -> MyNif.create_func(ref) end)

The NIF would be in my app that depends on :ecto_sqlite3, so I don't have direct access to :exqlite connections. Maybe some kind of callback like on_open would be provided to :ecto_sqlite3 adapter to be called with db reference each time connection opens.

ruslandoga commented 2 years ago

Seems like it's already possible to define custom functions via extensions.

https://hexdocs.pm/exqlite/readme.html#using-sqlite3-native-extensions

warmwaffles commented 2 years ago

@ruslandoga you may want to check out @mindreframer's stuff.

Another issue

https://github.com/elixir-sqlite/exqlite/issues/174