View Source Ch (Ch v0.2.6)

Minimal HTTP ClickHouse client.

Summary

Functions

Returns a supervisor child specification for a DBConnection pool.

Runs a query and returns the result as {:ok, %Ch.Result{}} or {:error, Exception.t()} if there was a database error.

Runs a query and returns the result or raises Ch.Error if there was an error. See query/4.

Start the connection process and connect to ClickHouse.

Types

@type common_option() ::
  {:database, String.t()}
  | {:username, String.t()}
  | {:password, String.t()}
  | {:settings, Keyword.t()}
  | {:timeout, timeout()}
@type query_option() ::
  common_option()
  | {:command, Ch.Query.command()}
  | {:headers, [{String.t(), String.t()}]}
  | {:format, String.t()}
  | {:encode, boolean()}
  | {:decode, boolean()}
  | DBConnection.connection_option()
@type start_option() ::
  common_option()
  | {:scheme, String.t()}
  | {:hostname, String.t()}
  | {:port, :inet.port_number()}
  | {:transport_opts, :gen_tcp.connect_option()}
  | DBConnection.start_option()

Functions

@spec child_spec([start_option()]) :: :supervisor.child_spec()

Returns a supervisor child specification for a DBConnection pool.

See start_link/1 for supported options.

Link to this function

query(conn, statement, params \\ [], opts \\ [])

View Source
@spec query(DBConnection.conn(), iodata(), params, [query_option()]) ::
  {:ok, Ch.Result.t()} | {:error, Exception.t()}
when params: map() | [term()] | [row :: [term()]] | iodata() | Enumerable.t()

Runs a query and returns the result as {:ok, %Ch.Result{}} or {:error, Exception.t()} if there was a database error.

Options

  • :database - Database
  • :username - Username
  • :password - User password
  • :settings - Keyword list of settings
  • :timeout - Query request timeout
  • :command - Command tag for the query
  • :headers - Custom HTTP headers for the request
  • :format - Custom response format for the request
  • :decode - Whether to automatically decode the response
  • DBConnection.connection_option()
Link to this function

query!(conn, statement, params \\ [], opts \\ [])

View Source
@spec query!(DBConnection.conn(), iodata(), params, [query_option()]) :: Ch.Result.t()
when params: map() | [term()] | [row :: [term()]] | iodata() | Enumerable.t()

Runs a query and returns the result or raises Ch.Error if there was an error. See query/4.

@spec start_link([start_option()]) :: GenServer.on_start()

Start the connection process and connect to ClickHouse.

Options

  • :scheme - HTTP scheme, defaults to "http"
  • :hostname - server hostname, defaults to "localhost"
  • :port - HTTP port, defualts to 8123
  • :transport_opts - options to be given to the transport being used. See Mint.HTTP1.connect/4 for more info
  • :database - Database, defaults to "default"
  • :username - Username
  • :password - User password
  • :settings - Keyword list of ClickHouse settings
  • :timeout - HTTP receive timeout in milliseconds
  • :transport_opts - options to be given to the transport being used. See Mint.HTTP1.connect/4 for more info
  • DBConnection.start_option()