mirror of
https://github.com/lloeki/rebel.git
synced 2025-12-06 10:04:39 +01:00
date, time, datetime values support
This commit is contained in:
parent
075957be04
commit
9b6e871b1b
2 changed files with 13 additions and 0 deletions
|
|
@ -278,6 +278,7 @@ module Rebel::SQL
|
||||||
when String then raw "'#{escape_str(v)}'"
|
when String then raw "'#{escape_str(v)}'"
|
||||||
when Integer then raw v.to_s
|
when Integer then raw v.to_s
|
||||||
when TrueClass, FalseClass then raw(v ? 'TRUE' : 'FALSE')
|
when TrueClass, FalseClass then raw(v ? 'TRUE' : 'FALSE')
|
||||||
|
when Date, Time, DateTime then value(v.iso8601)
|
||||||
when nil then raw 'NULL'
|
when nil then raw 'NULL'
|
||||||
else raise NotImplementedError, v.inspect
|
else raise NotImplementedError, v.inspect
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -80,4 +80,16 @@ class TestRaw < Minitest::Test
|
||||||
def test_function
|
def test_function
|
||||||
assert_str_equal(Rebel::SQL.function('COALESCE', :foo, 0), 'COALESCE("foo", 0)')
|
assert_str_equal(Rebel::SQL.function('COALESCE', :foo, 0), 'COALESCE("foo", 0)')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_value
|
||||||
|
assert_str_equal(Rebel::SQL.value(Rebel::SQL.raw("'FOO'")), "'FOO'")
|
||||||
|
assert_str_equal(Rebel::SQL.value('FOO'), "'FOO'")
|
||||||
|
assert_str_equal(Rebel::SQL.value(1), '1')
|
||||||
|
assert_str_equal(Rebel::SQL.value(true), 'TRUE')
|
||||||
|
assert_str_equal(Rebel::SQL.value(false), 'FALSE')
|
||||||
|
assert_str_equal(Rebel::SQL.value(Date.new(2016, 12, 31)), "'2016-12-31'")
|
||||||
|
assert_str_equal(Rebel::SQL.value(Time.utc(2016, 12, 31, 23, 59, 59)), "'2016-12-31T23:59:59Z'")
|
||||||
|
assert_str_equal(Rebel::SQL.value(DateTime.new(2016, 12, 31, 23, 59, 59)), "'2016-12-31T23:59:59+00:00'")
|
||||||
|
assert_str_equal(Rebel::SQL.value(nil), 'NULL')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue