mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
allow query to receive any object arguments
This commit is contained in:
parent
5b23114095
commit
3464a1d1cc
3 changed files with 56 additions and 16 deletions
|
@ -68,7 +68,7 @@ class FooDriver < DB::Driver
|
|||
end
|
||||
|
||||
class FooStatement < DB::Statement
|
||||
protected def perform_query(args : Slice(DB::Any)) : DB::ResultSet
|
||||
protected def perform_query(args : Enumerable) : DB::ResultSet
|
||||
GenericResultSet(Any).new(self, FooDriver.fake_row)
|
||||
end
|
||||
|
||||
|
@ -110,7 +110,7 @@ class BarDriver < DB::Driver
|
|||
end
|
||||
|
||||
class BarStatement < DB::Statement
|
||||
protected def perform_query(args : Slice(DB::Any)) : DB::ResultSet
|
||||
protected def perform_query(args : Enumerable) : DB::ResultSet
|
||||
GenericResultSet(Any).new(self, BarDriver.fake_row)
|
||||
end
|
||||
|
||||
|
@ -157,4 +157,26 @@ describe DB do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "allow custom types to be used as arguments for query" do
|
||||
DB.open("foo://host") do |db|
|
||||
FooDriver.fake_row = [1, "string"] of FooDriver::Any
|
||||
db.query "query" { }
|
||||
db.query "query", 1 { }
|
||||
db.query "query", 1, "string" { }
|
||||
db.query("query", Slice(UInt8).new(4)) { }
|
||||
db.query("query", 1, "string", FooValue.new(5)) { }
|
||||
db.query "query", [1, "string", FooValue.new(5)] { }
|
||||
end
|
||||
|
||||
DB.open("bar://host") do |db|
|
||||
BarDriver.fake_row = [1, "string"] of BarDriver::Any
|
||||
db.query "query" { }
|
||||
db.query "query", 1 { }
|
||||
db.query "query", 1, "string" { }
|
||||
db.query("query", Slice(UInt8).new(4)) { }
|
||||
db.query("query", 1, "string", BarValue.new(5)) { }
|
||||
db.query "query", [1, "string", FooValue.new(5)] { }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -42,7 +42,7 @@ class DummyDriver < DB::Driver
|
|||
super(connection)
|
||||
end
|
||||
|
||||
protected def perform_query(args : Slice(DB::Any))
|
||||
protected def perform_query(args : Enumerable)
|
||||
set_params args
|
||||
DummyResultSet.new self, @query
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue