make Nil a proper column type

This commit is contained in:
Brian J. Cardiff 2016-04-10 21:21:10 +03:00
parent f834b0f8a6
commit d69555b372
3 changed files with 12 additions and 3 deletions

View file

@ -55,7 +55,7 @@ class DummyDriver < DB::Driver
private def set_params(args)
@params.clear
args.each_with_index do |arg, index|
@params[index] = arg
@params[index] = arg.as(DB::Any)
end
end
@ -114,12 +114,16 @@ class DummyDriver < DB::Driver
return nil if n == "NULL"
if n == "?"
return @statement.params[0]
return (@statement.as(DummyStatement)).params[0]
end
return n
end
def read?(t : Nil.class)
read?.as(Nil)
end
def read?(t : String.class)
read?.try &.to_s
end

View file

@ -70,7 +70,7 @@ module DB
# Types supported to interface with database driver.
# These can be used in any `ResultSet#read` or any `Database#query` related
# method to be used as query parameters
TYPES = [String, Int32, Int64, Float32, Float64, Slice(UInt8)]
TYPES = [Nil, String, Int32, Int64, Float32, Float64, Slice(UInt8)]
# See `DB::TYPES` in `DB`. `Any` is a nillable version of the union of all types in `DB::TYPES`
alias Any = Nil | String | Int32 | Int64 | Float32 | Float64 | Slice(UInt8)

View file

@ -72,6 +72,11 @@ module DB
end
{% end %}
# Reads the next column as a Nil.
def read(t : Nil.class) : Nil
read?(Nil)
end
# def read_blob
# yield ... io ....
# end