mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
update to 0.12 features
clarify expected protocol with ResultSet in docs minor refactors suggested
This commit is contained in:
parent
2cb37d374c
commit
928c1517dc
5 changed files with 19 additions and 17 deletions
|
@ -28,10 +28,7 @@ module DB
|
|||
# :nodoc:
|
||||
def prepare(query) : Statement
|
||||
stmt = @statements_cache.fetch(query, nil)
|
||||
if stmt.is_a?(Nil)
|
||||
stmt = build_statement(query)
|
||||
@statements_cache[query] = stmt
|
||||
end
|
||||
stmt = @statements_cache[query] = build_statement(query) unless stmt
|
||||
|
||||
stmt
|
||||
end
|
||||
|
|
|
@ -79,7 +79,7 @@ module DB
|
|||
record ExecResult, rows_affected, last_insert_id
|
||||
|
||||
# :nodoc:
|
||||
def self.driver_class(driver_name) # : Driver.class
|
||||
def self.driver_class(driver_name) : Driver.class
|
||||
@@drivers.not_nil![driver_name]
|
||||
end
|
||||
|
||||
|
|
|
@ -26,9 +26,6 @@ module DB
|
|||
# Refer to `Connection`, `Statement` and `ResultSet` for further
|
||||
# driver implementation instructions.
|
||||
abstract class Driver
|
||||
def initialize
|
||||
end
|
||||
|
||||
abstract def build_connection(db : Database) : Connection
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,6 +4,14 @@ module DB
|
|||
# See `DB` for a complete sample.
|
||||
#
|
||||
# Each `#read` call consumes the result and moves to the next column.
|
||||
# Each column must be read in order.
|
||||
# At any moment a `#move_next` can be invoked, meaning to skip the
|
||||
# remaining, or even all the columns, in the current row.
|
||||
# Also it is not mandatory to consume the whole `ResultSet`, hence an iteration
|
||||
# through `#each` or `#move_next` can be stopped.
|
||||
#
|
||||
# **Note:** depending on how the `ResultSet` was obtained it might be mandatory an
|
||||
# explicit call to `#close`. Check `QueryMethods#query`.
|
||||
#
|
||||
# ### Note to implementors
|
||||
#
|
||||
|
|
|
@ -46,23 +46,23 @@ module DB
|
|||
query(*args) do |rs|
|
||||
rs.each do
|
||||
# return case rs.read?(rs.column_type(0)) # :-( Some day...
|
||||
t = rs.column_type(0)
|
||||
if t == String
|
||||
case rs.column_type(0)
|
||||
when String.class
|
||||
return rs.read?(String)
|
||||
elsif t == Int32
|
||||
when Int32.class
|
||||
return rs.read?(Int32)
|
||||
elsif t == Int64
|
||||
when Int64.class
|
||||
return rs.read?(Int64)
|
||||
elsif t == Float32
|
||||
when Float32.class
|
||||
return rs.read?(Float32)
|
||||
elsif t == Float64
|
||||
when Float64.class
|
||||
return rs.read?(Float64)
|
||||
elsif t == Slice(UInt8)
|
||||
when Slice(UInt8).class
|
||||
return rs.read?(Slice(UInt8))
|
||||
elsif t == Nil
|
||||
when Nil.class
|
||||
return rs.read?(Int32)
|
||||
else
|
||||
raise "not implemented for #{t} type"
|
||||
raise "not implemented for #{rs.column_type(0)} type"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue