Skip to content

Commit

Permalink
prepare without locking mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
dlindenkreuz committed Jan 5, 2024
1 parent e0285a8 commit 8bb1ded
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions lib/adbc_connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ defmodule Adbc.Connection do
"""
@spec prepare(t(), binary) :: {:ok, reference} | {:error, Exception.t()}
def prepare(conn, query) when is_binary(query) do
stream_lock(conn, {:prepare, query}, fn ref, _ -> {:ok, ref} end)
with stmt <- create_statement(conn, query),
:ok <- Adbc.Nif.adbc_statement_prepare(stmt) do
{:ok, stmt}
end
end

@doc """
Expand Down Expand Up @@ -275,13 +278,6 @@ defmodule Adbc.Connection do

defp stream_lock(conn, command, fun) do
case GenServer.call(conn, {:stream_lock, command}, :infinity) do
{:ok, conn, unlock_ref, statement_ref} ->
try do
statement_ref
after
GenServer.cast(conn, {:unlock, unlock_ref})
end

{:ok, conn, unlock_ref, stream_ref, rows_affected} ->
try do
fun.(stream_ref, normalize_rows(rows_affected))
Expand Down Expand Up @@ -371,11 +367,6 @@ defmodule Adbc.Connection do
{pid, _} = from

case handle_command(command, state.conn) do
{:ok, statement_ref} when is_reference(statement_ref) ->
unlock_ref = Process.monitor(pid)
GenServer.reply(from, {:ok, self(), unlock_ref, statement_ref})
%{state | lock: unlock_ref, queue: queue}

{:ok, stream_ref, rows_affected} when is_reference(stream_ref) ->
unlock_ref = Process.monitor(pid)
GenServer.reply(from, {:ok, self(), unlock_ref, stream_ref, rows_affected})
Expand Down Expand Up @@ -403,13 +394,6 @@ defmodule Adbc.Connection do
end
end

defp handle_command({:prepare, query}, conn) do
with stmt <- create_statement(conn, query),
:ok <- Adbc.Nif.adbc_statement_prepare(stmt) do
{:ok, stmt, -1}
end
end

defp handle_command({name, args}, conn) do
with {:ok, stream_ref} <- apply(Adbc.Nif, name, [conn | args]) do
{:ok, stream_ref, -1}
Expand Down

0 comments on commit 8bb1ded

Please sign in to comment.