Skip to content

Commit

Permalink
Use a Query message for parameterless executes
Browse files Browse the repository at this point in the history
`execute` uses a significantly more complicated protocol (parse, prepare,
execute) and we should avoid that overhead if we don't actually need
parameters.

I didn't do this with execute_iter or execute_fold because the
simple_query interface doesn't have those versions yet.
  • Loading branch information
brendanlong committed Oct 26, 2018
1 parent 3a4252e commit 2eae60a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pgx/src/pgx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,17 @@ module Make (Thread : IO) = struct
simple_query' dbh query)

let execute ?(params=[]) db query =
Prepared.(with_prepare db ~query ~f:(fun s ->
match params with
| [] ->
simple_query db query
>>| (function
| rows :: [] -> rows
| results ->
fail_msg "Pgx.execute: Query returned %d result sets but \
execute should only ever return one. Query was: %s"
(List.length results) query)
| _ ->
Prepared.(with_prepare db ~query ~f:(fun s ->
execute s ~params))

let execute_iter ?(params=[]) db query ~f =
Expand Down

0 comments on commit 2eae60a

Please sign in to comment.