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

View file

@ -70,7 +70,7 @@ module DB
# Types supported to interface with database driver. # Types supported to interface with database driver.
# These can be used in any `ResultSet#read` or any `Database#query` related # These can be used in any `ResultSet#read` or any `Database#query` related
# method to be used as query parameters # 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` # 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) alias Any = Nil | String | Int32 | Int64 | Float32 | Float64 | Slice(UInt8)

View file

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