mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
arguments support
This commit is contained in:
parent
1572062501
commit
8a8b86e31a
2 changed files with 34 additions and 2 deletions
|
@ -8,7 +8,15 @@ class DummyDriver < DB::Driver
|
||||||
super(driver)
|
super(driver)
|
||||||
end
|
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
|
DummyResultSet.new self, @items.each
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,6 +5,30 @@ module DB
|
||||||
def initialize(@driver)
|
def initialize(@driver)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue