tokyo_wrapper 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -55,6 +55,12 @@ module TokyoWrapper
55
55
  @table[id.to_s]
56
56
  end
57
57
 
58
+ def all_by_key_value(key, value)
59
+ @table.query do |query|
60
+ query.add key, :equals, value
61
+ end
62
+ end
63
+
58
64
  private
59
65
  #
60
66
  # rufus-tokyo converts array to string without a delimiter e.g. It converts [1,2,3,4] to "1234".
@@ -21,7 +21,6 @@ module TokyoWrapper
21
21
  def all_by_has_many_association_id(association_id_name, association_id)
22
22
  @table.query do | query |
23
23
  query.add "#{association_id_name}s", :stror, association_id.to_s
24
- query.no_pk
25
24
  end
26
25
  end
27
26
 
@@ -263,7 +263,7 @@ describe TokyoWrapper::TableMethods::Associations do
263
263
  "notes" => "Some notes",
264
264
  "sector_ids" => ["2","5","32","8"]}
265
265
  id_1 = write_table.add(data_hash_1)
266
- data_hash_2 = {"street" => "1111 Masonneuve",
266
+ data_hash_2 = {"street" => "1111 Maisonneuve",
267
267
  "city" => "Montreal",
268
268
  "notes" => "Another notes",
269
269
  "sector_ids" => ["1","2","3458","9"]}
@@ -280,19 +280,23 @@ describe TokyoWrapper::TableMethods::Associations do
280
280
  begin
281
281
  read_table = TokyoWrapper::Table.create_with_read_non_locking(@table_file)
282
282
 
283
- read_table.all_by_has_many_association_id("sector_id", "2").should == [{"street" => "1111 Main",
283
+ read_table.all_by_has_many_association_id("sector_id", "2").should == [{:pk => id_1.to_s,
284
+ "street" => "1111 Main",
284
285
  "city" => "Montreal",
285
286
  "notes" => "Some notes",
286
287
  "sector_ids" => "2,5,32,8"},
287
- {"street" => "1111 Masonneuve",
288
+ {:pk => id_2.to_s,
289
+ "street" => "1111 Maisonneuve",
288
290
  "city" => "Montreal",
289
291
  "notes" => "Another notes",
290
292
  "sector_ids" => "1,2,3458,9"}]
291
- read_table.all_by_has_many_association_id("sector_id", "45").should == [{"street" => "1111 Desjardins",
293
+ read_table.all_by_has_many_association_id("sector_id", "45").should == [{:pk => id_3.to_s,
294
+ "street" => "1111 Desjardins",
292
295
  "city" => "Quebec",
293
296
  "notes" => "Different notes",
294
297
  "sector_ids" => "87,45,1,727"}]
295
- read_table.all_by_has_many_association_id("sector_id", "3458").should == [{"street" => "1111 Masonneuve",
298
+ read_table.all_by_has_many_association_id("sector_id", "3458").should == [{:pk => id_2.to_s,
299
+ "street" => "1111 Maisonneuve",
296
300
  "city" => "Montreal",
297
301
  "notes" => "Another notes",
298
302
  "sector_ids" => "1,2,3458,9"}]
@@ -139,4 +139,57 @@ describe TokyoWrapper::Table do
139
139
 
140
140
  end
141
141
 
142
+ context "Find all" do
143
+
144
+ it "should find all the rows that have a given value" do
145
+
146
+ begin
147
+ write_table = TokyoWrapper::Table.create_with_create_write_non_blocking_lock(@table_file)
148
+
149
+ data_hash_1 = {"street" => "1111 Main",
150
+ "city" => "Montreal",
151
+ "province" => "Quebec",
152
+ "country" => "Canada",
153
+ "notes" => "Some notes"}
154
+ id_1 = write_table.add(data_hash_1)
155
+ data_hash_2 = {"street" => "1111 Maisonneuve",
156
+ "city" => "Montreal",
157
+ "province" => "Quebec",
158
+ "country" => "Canada",
159
+ "notes" => "Another notes"}
160
+ id_2 = write_table.add(data_hash_2)
161
+ data_hash_3 = {"street" => "1111 Main",
162
+ "city" => "Quebec",
163
+ "province" => "Quebec",
164
+ "country" => "Canada",
165
+ "notes" => "Different notes"}
166
+ id_3 = write_table.add(data_hash_3)
167
+
168
+ ensure
169
+ write_table.close unless write_table.nil?
170
+ end
171
+
172
+ begin
173
+ read_table = TokyoWrapper::Table.create_with_read_non_locking(@table_file)
174
+
175
+ read_table.all_by_key_value("city", "Montreal").should == [{:pk => id_1.to_s,
176
+ "street" => "1111 Main",
177
+ "city" => "Montreal",
178
+ "province" => "Quebec",
179
+ "country" => "Canada",
180
+ "notes" => "Some notes"},
181
+ {:pk => id_2.to_s,
182
+ "street" => "1111 Maisonneuve",
183
+ "city" => "Montreal",
184
+ "province" => "Quebec",
185
+ "country" => "Canada",
186
+ "notes" => "Another notes"}]
187
+ ensure
188
+ read_table.close unless read_table.nil?
189
+ end
190
+
191
+ end
192
+
193
+ end
194
+
142
195
  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.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tadatoshi Takahashi