tokyo_wrapper 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
data/lib/tokyo_wrapper/table.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'tokyo_wrapper/table_methods/associations'
|
2
|
+
require 'tokyo_wrapper/table_methods/query'
|
2
3
|
|
3
4
|
module TokyoWrapper
|
4
5
|
|
5
6
|
class Table
|
6
7
|
include TokyoWrapper::TableMethods::Associations
|
8
|
+
include TokyoWrapper::TableMethods::Query
|
7
9
|
|
8
10
|
def initialize(table)
|
9
11
|
@table = table
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module TokyoWrapper
|
2
|
+
|
3
|
+
module TableMethods
|
4
|
+
|
5
|
+
module Query
|
6
|
+
|
7
|
+
def all_by_multiple_key_values(key_value_hash = {})
|
8
|
+
@table.query do |query|
|
9
|
+
key_value_hash.each do |key, value|
|
10
|
+
query.add key, :equals, value
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe TokyoWrapper::TableMethods::Associations do
|
4
|
+
include RufusTokyoMacros
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@table_file = File.expand_path(File.dirname(__FILE__) + '/../../tokyo_cabinet_files/table.tct')
|
8
|
+
clear_table(@table_file)
|
9
|
+
end
|
10
|
+
|
11
|
+
after(:each) do
|
12
|
+
clear_table(@table_file)
|
13
|
+
end
|
14
|
+
|
15
|
+
context "Find all" do
|
16
|
+
|
17
|
+
it "should find all the rows that have given values" do
|
18
|
+
|
19
|
+
begin
|
20
|
+
write_table = TokyoWrapper::Table.create_with_create_write_non_blocking_lock(@table_file)
|
21
|
+
|
22
|
+
data_hash_1 = {"street" => "1111 Main",
|
23
|
+
"city" => "Montreal",
|
24
|
+
"province" => "Quebec",
|
25
|
+
"country" => "Canada",
|
26
|
+
"notes" => "Some notes",
|
27
|
+
"register_id" => "45"}
|
28
|
+
id_1 = write_table.add(data_hash_1)
|
29
|
+
data_hash_2 = {"street" => "1111 Maisonneuve",
|
30
|
+
"city" => "Montreal",
|
31
|
+
"province" => "Quebec",
|
32
|
+
"country" => "Canada",
|
33
|
+
"notes" => "Another notes",
|
34
|
+
"register_id" => "8"}
|
35
|
+
id_2 = write_table.add(data_hash_2)
|
36
|
+
data_hash_3 = {"street" => "1111 Main",
|
37
|
+
"city" => "Quebec",
|
38
|
+
"province" => "Quebec",
|
39
|
+
"country" => "Canada",
|
40
|
+
"notes" => "Different notes",
|
41
|
+
"register_id" => "8"}
|
42
|
+
id_3 = write_table.add(data_hash_3)
|
43
|
+
data_hash_4 = {"street" => "1112 Main",
|
44
|
+
"city" => "Montreal",
|
45
|
+
"province" => "Quebec",
|
46
|
+
"country" => "Canada",
|
47
|
+
"notes" => "One more note",
|
48
|
+
"register_id" => "45"}
|
49
|
+
id_4 = write_table.add(data_hash_4)
|
50
|
+
|
51
|
+
ensure
|
52
|
+
write_table.close unless write_table.nil?
|
53
|
+
end
|
54
|
+
|
55
|
+
begin
|
56
|
+
read_table = TokyoWrapper::Table.create_with_read_non_locking(@table_file)
|
57
|
+
|
58
|
+
read_table.all_by_multiple_key_values({"city" => "Montreal",
|
59
|
+
"register_id" => "45"}).should == [{:pk => id_1.to_s,
|
60
|
+
"street" => "1111 Main",
|
61
|
+
"city" => "Montreal",
|
62
|
+
"province" => "Quebec",
|
63
|
+
"country" => "Canada",
|
64
|
+
"notes" => "Some notes",
|
65
|
+
"register_id" => "45"},
|
66
|
+
{:pk => id_4.to_s,
|
67
|
+
"street" => "1112 Main",
|
68
|
+
"city" => "Montreal",
|
69
|
+
"province" => "Quebec",
|
70
|
+
"country" => "Canada",
|
71
|
+
"notes" => "One more note",
|
72
|
+
"register_id" => "45"}]
|
73
|
+
ensure
|
74
|
+
read_table.close unless read_table.nil?
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tokyo_wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tadatoshi Takahashi
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-31 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -26,6 +26,7 @@ files:
|
|
26
26
|
- init.rb
|
27
27
|
- lib/tokyo_wrapper/table.rb
|
28
28
|
- lib/tokyo_wrapper/table_methods/associations.rb
|
29
|
+
- lib/tokyo_wrapper/table_methods/query.rb
|
29
30
|
- lib/tokyo_wrapper.rb
|
30
31
|
- Rakefile
|
31
32
|
- README.rdoc
|
@@ -35,6 +36,7 @@ files:
|
|
35
36
|
- spec/spec_helper.rb
|
36
37
|
- spec/tokyo_cabinet_files/table.tct
|
37
38
|
- spec/tokyo_wrapper/table_methods/associations_spec.rb
|
39
|
+
- spec/tokyo_wrapper/table_methods/query_spec.rb
|
38
40
|
- spec/tokyo_wrapper/table_spec.rb
|
39
41
|
has_rdoc: true
|
40
42
|
homepage: http://github.com/tadatoshi/tokyo_wrapper
|