Skip to content

Commit

Permalink
add Ecto.Adapters.SQL.Constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
petermueller committed Jul 29, 2024
1 parent 849a417 commit e5ea9f6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/ecto/adapters/sql.ex
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ defmodule Ecto.Adapters.SQL do
sql_call(adapter_meta, :query_many, [sql], params, opts)
end

@doc false
def to_constraints(adapter_meta, opts, err, err_opts) do
%{constraint_handler: constraint_handler} = adapter_meta
constraint_handler = Keyword.get(opts, :constraint_handler) || constraint_handler
Expand Down
19 changes: 19 additions & 0 deletions lib/ecto/adapters/sql/constraint.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
defmodule Ecto.Adapters.SQL.Constraint do
@moduledoc """
Specifies the constraint handling API
"""

@doc """
Receives the exception returned by `c:Ecto.Adapters.SQL.Connection.query/4`.
The constraints are in the keyword list and must return the
constraint type, like `:unique`, and the constraint name as
a string, for example:
[unique: "posts_title_index"]
Must return an empty list if the error does not come
from any constraint.
"""
@callback to_constraints(exception :: Exception.t(), options :: Keyword.t()) :: Keyword.t()
end

0 comments on commit e5ea9f6

Please sign in to comment.