Skip to content

Commit 12a498e

Browse files
authored
fixes insert for newer ver of ecto and constraints (plausible#2)
1 parent 455b0a2 commit 12a498e

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/clickhouse_ecto/connection.ex

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,16 @@ defmodule ClickhouseEcto.Connection do
114114
end)
115115
end
116116

117-
def to_constraints(_error), do: []
117+
def to_constraints(%Clickhousex.Error{code: "469", message: message}, _opts) do
118+
pattern = ~r/(?<= Constraint `)(?<constraint_name>.*?)(?=` for table)/
119+
120+
case Regex.named_captures(pattern, message) do
121+
%{"constraint_name" => constraint} -> [check: constraint]
122+
_ -> []
123+
end
124+
end
125+
126+
def to_constraints(_error, _opts), do: []
118127

119128
@doc """
120129
Returns a stream that prepares and executes the given query with `DBConnection`.
@@ -139,7 +148,7 @@ defmodule ClickhouseEcto.Connection do
139148
@doc false
140149
def delete_all(query), do: SQL.delete_all(query)
141150

142-
def insert(prefix, table, header, rows, on_conflict, returning),
151+
def insert(prefix, table, header, rows, on_conflict, returning, _opts),
143152
do: SQL.insert(prefix, table, header, rows, on_conflict, returning)
144153

145154
def update(prefix, table, fields, filters, returning),

test/clickhouse_ecto_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ defmodule ClickhouseEctoTest do
2525
defp all(query), do: query |> SQL.all() |> IO.iodata_to_binary()
2626

2727
defp insert(prefx, table, header, rows, on_conflict, returning) do
28-
IO.iodata_to_binary(SQL.insert(prefx, table, header, rows, on_conflict, returning))
28+
IO.iodata_to_binary(SQL.insert(prefx, table, header, rows, on_conflict, returning, []))
2929
end
3030

3131
test "from" do

0 commit comments

Comments
 (0)