So i’ve landed some features
In the lower level libs that make up the Sqlite.Ecto2
adapter. Now my problem is one of the actual implementation when working with Ecto. I know Ecto itself doesn’t support any notification system, but
the Postgrex
adapter does support notifications. From skimming the source, i found that Postgrex
just
opens another connection to the database which is something that sqlite
can not support just because how it was built.
so one idea i had was to use Elixir.Registry
, so every connection in the pool sends notifications out via Registry
.
My issue is that sqlite
sends a message that looks like
{:insert | :update | :delete, 'tablename', rowid}
(here are the docs for that)
Basically i get a rowid
not a primary key
or anything that is actually exposed to the Ecto Repo,
so even if an end user subscribed and got this message, they wouldn’t be able to easily lookup the data
that was affected because rowid
is kind of an internal thing.
What i was thinking of doing is:
%{columns: c, rows: [row]} = Ecto.Adapters.SQL.query!(repo, "SELECT * FROM '#{table}' where rowid = #{rowid};", [])
And then sending that message to subscribers of the Registry, so a consumer would have to do:
receive do
{action, 'users', %{columns: c, rows: [row]}} -> MyRepo.load(User, {result.columns, c, row})
end
The only problem i have with this is that every insert will also have a query to dispatch the notification,
and having user call load
seems a little strange also.