{"id":13695596,"url":"https://github.com/clickhouse-elixir/clickhouse_ecto","last_synced_at":"2025-10-21T18:32:09.019Z","repository":{"id":44956237,"uuid":"126465258","full_name":"clickhouse-elixir/clickhouse_ecto","owner":"clickhouse-elixir","description":"Ecto adapter for ClickHouse database","archived":false,"fork":false,"pushed_at":"2023-05-17T06:53:10.000Z","size":3620,"stargazers_count":64,"open_issues_count":8,"forks_count":37,"subscribers_count":18,"default_branch":"master","last_synced_at":"2024-10-14T11:19:35.448Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clickhouse-elixir.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null}},"created_at":"2018-03-23T09:49:05.000Z","updated_at":"2024-08-17T02:51:40.000Z","dependencies_parsed_at":"2024-04-13T00:37:18.177Z","dependency_job_id":"518537d4-0802-4ab2-9565-a1f4e032fed4","html_url":"https://github.com/clickhouse-elixir/clickhouse_ecto","commit_stats":{"total_commits":60,"total_committers":10,"mean_commits":6.0,"dds":0.6,"last_synced_commit":"bc963d3f53bf4264e6fa2b7345c7e3c3dc49d6ee"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clickhouse-elixir%2Fclickhouse_ecto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clickhouse-elixir%2Fclickhouse_ecto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clickhouse-elixir%2Fclickhouse_ecto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clickhouse-elixir%2Fclickhouse_ecto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clickhouse-elixir","download_url":"https://codeload.github.com/clickhouse-elixir/clickhouse_ecto/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224364326,"owners_count":17299049,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T18:00:30.522Z","updated_at":"2025-10-21T18:32:03.978Z","avatar_url":"https://github.com/clickhouse-elixir.png","language":"Elixir","funding_links":[],"categories":["Language bindings","Elixir"],"sub_categories":["Elixir"],"readme":"# ClickhouseEcto\n\nEcto adapter for ClickHouse database using [clickhousex driver](http://github.com/appodeal/clickhousex).\n\n## Installation\n\nThe package can be installed\nby adding `clickhouse_ecto` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:clickhouse_ecto, \"~\u003e 0.2.8\"}\n  ]\nend\n\n\n```\n\n## Configuration\nAdd configuration for your repo like this:\n\n```elixir\nconfig :example_app, ExampleApp.ClickHouseRepo,\n       adapter: ClickhouseEcto,\n       loggers: [Ecto.LogEntry],\n       hostname: \"localhost\",\n       port: 8123,\n       database: \"example_app\",\n       username: \"user\",\n       password: \"654321\",\n       timeout: 60_000,\n       pool_timeout: 60_000,\n       ownership_timeout: 60_000,\n       pool_size: 30\n```\n\n## Examples\n\nExample of Ecto model:\n\n```elixir\ndefmodule ExampleApp.Click do\n  use ExampleApp.Web, :model\n\n  @primary_key {:date, :date, []}\n  @timestamps_opts updated_at: false\n\n  schema \"clicks\" do\n    field :site_id, :integer\n    field :source, :string\n    field :ip, :string\n    field :score, :decimal\n    field :width, :integer\n    field :height, :integer\n\n    timestamps()\n  end\n\n  @doc \"\"\"\n  Builds a changeset based on the `struct` and `params`.\n  \"\"\"\n  def changeset(struct, params \\\\ %{}) do\n    struct\n    |\u003e cast(params, [:site_id, :source, :ip, :points, :width, :height, :date])\n    |\u003e validate_required([:date, :site_id])\n  end\nend\n```\n\nDue to ClickHouse does not support data update and uniq rows\nidentifiers, do not forget to set primary key field and turn off\nupdated_at timestamp updating:\n\n```elixir\n  @primary_key {:date, :date, []}\n  @timestamps_opts updated_at: false\n```\n\nExample of data migrations:\n\n```elixir\ndefmodule ExampleApp.Repo.Migrations.CreateClick do\n  use Ecto.Migration\n\n  def change do\n    create_if_not_exists table(:clicks, engine: \"MergeTree(date,(date,inserted_at,source,site_id,ip,score,width,height),8192)\") do\n      add :site_id, :integer, default: 0\n      add :source, :string, default: \"\"\n      add :ip, :string, default: \"\"\n      add :score, :float, default: 0.0\n      add :width, :integer\n      add :height, :integer\n\n      add :date, :date, default: :today\n      timestamps(updated_at: false)\n    end\n  end\nend\n\ndefmodule ExampleApp.Repo.Migrations.AddUserAgentToClicks do\n  use Ecto.Migration\n\n  def change do\n    alter table(:clicks) do\n      add :user_agent, :string\n    end\n  end\nend\n```\n\nQueries examples:\n\n```elixir\niex(1)\u003e ExampleApp.Repo.insert %ExampleApp.Click{site_id: 1, date: Ecto.Date.utc, score: 1.1}\n[debug] QUERY OK db=7.8ms\nINSERT INTO \"clicks\" (\"date\",\"score\",\"site_id\",\"inserted_at\") VALUES (?,?,?,?) [{2018, 4, 5}, 1.1, 1, {{2018, 4, 5}, {8, 18, 30, 727360}}]\n{:ok,\n %ExampleApp.Click{__meta__: #Ecto.Schema.Metadata\u003c:loaded, \"clicks\"\u003e,\n  date: #Ecto.Date\u003c2018-04-05\u003e, height: nil,\n  inserted_at: ~N[2018-04-05 08:18:30.727360], ip: nil, score: 1.1, site_id: 1,\n  source: nil, width: nil}}\niex(2)\u003e ExampleApp.Repo.all ExampleApp.Click\n[debug] QUERY OK source=\"clicks\" db=11.8ms\nSELECT c0.\"date\", c0.\"site_id\", c0.\"source\", c0.\"ip\", c0.\"score\", c0.\"width\", c0.\"height\", c0.\"inserted_at\" FROM \"clicks\" AS c0 []\n[%ExampleApp.Click{__meta__: #Ecto.Schema.Metadata\u003c:loaded, \"clicks\"\u003e,\n  date: ~D[2018-04-05], height: 0, inserted_at: ~N[2018-04-05 09:15:42.000000],\n  ip: \"\", score: #Decimal\u003c1.1\u003e, site_id: 1, source: \"\", width: 0}]\n```\n\nDocumentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)\nand published on [HexDocs](https://hexdocs.pm). Once published, the docs can\nbe found at [https://hexdocs.pm/clickhouse_ecto](https://hexdocs.pm/clickhouse_ecto).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclickhouse-elixir%2Fclickhouse_ecto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclickhouse-elixir%2Fclickhouse_ecto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclickhouse-elixir%2Fclickhouse_ecto/lists"}