Skip to content

Commit c1446c2

Browse files
committed
add Ecto.Adapters.SQL.Constraint
1 parent 14a73ac commit c1446c2

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/ecto/adapters/sql.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ defmodule Ecto.Adapters.SQL do
658658
sql_call(adapter_meta, :query_many, [sql], params, opts)
659659
end
660660

661+
@doc false
661662
def to_constraints(adapter_meta, opts, err, err_opts) do
662663
%{constraint_handler: constraint_handler} = adapter_meta
663664
constraint_handler = Keyword.get(opts, :constraint_handler) || constraint_handler

lib/ecto/adapters/sql/constraint.ex

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
defmodule Ecto.Adapters.SQL.Constraint do
2+
@moduledoc """
3+
Specifies the constraint handling API
4+
"""
5+
6+
@doc """
7+
Receives the exception returned by `c:Ecto.Adapters.SQL.Connection.query/4`.
8+
9+
The constraints are in the keyword list and must return the
10+
constraint type, like `:unique`, and the constraint name as
11+
a string, for example:
12+
13+
[unique: "posts_title_index"]
14+
15+
Must return an empty list if the error does not come
16+
from any constraint.
17+
"""
18+
@callback to_constraints(exception :: Exception.t(), options :: Keyword.t()) :: Keyword.t()
19+
end

0 commit comments

Comments
 (0)