This commit is contained in:
Loic Nageleisen 2017-03-20 15:56:36 +01:00
parent 3c2d41788c
commit 06ff4227af
2 changed files with 8 additions and 0 deletions

View file

@ -137,6 +137,10 @@ module Rebel::SQL
def in(*v) def in(*v)
Raw.new("#{self} IN (#{Rebel::SQL.values(*v)})") Raw.new("#{self} IN (#{Rebel::SQL.values(*v)})")
end end
def like(n)
Raw.new("#{self} LIKE #{Rebel::SQL.value(n)}")
end
end end
@identifier_quote = '"' @identifier_quote = '"'

View file

@ -67,6 +67,10 @@ class TestRaw < Minitest::Test
assert_str_equal(Rebel::SQL.name(:foo).in(1, 2, 3), '"foo" IN (1, 2, 3)') assert_str_equal(Rebel::SQL.name(:foo).in(1, 2, 3), '"foo" IN (1, 2, 3)')
end end
def test_like
assert_str_equal(Rebel::SQL.name(:foo).like('%bar%'), %("foo" LIKE '%bar%'))
end
def test_where def test_where
assert_str_equal(Rebel::SQL.where?(foo: 1, bar: 2, baz: 3), 'WHERE "foo" = 1 AND "bar" = 2 AND "baz" = 3') assert_str_equal(Rebel::SQL.where?(foo: 1, bar: 2, baz: 3), 'WHERE "foo" = 1 AND "bar" = 2 AND "baz" = 3')
assert_str_equal(Rebel::SQL.where?(Rebel::SQL.name(:foo).eq(1).or(Rebel::SQL.name(:bar).eq(2)), Rebel::SQL.name(:baz).eq(3)), 'WHERE ("foo" = 1 OR "bar" = 2) AND "baz" = 3') assert_str_equal(Rebel::SQL.where?(Rebel::SQL.name(:foo).eq(1).or(Rebel::SQL.name(:bar).eq(2)), Rebel::SQL.name(:baz).eq(3)), 'WHERE ("foo" = 1 OR "bar" = 2) AND "baz" = 3')