# `Huginn.Clickhouse.Query`
[🔗](https://github.com/nyo16/huginn/blob/v0.6.0/lib/huginn/clickhouse/query.ex#L1)

Builds QueryInfo messages for ClickHouse gRPC requests.

# `query_opts`

```elixir
@type query_opts() :: [
  database: String.t(),
  user_name: String.t(),
  password: String.t(),
  jwt: String.t(),
  format: String.t(),
  settings: map(),
  query_id: String.t(),
  session_id: String.t(),
  session_timeout: non_neg_integer(),
  send_output_columns: boolean()
]
```

# `build`

```elixir
@spec build(String.t(), query_opts()) :: struct()
```

Builds a QueryInfo struct for a SQL query.

## Options

  * `:database` - Database to use for the query
  * `:user_name` - Username for authentication
  * `:password` - Password for authentication
  * `:jwt` - JWT token for authentication
  * `:format` - Output format (default: "TabSeparated")
  * `:settings` - Map of ClickHouse settings
  * `:query_id` - Custom query ID for tracking
  * `:session_id` - Session ID for stateful queries
  * `:session_timeout` - Session timeout in seconds
  * `:send_output_columns` - Include column metadata in response

# `build_cancel`

```elixir
@spec build_cancel() :: struct()
```

Builds a cancel QueryInfo to stop a running query.

# `build_continuation`

```elixir
@spec build_continuation(binary(), keyword()) :: struct()
```

Builds a continuation QueryInfo for streaming input.

Used with `ExecuteQueryWithStreamInput` and `ExecuteQueryWithStreamIO` methods.

# `build_external_table`

```elixir
@spec build_external_table(
  String.t(),
  [{String.t(), String.t()}],
  binary(),
  keyword()
) :: struct()
```

Builds an external table definition for use with queries.

## Options

  * `:format` - Data format (default: "TabSeparated")
  * `:compression` - Compression type of data
  * `:settings` - Additional settings for the table

# `build_insert`

```elixir
@spec build_insert(String.t(), binary(), keyword()) :: struct()
```

Builds a QueryInfo struct for an INSERT query with input data.

The input data format is taken from the SQL `FORMAT` clause (e.g.
`INSERT INTO t FORMAT TabSeparated`), not from an option.

## Options

Same as `build/2` (except `:format` and `:send_output_columns`, which do not
apply to inserts) plus:

  * `:input_compression` - Compression type of `data` (e.g. `"gzip"`); the
    server decompresses it before parsing

# `with_config`

```elixir
@spec with_config(keyword(), Huginn.Clickhouse.Config.t()) :: keyword()
```

Applies a pool's config to per-call query options.

The config's `:database` and authentication credentials become defaults;
options given in `opts` always win.

## Examples

    iex> config = Huginn.Clickhouse.Config.new(host: "localhost", database: "analytics")
    iex> Huginn.Clickhouse.Query.with_config([format: "JSON"], config)
    [database: "analytics", format: "JSON"]

---

*Consult [api-reference.md](api-reference.md) for complete listing*
