Skip to content

Commit e5ea9f6

Browse files
committed
add Ecto.Adapters.SQL.Constraint
1 parent 849a417 commit e5ea9f6

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/ecto/adapters/sql.ex

+1
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ defmodule Ecto.Adapters.SQL do
644644
sql_call(adapter_meta, :query_many, [sql], params, opts)
645645
end
646646

647+
@doc false
647648
def to_constraints(adapter_meta, opts, err, err_opts) do
648649
%{constraint_handler: constraint_handler} = adapter_meta
649650
constraint_handler = Keyword.get(opts, :constraint_handler) || constraint_handler

lib/ecto/adapters/sql/constraint.ex

+19
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)