Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/sql_dust/utils/path_utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ defmodule SqlDust.PathUtils do
end

defp scan_and_prepend_path_aliases(sql, options) do
~r/(?:\.\*|\w+[a-zA-Z]+\w*(?:\.(?:\*|\w{2,}))*)/
~r/(?:\.\*|\w*[a-zA-Z_\$]\w*(?:\.(?:\*|\w{2,}))*)/
|> Regex.split(sql, [include_captures: true])
|> analyze_aliases([], options, false)
end
Expand Down
28 changes: 28 additions & 0 deletions test/sql_dust_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,34 @@ defmodule SqlDustTest do
""", []}
end

test "selecting weirdly named columns of the base resource (passing a list)" do
options = %{
select: ["id", "first_name", "last_name", "m2"]
}

assert SqlDust.from("users", options) == {
"SELECT\n `u`.`id`,\n `u`.`first_name`,\n `u`.`last_name`,\n `u`.`m2`\nFROM `users` `u`\n",
[]}
end

test "selecting weirdly named columns of the base resource (passing a map)" do
options = %{
select: ["id", "name", "m2"],
where: [
["name LIKE ? OR name LIKE ?", "%Paul%", "%Engel%"]
]
}

assert SqlDust.from("users", options) == {
"""
SELECT `u`.`id`, `u`.`name`, `u`.`m2`
FROM `users` `u`
WHERE (`u`.`name` LIKE ? OR `u`.`name` LIKE ?)
""",
["%Paul%", "%Engel%"]
}
end

test "interpolating variables" do
options = %{
select: ["id", "CONCAT(name, <<postfix>>)"],
Expand Down