Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/feeb/db/query/binding.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ defmodule Feeb.DB.Query.Binding do

defp parse_kv(sql) do
sql
|> String.split(" = ?")
|> String.split(" ?")
|> List.delete_at(-1)
|> Enum.map(fn expr ->
expr
|> String.split(" ")
|> Enum.at(-1)
|> Enum.at(-2)
|> String.to_atom()
end)
end
Expand Down
20 changes: 20 additions & 0 deletions test/db/query/binding_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
defmodule Feeb.DB.Query.BindingTest do
use ExUnit.Case, async: true

alias Feeb.DB.Query.Binding

describe "parse_params/3" do
test "returns the expected params bindings (SELECT)" do
[
{"select * from users where id = ?;", [:id]},
{"select * from users where id = ? and name = ?;", [:id, :name]},
{"select * from users where inserted_at >= ?", [:inserted_at]},
{"select * from foo where id > ? and id < ?", [:id, :id]},
{"select * from foo where bar <= ? or id = ?", [:bar, :id]}
]
|> Enum.each(fn {sql, expected_bindings} ->
assert expected_bindings == Binding.parse_params(:select, sql, [])
end)
end
end
end