ChDriver. DBConnection
(ch_driver v0.1.1)
Copy Markdown
DBConnection behaviour implementation for ClickHouse's native TCP
protocol.
This is internal wiring: it's what makes ChDriver.start_link/1 and
ChDriver.query/2,3,4 work as a normal pooled connection, but you should
never call functions in this module directly. Use ChDriver's public API
instead.
ClickHouse's native protocol is unpipelined request/response — one query
in flight per socket at a time — so this module is a thin adapter over
ChDriver.Connection: handle_execute/4 builds the final wire statement
and params, runs the query, and translates the result into the shape
DBConnection expects.
Socket-level failures disconnect the pooled connection so it gets torn down and reconnected; a ClickHouse-level query error (a rejected query, a syntax error, etc.) is returned as an ordinary error instead, since the connection itself is still fine to reuse.
There's no transaction support in ClickHouse's native protocol, so
handle_begin/2, handle_commit/2, and handle_rollback/2 all return an
error rather than pretending to do something.
Cursors
handle_declare/4, handle_fetch/4, and handle_deallocate/4 back
ChDriver.stream/2,3,4: they read a query's result one block at a time
via ChDriver.Connection.start_stream/3 / stream_fetch/2 /
cancel_stream/2, instead of accumulating the whole thing into memory
the way handle_execute/4 does.