From 8a70b853dde2b0ee2b7093481c16c0b1d3dda8c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20=C5=9Awi=C4=85tkowski?= Date: Tue, 14 Jul 2026 13:10:56 +0200 Subject: [PATCH 1/2] Delete duplicated function It looks like a remnant from a time when adding query caching was attempted, but later was abandoned. --- lib/exqlite/connection.ex | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/lib/exqlite/connection.ex b/lib/exqlite/connection.ex index 261c4b54..8f3d7e68 100644 --- a/lib/exqlite/connection.ex +++ b/lib/exqlite/connection.ex @@ -374,7 +374,7 @@ defmodule Exqlite.Connection do def handle_declare(%Query{} = query, params, opts, state) do # We emulate cursor functionality by just using a prepared statement and # step through it. Thus we just return the query ref as the cursor. - with {:ok, query} <- prepare_no_cache(query, opts, state), + with {:ok, query} <- prepare(query, opts, state), {:ok, query} <- bind_params(query, params, state) do {:ok, query, query.ref, state} end @@ -627,25 +627,10 @@ defmodule Exqlite.Connection do end end - # Attempt to retrieve the cached query, if it doesn't exist, we'll prepare one - # and cache it for later. defp prepare(%Query{statement: statement} = query, options, state) do query = maybe_put_command(query, options) - with {:ok, ref} <- Sqlite3.prepare(state.db, IO.iodata_to_binary(statement)), - query <- %{query | ref: ref} do - {:ok, query} - else - {:error, reason} -> - {:error, %Error{message: to_string(reason), statement: statement}, state} - end - end - - # Prepare a query and do not cache it. - defp prepare_no_cache(%Query{statement: statement} = query, options, state) do - query = maybe_put_command(query, options) - - case Sqlite3.prepare(state.db, statement) do + case Sqlite3.prepare(state.db, IO.iodata_to_binary(statement)) do {:ok, ref} -> {:ok, %{query | ref: ref}} From 42e4355996756418cfaa9504cd8b05f4d3e5ef02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20=C5=9Awi=C4=85tkowski?= Date: Tue, 14 Jul 2026 13:21:10 +0200 Subject: [PATCH 2/2] Fix typespecs --- lib/exqlite.ex | 2 +- lib/exqlite/connection.ex | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/exqlite.ex b/lib/exqlite.ex index af42a7f5..df5f704a 100644 --- a/lib/exqlite.ex +++ b/lib/exqlite.ex @@ -64,7 +64,7 @@ defmodule Exqlite do end @spec execute(DBConnection.conn(), Query.t(), list(), list()) :: - {:ok, Result.t()} | {:error, Error.t()} + {:ok, DBConnection.Query.t(), Result.t()} | {:error, Error.t()} def execute(conn, query, params, opts \\ []) do DBConnection.execute(conn, query, params, opts) end diff --git a/lib/exqlite/connection.ex b/lib/exqlite/connection.ex index 8f3d7e68..d08b4bb3 100644 --- a/lib/exqlite/connection.ex +++ b/lib/exqlite/connection.ex @@ -48,7 +48,7 @@ defmodule Exqlite.Connection do transaction_status: :idle | :transaction, status: :idle | :busy, chunk_size: integer(), - before_disconnect: (t -> any) | {module, atom, [any]} | nil + before_disconnect: (Exception.t(), t -> any) | {module, atom, [any]} | nil } @type journal_mode() :: :delete | :truncate | :persist | :memory | :wal | :off @@ -81,7 +81,8 @@ defmodule Exqlite.Connection do | {:hard_heap_limit, integer()} | {:key, String.t()} | {:custom_pragmas, [{keyword(), integer() | boolean() | String.t()}]} - | {:before_disconnect, (t -> any) | {module, atom, [any]} | nil} + | {:before_disconnect, + (Exception.t(), t -> any) | {module, atom, [any]} | nil} @impl true @doc """