mirror of
https://github.com/lloeki/rebel.git
synced 2025-12-06 01:54:40 +01:00
arbitrary functions
This commit is contained in:
parent
892b21eaf8
commit
448a342d5f
2 changed files with 13 additions and 0 deletions
|
|
@ -218,6 +218,11 @@ module Rebel::SQL
|
||||||
|
|
||||||
## Functions
|
## Functions
|
||||||
|
|
||||||
|
def function(name, *args)
|
||||||
|
raw("#{name}(#{names_or_values(*args)})")
|
||||||
|
end
|
||||||
|
alias fn function
|
||||||
|
|
||||||
def count(*n)
|
def count(*n)
|
||||||
raw("COUNT(#{names(*n)})")
|
raw("COUNT(#{names(*n)})")
|
||||||
end
|
end
|
||||||
|
|
@ -282,6 +287,10 @@ module Rebel::SQL
|
||||||
item.is_a?(Symbol) ? name(item) : value(item)
|
item.is_a?(Symbol) ? name(item) : value(item)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def names_or_values(*items)
|
||||||
|
list(items.map { |v| name_or_value(v) })
|
||||||
|
end
|
||||||
|
|
||||||
def equal(l, r)
|
def equal(l, r)
|
||||||
"#{name_or_value(l)} = #{name_or_value(r)}"
|
"#{name_or_value(l)} = #{name_or_value(r)}"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -68,4 +68,8 @@ class TestRaw < Minitest::Test
|
||||||
def test_join
|
def test_join
|
||||||
assert_str_equal(Rebel::SQL.join(:foo), 'JOIN "foo"')
|
assert_str_equal(Rebel::SQL.join(:foo), 'JOIN "foo"')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_function
|
||||||
|
assert_str_equal(Rebel::SQL.function('COALESCE', :foo, 0), 'COALESCE("foo", 0)')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue