Skip to content

Commit bd58aee

Browse files
committed
Closes elixir-sqlite#202 - Basic support for UNIQUE constraint changeset errors.
1 parent a311dc5 commit bd58aee

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/sqlite_ecto/connection.ex

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ if Code.ensure_loaded?(Sqlitex.Server) do
1414
DBConnection.child_spec(Sqlite.DbConnection.Protocol, opts)
1515
end
1616

17+
def to_constraints(%Sqlite.DbConnection.Error{sqlite: %{code: :constraint}, message: message}) do
18+
case :binary.split(message, " constraint failed: ") do
19+
["UNIQUE", field] -> [unique: String.replace(field, ".", "_") <> "_index"]
20+
_ -> []
21+
end
22+
end
23+
1724
def to_constraints(_), do: []
1825

1926
## Query

0 commit comments

Comments
 (0)