From e782edd6b1812a6d608ae65efbed4e0658a38b0c Mon Sep 17 00:00:00 2001 From: Giovanni Visciano Date: Thu, 31 Mar 2022 18:17:09 +0200 Subject: [PATCH] doc --- README.md | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index bc0dca8..fe0d5c8 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,14 @@ res = Postgrex.query!(conn, "select x, y from table", []) ### Named parameters query +This function can be used to get rid of the query positional parameters and use named ones. + ```elixir -{:ok, q, p} = Exql.Query.named_params("insert into a_table (x, y1, y2) values (:x, :y, :y)", %{x: "X", y: "Y"}) +# positional parameters: +Postgrex.query!(conn, "insert into a_table (x, y1, y2) values ($1, $2, $2)", ["X", "Y"]) +# named parameters: +{:ok, q, p} = Exql.Query.named_params("insert into a_table (x, y1, y2) values (:x, :y, :y)", %{x: "X", y: "Y"}) Postgrex.query!(conn, q, p) ``` @@ -34,15 +39,7 @@ def query!(conn, stmt, args \\ %{}, opts \\ []) do end ``` -so that this: - -```elixir -{:ok, q, p} = Exql.Query.named_params("insert into a_table (x, y1, y2) values (:x, :y, :y)", %{x: "X", y: "Y"}) -res = Postgrex.query!(conn, q, p) -Exql.Query.result_to_map(res) -``` - -become this: +And just write: ```elixir query!("insert into a_table (x, y1, y2) values (:x, :y, :y)", %{x: "X", y: "Y"})