Packages

Elixir client for ClickHouse, a fast open-source Online Analytical Processing (OLAP) database management system. Forked from https://github.com/balance-platform/pillar to support CH25+

Current section

Files

Jump to
caterpillar lib pillar pool worker.ex
Raw

lib/pillar/pool/worker.ex

defmodule Pillar.Pool.Worker do
@moduledoc false
use GenServer
def start_link(connection_string) do
GenServer.start_link(__MODULE__, connection_string)
end
def init(connection_string_list) when is_list(connection_string_list) do
connection_string = Enum.random(connection_string_list)
{:ok, Pillar.Connection.new(connection_string)}
end
def handle_call({command, query, params, options}, _from, connection) do
result = handle_command(connection, command, query, params, options)
{:reply, result, connection}
end
def handle_cast({command, query, params, options}, connection) do
{:ok, _result} = handle_command(connection, command, query, params, options)
{:noreply, connection}
end
defp handle_command(connection, command, query, params, options)
when command in [:insert, :select, :query] do
case command do
:insert -> Pillar.insert(connection, query, params, options)
:select -> Pillar.select(connection, query, params, options)
:query -> Pillar.query(connection, query, params, options)
end
end
defp handle_command(connection, command, table_name, record_or_records, options)
when command in [:insert_to_table] do
Pillar.insert_to_table(connection, table_name, record_or_records, options)
end
end