Skip to content

Commit

Permalink
more consistent docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tessi committed Jul 17, 2023
1 parent 009f427 commit adc7356
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ defmodule TestQuery do
right = 2

query = from u in "users",
select: named_fragment("coalesce(:left, :right)", left: left, right: right)
select: named_fragment("coalesce(:left, :right)", left: "example", right: "input")

Repo.all(query)
end
Expand Down
14 changes: 4 additions & 10 deletions lib/ecto_named_fragment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ defmodule EctoNamedFragment do
```elixir
defmodule TestQuery do
import Ecto.Query
import EctoNamedFragment
use EctoNamedFragment
def test_query do
left = 1
right = 2
query = from u in "users",
select: named_fragment("coalesce(:left, :right)", left: left, right: right)
select: named_fragment("coalesce(:left, :right)", left: "example", right: "input")
Repo.all(query)
end
Expand All @@ -40,17 +37,14 @@ defmodule EctoNamedFragment do
fragment with positioned params.
```elixir
frag("coalesce(:left, :right)", left: left, right: right)
named_fragment("coalesce(:left, :right)", left: "example", right: "input")
```
into
```elixir
fragment("coalesce(?, ?)", left, right)
fragment("coalesce(?, ?)", "example", "input")
```
This conversion is done at compile-time (d'oh! it's a macro, right :)).
Thus, it's not possible to dynamically create the query-string at runtime.
"""
defmacro named_fragment(query, args) when is_binary(query) and is_list(args) do
case ConvertToPositionedArgs.call(query, args) do
Expand Down

0 comments on commit adc7356

Please sign in to comment.