arguments support

This commit is contained in:
Brian J. Cardiff 2016-01-29 17:13:05 -03:00
parent 1572062501
commit 8a8b86e31a
2 changed files with 34 additions and 2 deletions

View File

@ -8,7 +8,15 @@ class DummyDriver < DB::Driver
super(driver)
end
def exec(*args)
protected def add_parameter(index : Int32, value)
raise "not implemented"
end
protected def add_parameter(name : String, value)
raise "not implemented"
end
protected def execute
DummyResultSet.new self, @items.each
end
end

View File

@ -5,6 +5,30 @@ module DB
def initialize(@driver)
end
abstract def exec(*args) : ResultSet
def exec(*args) : ResultSet
exec args
end
def exec(args : Enumerable)
before_execute
args.each_with_index(1) do |arg, index|
if arg.is_a?(Hash)
arg.each do |key, value|
add_parameter key.to_s, value
end
else
add_parameter index, arg
end
end
execute
end
protected def before_execute
end
# 1-based positional arguments
protected abstract def add_parameter(index : Int32, value)
protected abstract def add_parameter(name : String, value)
protected abstract def execute : ResultSet
end
end