Ecto.Adapters.ClickHouse.Connection (clickhouse_adapter_ecto v0.2.0)

Copy Markdown

Implements Ecto.Adapters.SQL.Connection on top of ChDriver.

Query params (? placeholders in generated SQL) are sent to ClickHouse as native protocol parameters rather than inlined as SQL literals, so there's no client-side value escaping to get wrong. nil is the one exception -- ClickHouse's parameter protocol has no type-independent NULL, so it's inlined as the literal NULL token instead.

Statement generation lives in Ecto.Adapters.ClickHouse.QueryBuilder (all/2, insert/8, etc) and Ecto.Adapters.ClickHouse.Expression (clause/expression rendering); DDL generation lives in Ecto.Adapters.ClickHouse.DDL. This module implements the Ecto.Adapters.SQL.Connection behaviour itself and mostly delegates to those.

Summary

Functions

Streams query results incrementally, one ClickHouse wire-protocol block at a time, rather than buffering the whole result set first.

Functions

stream(conn, statement, params, opts)

Streams query results incrementally, one ClickHouse wire-protocol block at a time, rather than buffering the whole result set first.

This adapter has no session transaction support, and Repo.stream/2 requires a connection checked out via Repo.transaction/2, so Repo.stream/2 does not work end-to-end on this adapter yet. Use ChDriver.stream/4 directly against the repo's connection pool instead:

%{pid: pool} = Ecto.Adapter.lookup_meta(MyApp.Repo)

DBConnection.run(pool, fn conn ->
  ChDriver.stream(conn, "SELECT id, path FROM page_views", [])
  |> Enum.each(&IO.inspect/1)
end)