#5 remove read_object. allow read / read? to receive any type

This commit is contained in:
Brian J. Cardiff 2016-06-21 12:10:09 -03:00
parent 0daa1c18d7
commit 9f3f0a9836
2 changed files with 74 additions and 31 deletions

View file

@ -16,14 +16,10 @@ module DB
# ### Note to implementors
#
# 1. Override `#move_next` to move to the next row.
# 2. Override `#read?(t)` for all `t` in `DB::TYPES`.
# 3. (Optional) Override `#read(t)` for all `t` in `DB::TYPES`.
# 2. Override `#read?(t)` for all `t` in `DB::TYPES` and any other types the driver should handle.
# 3. (Optional) Override `#read(t)` for all `t` in `DB::TYPES` and any other.
# 4. Override `#column_count`, `#column_name`.
# 5. Override `#column_type`. It must return a type in `DB::TYPES`.
# 6. Override `#read_object` to return other data types not included in `DB::TYPES`. This
# will create a union type, so user will be forced to cast result type. Usually `#read`
# should be used to avoid unnecesary intermediate union type values. Calling `#read_object`
# should also move to the next column.
abstract class ResultSet
include Disposable
@ -63,28 +59,26 @@ module DB
# The result is one of `DB::TYPES`.
abstract def column_type(index : Int32)
# list datatypes that must be supported form the driver
# users will call read(String) or read?(String) for nillables
{% for t in DB::TYPES %}
# Reads the next column as a nillable {{t}}.
abstract def read?(t : {{t}}.class) : {{t}}?
# Reads the next column as a {{t}}.
def read(t : {{t}}.class) : {{t}}
read?({{t}}).not_nil!
end
{% end %}
def read(t)
read?(t).not_nil!
end
# Reads the next column as a Nil.
def read(t : Nil.class) : Nil
read?(Nil)
end
def read_object
raise "Not implemented"
def read?(t)
raise "read?(t : #{t}) is not implemented in #{self.class}"
end
# list datatypes that must be supported form the driver
# users will call read(String) or read?(String) for nillables
{% for t in DB::TYPES %}
# Reads the next column as a nillable {{t}}.
abstract def read?(t : {{t}}.class) : {{t}}?
{% end %}
# def read_blob
# yield ... io ....
# end