README.md

# Ecto ClickHouse Adapter

[![Hex Package](https://img.shields.io/hexpm/v/before_chto.svg)](https://hex.pm/packages/before_chto)
[![Hex Docs](https://img.shields.io/badge/hex-docs-blue.svg)](https://hexdocs.pm/before_chto)

Ecto Adapter for ClickHouse using [`:ch`](https://github.com/plausible/ch)

## Caveats and limitations

See [`:ch`](https://github.com/plausible/ch/tree/hexdocs#caveats-and-limitations)

## Installation

```elixir
defp deps do
  [
    {:chto, "~> 0.1.0"}
  ]
end
```

## Usage

Define your repo similar to this.

```elixir
defmodule MyApp.Repo do
  use Ecto.Repo, otp_app: :my_app, adapter: Ecto.Adapters.ClickHouse
end
```

Configure your repository similar to the following. If you want to know more
about the possible options to pass the repository, checkout the documentation
for [`Ecto.Adapters.ClickHouse`](https://hexdocs.pm/chto/). It will have
more information on what is configurable.

```elixir
config :my_app,
  ecto_repos: [MyApp.Repo]

config :my_app, MyApp.Repo,
  url: "http://localhost:8123/default"
```

Ecto schemas need to use custom Ecto types when there is any ambiguity.
See `Ecto types` section in the documentation for the list of available types.

```elixir
defmodule Example do
  use Ecto.Schema

  @primary_key false
  schema "example" do
    field :a, Ch.Types.UInt32
    field :b, :string
    field :c, :naive_datetime
  end
end
```

For schemaless inserts, a `:types` keyword list can be provided.

```elixir
Repo.insert_all("example", [%{a: 1, b: "2"}, %{a: 3, c: nil}], types: [a: :u32, b: :string, c: :datetime])
```

For deletes, custom settings can be provided.

```elixir
Repo.delete_all("example", settings: [allow_experimental_lightweight_delete: 1, mutations_sync: 1])
```