update Slice(UInt8) to Bytes

This commit is contained in:
Brian J. Cardiff 2016-06-22 14:10:09 -03:00
parent 11e24e1c65
commit 8025ecaa13
5 changed files with 17 additions and 17 deletions

View file

@ -231,14 +231,14 @@ describe DB do
db.query "query" { } db.query "query" { }
db.query "query", 1 { } db.query "query", 1 { }
db.query "query", 1, "string" { } db.query "query", 1, "string" { }
db.query("query", Slice(UInt8).new(4)) { } db.query("query", Bytes.new(4)) { }
db.query("query", 1, "string", FooValue.new(5)) { } db.query("query", 1, "string", FooValue.new(5)) { }
db.query "query", [1, "string", FooValue.new(5)] { } db.query "query", [1, "string", FooValue.new(5)] { }
db.query("query").close db.query("query").close
db.query("query", 1).close db.query("query", 1).close
db.query("query", 1, "string").close db.query("query", 1, "string").close
db.query("query", Slice(UInt8).new(4)).close db.query("query", Bytes.new(4)).close
db.query("query", 1, "string", FooValue.new(5)).close db.query("query", 1, "string", FooValue.new(5)).close
db.query("query", [1, "string", FooValue.new(5)]).close db.query("query", [1, "string", FooValue.new(5)]).close
end end
@ -248,14 +248,14 @@ describe DB do
db.query "query" { } db.query "query" { }
db.query "query", 1 { } db.query "query", 1 { }
db.query "query", 1, "string" { } db.query "query", 1, "string" { }
db.query("query", Slice(UInt8).new(4)) { } db.query("query", Bytes.new(4)) { }
db.query("query", 1, "string", BarValue.new(5)) { } db.query("query", 1, "string", BarValue.new(5)) { }
db.query "query", [1, "string", BarValue.new(5)] { } db.query "query", [1, "string", BarValue.new(5)] { }
db.query("query").close db.query("query").close
db.query("query", 1).close db.query("query", 1).close
db.query("query", 1, "string").close db.query("query", 1, "string").close
db.query("query", Slice(UInt8).new(4)).close db.query("query", Bytes.new(4)).close
db.query("query", 1, "string", BarValue.new(5)).close db.query("query", 1, "string", BarValue.new(5)).close
db.query("query", [1, "string", BarValue.new(5)]).close db.query("query", [1, "string", BarValue.new(5)]).close
end end
@ -267,7 +267,7 @@ describe DB do
db.exec("query") db.exec("query")
db.exec("query", 1) db.exec("query", 1)
db.exec("query", 1, "string") db.exec("query", 1, "string")
db.exec("query", Slice(UInt8).new(4)) db.exec("query", Bytes.new(4))
db.exec("query", 1, "string", FooValue.new(5)) db.exec("query", 1, "string", FooValue.new(5))
db.exec("query", [1, "string", FooValue.new(5)]) db.exec("query", [1, "string", FooValue.new(5)])
end end
@ -277,7 +277,7 @@ describe DB do
db.exec("query") db.exec("query")
db.exec("query", 1) db.exec("query", 1)
db.exec("query", 1, "string") db.exec("query", 1, "string")
db.exec("query", Slice(UInt8).new(4)) db.exec("query", Bytes.new(4))
db.exec("query", 1, "string", BarValue.new(5)) db.exec("query", 1, "string", BarValue.new(5))
db.exec("query", [1, "string", BarValue.new(5)]) db.exec("query", [1, "string", BarValue.new(5)])
end end

View file

@ -78,7 +78,7 @@ class DummyDriver < DB::Driver
@values : Array(String)? @values : Array(String)?
@@last_result_set : self? @@last_result_set : self?
@@next_column_type : Nil.class | String.class | Int32.class | Int64.class | Float32.class | Float64.class | Slice(UInt8).class @@next_column_type : Nil.class | String.class | Int32.class | Int64.class | Float32.class | Float64.class | Bytes.class
def initialize(statement, query) def initialize(statement, query)
super(statement) super(statement)
@ -152,17 +152,17 @@ class DummyDriver < DB::Driver
read?(String).try &.to_f64 read?(String).try &.to_f64
end end
def read?(t : Slice(UInt8).class) def read?(t : Bytes.class)
value = read? value = read?
if value.is_a?(Nil) if value.is_a?(Nil)
value value
elsif value.is_a?(String) elsif value.is_a?(String)
ary = value.bytes ary = value.bytes
Slice.new(ary.to_unsafe, ary.size) Slice.new(ary.to_unsafe, ary.size)
elsif value.is_a?(Slice(UInt8)) elsif value.is_a?(Bytes)
value value
else else
raise "#{value} is not convertible to Slice(UInt8)" raise "#{value} is not convertible to Bytes"
end end
end end
end end

View file

@ -101,9 +101,9 @@ describe DummyDriver do
db.query("az,AZ") do |rs| db.query("az,AZ") do |rs|
rs.move_next rs.move_next
ary = [97u8, 122u8] ary = [97u8, 122u8]
rs.read(Slice(UInt8)).should eq(Slice.new(ary.to_unsafe, ary.size)) rs.read(Bytes).should eq(Bytes.new(ary.to_unsafe, ary.size))
ary = [65u8, 90u8] ary = [65u8, 90u8]
rs.read(Slice(UInt8)).should eq(Slice.new(ary.to_unsafe, ary.size)) rs.read(Bytes).should eq(Bytes.new(ary.to_unsafe, ary.size))
end end
end end
end end
@ -134,9 +134,9 @@ describe DummyDriver do
it "executes and selects blob" do it "executes and selects blob" do
with_dummy do |db| with_dummy do |db|
ary = UInt8[0x53, 0x51, 0x4C] ary = UInt8[0x53, 0x51, 0x4C]
slice = Slice.new(ary.to_unsafe, ary.size) slice = Bytes.new(ary.to_unsafe, ary.size)
DummyDriver::DummyResultSet.next_column_type = typeof(slice) DummyDriver::DummyResultSet.next_column_type = typeof(slice)
(db.scalar("?", slice) as Slice(UInt8)).to_a.should eq(ary) (db.scalar("?", slice).as(Bytes)).to_a.should eq(ary)
end end
end end
end end

View file

@ -70,7 +70,7 @@ module DB
# Types supported to interface with database driver. # Types supported to interface with database driver.
# These can be used in any `ResultSet#read` or any `Database#query` related # These can be used in any `ResultSet#read` or any `Database#query` related
# method to be used as query parameters # method to be used as query parameters
TYPES = [Nil, String, Int32, Int64, Float32, Float64, Slice(UInt8)] TYPES = [Nil, String, Int32, Int64, Float32, Float64, Bytes]
# See `DB::TYPES` in `DB`. `Any` is a union of all types in `DB::TYPES` # See `DB::TYPES` in `DB`. `Any` is a union of all types in `DB::TYPES`
{% begin %} {% begin %}

View file

@ -57,8 +57,8 @@ module DB
return rs.read?(Float32) return rs.read?(Float32)
when Float64.class when Float64.class
return rs.read?(Float64) return rs.read?(Float64)
when Slice(UInt8).class when Bytes.class
return rs.read?(Slice(UInt8)) return rs.read?(Bytes)
when Nil.class when Nil.class
return rs.read?(Int32) return rs.read?(Int32)
else else