Skip to content

Commit 045a5f9

Browse files
committed
Fix handling of database queries
SQLite `Select` queries return an Array for each column, not a Hash.
1 parent b3b5443 commit 045a5f9

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

lib/database.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def load(table)
2424

2525
{}.tap do |result|
2626
rows.each do |row|
27-
result[row["key"].to_sym] = row["value"]
27+
result[row[0].to_sym] = row[1]
2828
end
2929
end
3030
end

lib/preferences.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ def initialize
1111
end
1212

1313
def method_missing(meth, *args, &blk)
14+
if meth == :[] || meth == :[]=
15+
#convert hash key to symbol
16+
args[0] = args[0].to_sym
17+
end
18+
1419
@target.send(meth, *args, &blk)
1520
end
1621

spec/lib/database_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
context ".load" do
1313
it "returns a proper hash" do
14-
db = HH::Database.new(double(:execute => [{"key" => "key", "value" => "value"}]))
14+
db = HH::Database.new(double(:execute => [ ["key1", "value1"], ["key2", "value2"] ]))
1515

16-
db.load("names").should eql({:key => "value"})
16+
db.load("names").should eql({:key1 => "value1", :key2 => "value2"})
1717
end
1818
end
1919
end

0 commit comments

Comments
 (0)