Skip to content

Add support for PostgreSQL GiST operators #17 #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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/lexer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ defmodule SQL.Lexer do
acc = if type, do: insert_node(node(ident(type, data), line, column, data, opts), acc), else: acc
lex(rest, binary, opts, line, column, nil, [], insert_node(node(type(b), line, column+1, [], opts), acc), n)
end
def lex(<<b::binary-size(3), rest::binary>>, binary, opts, line, column, type, data, acc, n) when b in ~w[^-= |*= <=>] do
def lex(<<b::binary-size(3), rest::binary>>, binary, opts, line, column, type, data, acc, n) when b in ~w[^-= |*= <=> <-> >>= &<| <<| |>> |&> -|-] do
node = node(String.to_atom(b), line, column+3, [], opts)
if data == [] do
lex(rest, binary, opts, line, column+3, type, data, insert_node(node, acc), n)
else
lex(rest, binary, opts, line, column+3, nil, [], insert_node(node, insert_node(node(ident(type, data), line, column, data, opts), acc)), n)
end
end
def lex(<<b::binary-size(2), rest::binary>>, binary, opts, line, column, type, data, acc, n) when b in ~w[:: <> != !< !> <= >= += -= *= /= %= &= ||] do
def lex(<<b::binary-size(2), rest::binary>>, binary, opts, line, column, type, data, acc, n) when b in ~w[:: <> != !< !> <= >= += -= *= /= %= &= || << &< && &> >> ~= @> <@ @@] do
node = node(String.to_atom(b), line, column+2, [], opts)
if data == [] do
lex(rest, binary, opts, line, column+2, type, data, insert_node(node, acc), n)
Expand Down
4 changes: 2 additions & 2 deletions lib/mix/tasks/sql.gen.parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,15 @@ defmodule Mix.Tasks.Sql.Gen.Parser do
acc = if type, do: insert_node(node(ident(type, data), line, column, data, opts), acc), else: acc
lex(rest, binary, opts, line, column, nil, [], insert_node(node(type(b), line, column+1, [], opts), acc), n)
end
def lex(<<b::binary-size(3), rest::binary>>, binary, opts, line, column, type, data, acc, n) when b in ~w[^-= |*= <=>] do
def lex(<<b::binary-size(3), rest::binary>>, binary, opts, line, column, type, data, acc, n) when b in ~w[^-= |*= <=> <-> >>= &<| <<| |>> |&> -|-] do
node = node(String.to_atom(b), line, column+3, [], opts)
if data == [] do
lex(rest, binary, opts, line, column+3, type, data, insert_node(node, acc), n)
else
lex(rest, binary, opts, line, column+3, nil, [], insert_node(node, insert_node(node(ident(type, data), line, column, data, opts), acc)), n)
end
end
def lex(<<b::binary-size(2), rest::binary>>, binary, opts, line, column, type, data, acc, n) when b in ~w[:: <> != !< !> <= >= += -= *= /= %= &= ||] do
def lex(<<b::binary-size(2), rest::binary>>, binary, opts, line, column, type, data, acc, n) when b in ~w[:: <> != !< !> <= >= += -= *= /= %= &= || << &< && &> >> ~= @> <@ @@] do
node = node(String.to_atom(b), line, column+2, [], opts)
if data == [] do
lex(rest, binary, opts, line, column+2, type, data, insert_node(node, acc), n)
Expand Down
48 changes: 48 additions & 0 deletions test/adapters/postgres_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,54 @@ defmodule SQL.Adapters.PostgresTest do
assert "where id <= 1" == to_string(~SQL[where id <= 1])
assert "where id <= 1" == to_string(~SQL[where id<=1])
end
test "<<" do
assert "where id << 1" == to_string(~SQL[where id << 1])
end
test "&<" do
assert "where id &< 1" == to_string(~SQL[where id &< 1])
end
test "&&" do
assert "where id && 1" == to_string(~SQL[where id && 1])
end
test "&>" do
assert "where id &> 1" == to_string(~SQL[where id &> 1])
end
test ">>" do
assert "where id >> 1" == to_string(~SQL[where id >> 1])
end
test "~=" do
assert "where id ~= 1" == to_string(~SQL[where id ~= 1])
end
test "@>" do
assert "where id @> 1" == to_string(~SQL[where id @> 1])
end
test "<@" do
assert "where id <@ 1" == to_string(~SQL[where id <@ 1])
end
test "&<|" do
assert "where id &<| 1" == to_string(~SQL[where id &<| 1])
end
test "<<|" do
assert "where id <<| 1" == to_string(~SQL[where id <<| 1])
end
test "|>>" do
assert "where id |>> 1" == to_string(~SQL[where id |>> 1])
end
test "|&>" do
assert "where id |&> 1" == to_string(~SQL[where id |&> 1])
end
test "@@" do
assert "where id @@ 1" == to_string(~SQL[where id @@ 1])
end
test "<->" do
assert "where id <-> 1" == to_string(~SQL[where id <-> 1])
end
test ">>=" do
assert "where id <-> 1" == to_string(~SQL[where id <-> 1])
end
test "-|-" do
assert "where id -|- 1" == to_string(~SQL[where id -|- 1])
end
test "between" do
assert "where id between 1 and 2" == to_string(~SQL[where id between 1 and 2])
assert "where id not between 1 and 2" == to_string(~SQL[where id not between 1 and 2])
Expand Down