From 9c0460bfef2976ec49ea11fce158e91794b588f5 Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Wed, 17 Dec 2025 02:43:32 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=93=9D=20Add=20docstrings=20to=20`fix?= =?UTF-8?q?-constraint-errors`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docstrings generation was requested by @ocean. * https://github.com/ocean/ecto_libsql/pull/35#issuecomment-3663385463 The following files were modified: * `lib/ecto/adapters/libsql/connection.ex` --- lib/ecto/adapters/libsql/connection.ex | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/ecto/adapters/libsql/connection.ex b/lib/ecto/adapters/libsql/connection.ex index c69a385d..52206eb3 100644 --- a/lib/ecto/adapters/libsql/connection.ex +++ b/lib/ecto/adapters/libsql/connection.ex @@ -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") -> @@ -1032,4 +1047,4 @@ defmodule Ecto.Adapters.LibSql.Connection do defp intersperse_reduce([], _separator, count, [], _reducer) do {[], count} end -end +end \ No newline at end of file From 132e10edf79ebddb812011bc428158b12c5c1ec5 Mon Sep 17 00:00:00 2001 From: Drew Robinson Date: Wed, 17 Dec 2025 13:56:02 +1100 Subject: [PATCH 2/2] Clean up documentation formatting in connection.ex Removed unnecessary blank lines in the documentation for the to_constraints function. --- lib/ecto/adapters/libsql/connection.ex | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/ecto/adapters/libsql/connection.ex b/lib/ecto/adapters/libsql/connection.ex index 52206eb3..7d60029e 100644 --- a/lib/ecto/adapters/libsql/connection.ex +++ b/lib/ecto/adapters/libsql/connection.ex @@ -68,16 +68,16 @@ defmodule Ecto.Adapters.LibSql.Connection do @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() @@ -1047,4 +1047,4 @@ defmodule Ecto.Adapters.LibSql.Connection do defp intersperse_reduce([], _separator, count, [], _reducer) do {[], count} end -end \ No newline at end of file +end