Skip to content

Commit

Permalink
set postgrex_prepare in query
Browse files Browse the repository at this point in the history
  • Loading branch information
dkuku committed Oct 13, 2024
1 parent 409d07d commit a5121fb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/postgrex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ defmodule Postgrex do
@spec query(conn, iodata, list, [execute_option]) ::
{:ok, Postgrex.Result.t()} | {:error, Exception.t()}
def query(conn, statement, params, opts \\ []) do
prepare? = !Keyword.get(opts, :comment)
opts = Keyword.put(opts, :postgrex_prepare, prepare?)

if name = Keyword.get(opts, :cache_statement) do
query = %Query{name: name, cache: :statement, statement: IO.iodata_to_binary(statement)}

Expand Down
6 changes: 3 additions & 3 deletions lib/postgrex/protocol.ex
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,11 @@ defmodule Postgrex.Protocol do
if new_query = cached_query(s, query) do
{:ok, new_query, s}
else
prepare = Keyword.get(opts, :postgrex_prepare, false)
status = new_status(opts, prepare: prepare)
prepare? = Keyword.get(opts, :postgrex_prepare, false)
status = new_status(opts, prepare: prepare?)

result =
case prepare do
case prepare? do
true -> close_parse_describe(s, status, query)
false -> close_parse_describe_flush(s, status, query)
end
Expand Down

0 comments on commit a5121fb

Please sign in to comment.