dm-adapter-simpledb 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,7 @@ $LOAD_PATH.unshift(File.join(ROOT,'lib'))
4
4
  require 'simpledb_adapter'
5
5
  require 'logger'
6
6
  require 'fileutils'
7
+ require 'right_aws'
7
8
  require 'spec'
8
9
  require 'spec/autorun'
9
10
 
@@ -0,0 +1,368 @@
1
+ require File.expand_path('../unit_spec_helper', File.dirname(__FILE__))
2
+ require 'dm-adapter-simpledb/where_expression'
3
+
4
+ module DmAdapterSimpledb
5
+ include DataMapper::Query::Conditions
6
+
7
+ describe WhereExpression do
8
+ include DataMapper
9
+
10
+ class Post
11
+ include DataMapper::Resource
12
+
13
+ property :id, Serial
14
+ property :title, String
15
+ property :body, Text
16
+ end
17
+
18
+ context "given a basic equality query" do
19
+ before :each do
20
+ @conditions = Operation.new(
21
+ :and,
22
+ Comparison.new(:eql, Post.properties[:title], "FOO"))
23
+ @it = WhereExpression.new(@conditions)
24
+ end
25
+
26
+ specify { @it.to_s.should == 'title = "FOO"' }
27
+
28
+ it "should have no unsupported conditions" do
29
+ @it.unsupported_conditions.should be == Operation.new(:and)
30
+ end
31
+ end
32
+
33
+ context "given a basic inequality query" do
34
+ before :each do
35
+ @conditions = Operation.new(
36
+ :and,
37
+ Operation.new(:not,
38
+ Comparison.new(:eql, Post.properties[:title], "FOO")))
39
+ @it = WhereExpression.new(@conditions)
40
+ end
41
+
42
+ specify { @it.to_s.should == 'title != "FOO"' }
43
+ end
44
+
45
+ context "given a greater-than query" do
46
+ before :each do
47
+ @conditions = Operation.new(
48
+ :and,
49
+ Comparison.new(:gt, Post.properties[:title], "FOO"))
50
+ @it = WhereExpression.new(@conditions)
51
+ end
52
+
53
+ specify { @it.to_s.should == 'title > "FOO"' }
54
+ end
55
+
56
+ context "given a lesser-than query" do
57
+ before :each do
58
+ @conditions = Operation.new(
59
+ :and,
60
+ Comparison.new(:lt, Post.properties[:title], "FOO"))
61
+ @it = WhereExpression.new(@conditions)
62
+ end
63
+
64
+ specify { @it.to_s.should == 'title < "FOO"' }
65
+ end
66
+
67
+ context "given a equal-or-greater-than query" do
68
+ before :each do
69
+ @conditions = Operation.new(
70
+ :and,
71
+ Comparison.new(:gte, Post.properties[:title], "FOO"))
72
+ @it = WhereExpression.new(@conditions)
73
+ end
74
+
75
+ specify { @it.to_s.should == 'title >= "FOO"' }
76
+ end
77
+
78
+ context "given an equal-to-or-lesser-than query" do
79
+ before :each do
80
+ @conditions = Operation.new(
81
+ :and,
82
+ Comparison.new(:lte, Post.properties[:title], "FOO"))
83
+ @it = WhereExpression.new(@conditions)
84
+ end
85
+
86
+ specify { @it.to_s.should == 'title <= "FOO"' }
87
+ end
88
+
89
+ context "given a LIKE query" do
90
+ before :each do
91
+ @conditions = Operation.new(
92
+ :and,
93
+ Comparison.new(:like, Post.properties[:title], "%FOO%"))
94
+ @it = WhereExpression.new(@conditions)
95
+ end
96
+
97
+ specify { @it.to_s.should == 'title LIKE "%FOO%"' }
98
+ end
99
+
100
+ context "given an IN query" do
101
+ before :each do
102
+ @conditions = Operation.new(
103
+ :and,
104
+ Comparison.new(:in, Post.properties[:title], ["FOO", "BAZ"]))
105
+ @it = WhereExpression.new(@conditions)
106
+ end
107
+
108
+ specify { @it.to_s.should == 'title IN ("FOO", "BAZ")' }
109
+ end
110
+
111
+ context "given an IN query with an empty list" do
112
+ before :each do
113
+ @conditions = Operation.new(
114
+ :and,
115
+ Comparison.new(:in, Post.properties[:title], []))
116
+ @it = WhereExpression.new(@conditions)
117
+ end
118
+
119
+ specify { @it.to_s.should == 'title IS NULL' }
120
+ end
121
+
122
+ context "given a negated IN query with an empty list" do
123
+ before :each do
124
+ @conditions = Operation.new(
125
+ :and,
126
+ Comparison.new(:eql, Post.properties[:title], "FOO"),
127
+ Operation.new(:not,
128
+ Comparison.new(:in, Post.properties[:title], [])))
129
+ @it = WhereExpression.new(@conditions)
130
+ end
131
+
132
+ specify { @it.to_s.should == 'title = "FOO"' }
133
+ end
134
+
135
+ context "given an empty IN query OR another IN query" do
136
+ before :each do
137
+ @conditions = Operation.new(
138
+ :or,
139
+ Comparison.new(:in, Post.properties[:body], []),
140
+ Comparison.new(:in, Post.properties[:title], ["foo"]))
141
+ @it = WhereExpression.new(@conditions)
142
+ end
143
+
144
+ specify { @it.to_s.should == 'body IS NULL OR title IN ("foo")' }
145
+ end
146
+
147
+ context "given an IN query with a range" do
148
+ before :each do
149
+ @conditions = Operation.new(
150
+ :and,
151
+ Comparison.new(:in, Post.properties[:title], ("A".."Z")))
152
+ @it = WhereExpression.new(@conditions)
153
+ end
154
+
155
+ specify { @it.to_s.should == 'title BETWEEN "A" AND "Z"' }
156
+ end
157
+
158
+ context "given an IN query with an exclusive range" do
159
+ before :each do
160
+ pending "Implementationm of exclusive ranges"
161
+ @conditions = Operation.new(
162
+ :and,
163
+ Comparison.new(:in, Post.properties[:title], ("A"..."Z")),
164
+ Comparison.new(:eql, Post.properties[:body], 42))
165
+ @it = WhereExpression.new(@conditions)
166
+ end
167
+
168
+ specify { @it.to_s.should == 'body = "42" AND title BETWEEN "A" AND "Z"' }
169
+
170
+ it "should include the range in unsupported conditions" do
171
+ @it.unsupported_conditions.should be ==
172
+ Operation.new(:and,
173
+ Comparison.new(:in, Post.properties[:title], ("A"..."Z")))
174
+ end
175
+ end
176
+
177
+ context "given a negated IN query with an exclusive range" do
178
+ before :each do
179
+ pending "Implementationm of exclusive ranges"
180
+ @conditions = Operation.new(
181
+ :and,
182
+ Operation.new(:not,
183
+ Comparison.new(:in, Post.properties[:title], (1...5))))
184
+ @it = WhereExpression.new(@conditions)
185
+ end
186
+
187
+ specify { @it.to_s.should == 'NOT title BETWEEN "1" AND "5"' }
188
+
189
+ it "should include the range in unsupported conditions" do
190
+ @it.unsupported_conditions.should be ==
191
+ Operation.new(:and,
192
+ Operation.new(:not,
193
+ Comparison.new(:in, Post.properties[:title], (1...5))))
194
+ @it.unsupported_conditions.operands.first.operands.first.value.should be == (1...5)
195
+ end
196
+ end
197
+
198
+ context "given a comparison to nil" do
199
+ before :each do
200
+ @conditions = Operation.new(
201
+ :and,
202
+ Comparison.new(:eql, Post.properties[:title], nil))
203
+ @it = WhereExpression.new(@conditions)
204
+ end
205
+
206
+ specify { @it.to_s.should == 'title IS NULL' }
207
+ end
208
+
209
+ context "given a negated comparison to nil" do
210
+ before :each do
211
+ @conditions = Operation.new(
212
+ :and,
213
+ Operation.new(:not,
214
+ Comparison.new(:eql, Post.properties[:title], nil)))
215
+ @it = WhereExpression.new(@conditions)
216
+ end
217
+
218
+ specify { @it.to_s.should == 'title IS NOT NULL' }
219
+ end
220
+
221
+ context "given a regexp comparison" do
222
+ before :each do
223
+ @conditions = Operation.new(
224
+ :and,
225
+ Comparison.new(:regexp, Post.properties[:title], /foo/),
226
+ Comparison.new(:eql, Post.properties[:body], "bar"))
227
+ @it = WhereExpression.new(@conditions)
228
+ end
229
+
230
+ specify { @it.to_s.should == 'body = "bar"' }
231
+
232
+ it "should include the regexp comparison in unsupported conds" do
233
+ @it.unsupported_conditions.should be ==
234
+ Operation.new(:and,
235
+ Comparison.new(:regexp, Post.properties[:title], /foo/))
236
+ end
237
+ end
238
+
239
+ context "given a literal expression with replacements" do
240
+ before :each do
241
+ @conditions = Operation.new(
242
+ :and,
243
+ ["body in (?, ?)", "FUZ", "BUZ"])
244
+ @it = WhereExpression.new(@conditions)
245
+ end
246
+
247
+ specify { @it.to_s.should == 'body in ("FUZ", "BUZ")' }
248
+ end
249
+
250
+ context "given a literal expression with subarray of replacements" do
251
+ before :each do
252
+ @conditions = Operation.new(
253
+ :and,
254
+ ["body in (?, ?)", ["FUZ", "BUZ"]])
255
+ @it = WhereExpression.new(@conditions)
256
+ end
257
+
258
+ specify { @it.to_s.should == 'body in ("FUZ", "BUZ")' }
259
+ end
260
+
261
+ context "given a literal expression" do
262
+ before :each do
263
+ @conditions = Operation.new(
264
+ :and,
265
+ ["body like '%frotz%'"])
266
+ @it = WhereExpression.new(@conditions)
267
+ end
268
+
269
+ specify { @it.to_s.should == "body like '%frotz%'" }
270
+ end
271
+
272
+ context "given a literal expression with a hash of replacements" do
273
+ before :each do
274
+ @conditions = Operation.new(
275
+ :and,
276
+ ["title = :title and body = :body",
277
+ {
278
+ :title => "foo", :body => "bar"
279
+ }
280
+ ])
281
+ @it = WhereExpression.new(@conditions)
282
+ end
283
+
284
+ specify { @it.to_s.should == 'title = "foo" and body = "bar"' }
285
+ end
286
+
287
+ context "given a two ANDed comparisons" do
288
+ before :each do
289
+ @conditions = Operation.new(
290
+ :and,
291
+ Comparison.new(:eql, Post.properties[:title], "FOO"),
292
+ Comparison.new(:eql, Post.properties[:body], "BAR"))
293
+ @it = WhereExpression.new(@conditions)
294
+ end
295
+
296
+ specify { @it.to_s.should == 'body = "BAR" AND title = "FOO"' }
297
+ end
298
+
299
+ context "given an OR nested in an AND comparisons" do
300
+ before :each do
301
+ @conditions = Operation.new(
302
+ :and,
303
+ Comparison.new(:eql, Post.properties[:title], "FOO"),
304
+ Operation.new(:or,
305
+ Comparison.new(:eql, Post.properties[:body], "BAR"),
306
+ Comparison.new(:eql, Post.properties[:body], "BAZ")))
307
+ @it = WhereExpression.new(@conditions)
308
+ end
309
+
310
+ specify {
311
+ @it.to_s.should == '( body = "BAR" OR body = "BAZ" ) AND title = "FOO"'
312
+ }
313
+ end
314
+
315
+ context "given a two ORed comparisons" do
316
+ before :each do
317
+ @conditions = Operation.new(
318
+ :or,
319
+ Comparison.new(:eql, Post.properties[:title], "FOO"),
320
+ Comparison.new(:eql, Post.properties[:body], "BAR"))
321
+ @it = WhereExpression.new(@conditions)
322
+ end
323
+
324
+ specify { @it.to_s.should == 'body = "BAR" OR title = "FOO"' }
325
+ end
326
+
327
+ context "given an intersection" do
328
+ before :each do
329
+ @conditions = Operation.new(
330
+ :or,
331
+ Comparison.new(:eql, Post.properties[:title], "FOO"),
332
+ Comparison.new(:eql, Post.properties[:body], "BAR"))
333
+ @it = WhereExpression.new(@conditions)
334
+ end
335
+
336
+ specify { @it.to_s.should == 'body = "BAR" OR title = "FOO"' }
337
+ end
338
+
339
+ context "given a negated AND comparison" do
340
+ before :each do
341
+ @conditions = Operation.new(
342
+ :and,
343
+ Operation.new(:not,
344
+ Operation.new(:and,
345
+ Comparison.new(:eql, Post.properties[:title], "FOO"),
346
+ Comparison.new(:eql, Post.properties[:body], "BAR"))))
347
+ @it = WhereExpression.new(@conditions)
348
+ end
349
+
350
+ specify { @it.to_s.should == 'NOT ( body = "BAR" AND title = "FOO" )' }
351
+ end
352
+
353
+ context "given individually negated equality comparisons" do
354
+ before :each do
355
+ @conditions = Operation.new(
356
+ :and,
357
+ Operation.new(:not,
358
+ Comparison.new(:eql, Post.properties[:title], "FOO")),
359
+ Operation.new(:not,
360
+ Comparison.new(:eql, Post.properties[:body], "BAR")))
361
+ @it = WhereExpression.new(@conditions)
362
+ end
363
+
364
+ specify { @it.to_s.should == 'body != "BAR" AND title != "FOO"' }
365
+ end
366
+
367
+ end
368
+ end
@@ -21,8 +21,9 @@ describe DataMapper::Adapters::SimpleDBAdapter do
21
21
  anything,
22
22
  hash_including(
23
23
  'simpledb_type' => ["products"],
24
- 'stock' => ["3"],
25
- 'name' => ["War and Peace"]))
24
+ 'stock' => ["3"],
25
+ 'name' => ["War and Peace"]),
26
+ :replace)
26
27
  @record.save
27
28
  end
28
29
  end
@@ -1,6 +1,7 @@
1
1
  require 'spec'
2
2
  ROOT = File.expand_path('../..', File.dirname(__FILE__))
3
3
  $LOAD_PATH.unshift(File.join(ROOT,'lib'))
4
+ require 'right_aws'
4
5
  require 'simpledb_adapter'
5
6
 
6
7
  Spec::Runner.configure do |config|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-adapter-simpledb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Boles
@@ -13,7 +13,7 @@ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
15
 
16
- date: 2010-01-19 00:00:00 -05:00
16
+ date: 2010-01-24 00:00:00 -05:00
17
17
  default_executable:
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
@@ -74,13 +74,12 @@ dependencies:
74
74
  requirements:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: "0.2"
77
+ version: "0.4"
78
78
  version:
79
79
  description: |
80
80
  A DataMapper adapter for Amazon's SimpleDB service.
81
81
 
82
82
  Features:
83
- * Uses the RightAWS gem for efficient SimpleDB operations.
84
83
  * Full set of CRUD operations
85
84
  * Supports all DataMapper query predicates.
86
85
  * Can translate many queries into efficient native SELECT operations.
@@ -119,8 +118,12 @@ files:
119
118
  - lib/dm-adapter-simpledb/sdb_array.rb
120
119
  - lib/dm-adapter-simpledb/table.rb
121
120
  - lib/dm-adapter-simpledb/utils.rb
121
+ - lib/dm-adapter-simpledb/where_expression.rb
122
122
  - lib/simpledb_adapter.rb
123
+ - scripts/console
124
+ - scripts/limits_benchmark
123
125
  - scripts/simple_benchmark.rb
126
+ - scripts/union_benchmark
124
127
  - spec/integration/associations_spec.rb
125
128
  - spec/integration/compliance_spec.rb
126
129
  - spec/integration/date_spec.rb
@@ -132,6 +135,7 @@ files:
132
135
  - spec/integration/simpledb_adapter_spec.rb
133
136
  - spec/integration/spec_helper.rb
134
137
  - spec/spec.opts
138
+ - spec/unit/dm_adapter_simpledb/where_expression_spec.rb
135
139
  - spec/unit/record_spec.rb
136
140
  - spec/unit/simpledb_adapter_spec.rb
137
141
  - spec/unit/unit_spec_helper.rb
@@ -174,6 +178,7 @@ test_files:
174
178
  - spec/integration/spec_helper.rb
175
179
  - spec/integration/multiple_records_spec.rb
176
180
  - spec/integration/associations_spec.rb
181
+ - spec/unit/dm_adapter_simpledb/where_expression_spec.rb
177
182
  - spec/unit/simpledb_adapter_spec.rb
178
183
  - spec/unit/unit_spec_helper.rb
179
184
  - spec/unit/record_spec.rb