Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/ecto/adapters/libsql/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ defmodule Ecto.Adapters.LibSql.Connection do
end

@impl true
@doc """
Parse a SQLite error message and map it to a list of Ecto constraint tuples.

Accepts an exception-like map containing a SQLite error `:message` and returns recognised constraint information such as unique, foreign_key or check constraints; returns an empty list when no known constraint pattern is found.

## Parameters

- error: Map containing a `:message` string produced by SQLite.
- _opts: Options (unused).

## Returns

- A keyword list of constraint tuples, for example `[unique: "table_column_index"]`, `[foreign_key: :unknown]`, `[check: "constraint_name"]`, or `[]` when no constraint is recognised.
"""
@spec to_constraints(%{message: String.t()}, Keyword.t()) :: Keyword.t()
def to_constraints(%{message: message}, _opts) do
cond do
String.contains?(message, "UNIQUE constraint failed") ->
Expand Down