Ecto calls in GenServers

I have a GenServer which needs to makes a function call which makes changes to my DB (and the function is in another module).

I think that my use of a GenServer is justified as the results of the function depends on my GenServer state and makes changes to the state.

When I make this function call, my server crashes due to an ownership error (at least in testing)

Now, my question is how can I use Ecto in a GenServer?

There’s an extensive section about that in the docs:
https://hexdocs.pm/ecto_sql/3.7.0/Ecto.Adapters.SQL.Sandbox.html#module-collaborating-processes

3 Likes

Thanks! I wasn’t aware of this. Maybe I should have read the docs…