elixir-sqlite/ecto_sqlite3

How to enable_load_extension

Closed this issue ยท 6 comments

Hi, not sure if this is the place to ask, but I'm using ecto_sqlite3 in a Phoenix app. I want to manually load the decimal extension from https://github.com/nalgeon/sqlean, which isn't present in https://github.com/mindreframer/ex_sqlean.

I tried in Application.start to run

MyApp.Repo.query!("select load_extension('./decimal.so');")

That is not authorized, and I understand first I would need to do something like

alias Exqlite.Basic
{:ok, conn} = Basic.open("db.sqlite3")
:ok = Basic.enable_load_extension(conn)

I'm not sure how to hook into creation of the database connection when just using Ecto Repo. Any advice? This is not a "bug" more of a stack-overflow usage type question I know...

@mindreframer would you be able to help out here?

@warmwaffles @cdock1029 Well... TBH, this was a little puzzle. I found a way, but it looks rather... interesting, to put it mildly.

I created a working example here: https://github.com/mindreframer/sqlite_init. I hope this helps somewhat, and if there is a better and more clear way to do it, I would also like to know it. I used ex_litedb, that is based on litedb, a friendly fork for sqleandb. I was using it for my personal purposes, so the documentation is lagging.

Cheers!

@mindreframer Thanks a lot this is helpful, I appreciate it. Interesting indeed, but for now it gets the job done. There is not such an easy way to get access to the connection otherwise.

dvic commented

@mindreframer thanks for this! I have a question though: where is this connection_listeners coming from? Is this an Ecto thing? And also, isn't this approach asynchronous? Is it possible that the query! example runs before the message is processed in ConnectionListener?

@dvic This is feature from DBConnection - https://github.com/elixir-ecto/db_connection/blob/master/lib/db_connection.ex

https://github.com/elixir-ecto/db_connection/blob/master/lib/db_connection.ex#L415

And yes, it seems to be asynchronous. So I guess it is up to the user / developer to prevent a possible race condition.

dvic commented

@dvic This is feature from DBConnection - https://github.com/elixir-ecto/db_connection/blob/master/lib/db_connection.ex

https://github.com/elixir-ecto/db_connection/blob/master/lib/db_connection.ex#L415

And yes, it seems to be asynchronous. So I guess it is up to the user / developer to prevent a possible race condition.

I see, thanks for the explanation!