Duckex - a client library for DuckDB

It is library created by me and @abc3. It is simple client for DuckDB, but with small twist when compared with other libraries out there - instead of using NIFs it uses port instead. That provides greater stability (as issues in DuckDB or loaded libraries will not cause issues for BEAM) and provides better OS-level management (as for example OOM killer will kill only port instead of whole BEAM VM).

Right now implementation is quite suboptimal (it do not support response streaming, as it is quite problematic on DuckDB side) and it uses JSON as a transport encoding between Elixir and Rust (yeah, port is implemented in Rust). Hopefully it will be resolved in near future.

It also is built on top of db_connection, so it should be possible to write Ecto integration, but right now it is not implemented (and if it will be implemented, it will be external library).

10 Likes

Oh nice! Given the sorts of analytical queries DuckDB is intended for I had long thought a NIF seemed like a bad idea. Especially since it has a bit of a reputation for OOM in some cases!

The port approach makes a lot more sense to me.

2 Likes

Awesome. Have you considered writing a blog post about lessons learned on how to integrate with db_connection?

1 Like

I can consider it, though there weren’t any major bumps in the process. But I can try to write some small article about that. db_connection is pretty straightforward, so it isn’t that hard to come up with something.

1 Like