Uses Ch as driver.
defp deps do
[
{:chto, github: "plausible/chto"}
]
end
In your config/config.exs
config :my_app, ecto_repos: [MyApp.Repo]
config :my_app, MyApp.Repo, url: "http://username:password@localhost:8123/database"
In your application code
defmodule MyApp.Repo do
use Ecto.Repo,
otp_app: :my_app,
adapter: Ecto.Adapters.ClickHouse
end
For automatic RowBinary encoding some schema fields need to use custom types:
defmodule MyApp.Example do
use Ecto.Schema
@primary_key false
schema "example" do
field :numeric_types_need_size, Ch.Types.UInt32
field :no_custom_type_for_strings, :string
field :datetime, :naive_datetime
field :maybe_name, Ch.Types.Nullable, type: :string
field :country_code, Ch.Types.FixedString, size: 2
field :price, Ch.Types.Decimal32, scale: 2
end
end
MyApp.Repo.insert_all(MyApp.Example, rows)
For schemaless inserts :types
is required
types = [
numeric_types_need_size: :u32,
no_custom_type_for_strings: :string,
datetime: :datetime,
maybe_name: {:nullable, :string},
country_code: {:string, _size = 2},
price: {:decimal, _size = 32, _scale = 2}
]
MyApp.Repo.insert_all("example", rows, types: types)
:settings
option can be used to enable asynchronous inserts, lightweght deletes, and more
MyApp.Repo.insert_all(MyApp.Example, rows, settings: [async_insert: 1])
MyApp.Repo.delete_all("example", settings: [allow_experimental_lightweight_delete: 1])
:inner_lateral
and :left_lateral
join types are used for ARRAY JOIN
and LEFT ARRAY JOIN
until Ecto adds :array_join
types.
ARRAY JOIN
example:
"arrays_test"
|> join(:inner_lateral, [a], r in "arr", on: true)
|> select([a, r], {a.s, r.arr})
SELECT a0."s", a1."arr"
FROM "arrays_test" AS a0
ARRAY JOIN "arr" AS a1
DEFAULT
expressions on columns are ignored when inserting RowBinary.
See Ch for more details and an example.
Both :binary
and :string
Ecto types are decoded as UTF-8 since Ecto doesn't call adapter's loaders for base types.