dm-appengine 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/{dm-appengine.rb → appengine_adapter.rb} +43 -27
- data/spec/dm-appengine_spec.rb +66 -0
- data/spec/spec_helper.rb +1 -1
- metadata +60 -59
data/Rakefile
CHANGED
@@ -17,10 +17,12 @@
|
|
17
17
|
#
|
18
18
|
# Datamapper adapter for Google App Engine
|
19
19
|
|
20
|
+
require 'date'
|
20
21
|
require 'rubygems'
|
21
|
-
|
22
|
+
require 'time'
|
23
|
+
|
24
|
+
gem 'appengine-apis', '~> 0.0.6'
|
22
25
|
|
23
|
-
require 'appengine-apis/local_boot'
|
24
26
|
require 'appengine-apis/datastore'
|
25
27
|
require 'dm-core'
|
26
28
|
|
@@ -112,10 +114,20 @@ module DataMapper
|
|
112
114
|
end
|
113
115
|
|
114
116
|
def convert_value(property, value)
|
117
|
+
value = property.value(value)
|
115
118
|
if property.type == DataMapper::Types::Text && value
|
116
119
|
AppEngine::Datastore::Text.new(value)
|
117
120
|
else
|
118
|
-
value
|
121
|
+
case value
|
122
|
+
when Date, DateTime
|
123
|
+
Time.parse(value.to_s)
|
124
|
+
when BigDecimal
|
125
|
+
value.to_s
|
126
|
+
when Class
|
127
|
+
value.name
|
128
|
+
else
|
129
|
+
value
|
130
|
+
end
|
119
131
|
end
|
120
132
|
end
|
121
133
|
|
@@ -130,12 +142,14 @@ module DataMapper
|
|
130
142
|
class QueryBuilder
|
131
143
|
import Datastore::JavaDatastore::FetchOptions
|
132
144
|
include Datastore::Query::Constants
|
145
|
+
include DataMapper::Query::Conditions
|
146
|
+
|
133
147
|
@@OPERATORS = {
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
148
|
+
EqualToComparison => EQUAL,
|
149
|
+
GreaterThanComparison => GREATER_THAN,
|
150
|
+
GreaterThanOrEqualToComparison => GREATER_THAN_OR_EQUAL,
|
151
|
+
LessThanComparison => LESS_THAN,
|
152
|
+
LessThanOrEqualToComparison => LESS_THAN_OR_EQUAL,
|
139
153
|
}.freeze
|
140
154
|
|
141
155
|
def initialize(query, kind, adapter)
|
@@ -172,24 +186,23 @@ module DataMapper
|
|
172
186
|
end
|
173
187
|
|
174
188
|
def parse_order(order)
|
175
|
-
if order.size == 1 && order[0].
|
176
|
-
if order[0].
|
189
|
+
if order.size == 1 && order[0].operator != :desc
|
190
|
+
if order[0].target.key?
|
177
191
|
# omit the default key ordering.
|
178
192
|
# This lets inequality filters work
|
179
193
|
return
|
180
194
|
end
|
181
195
|
end
|
182
|
-
debugger
|
183
196
|
order.map do |order|
|
184
|
-
if order.
|
197
|
+
if order.operator == :desc
|
185
198
|
direction = DESCENDING
|
186
199
|
else
|
187
200
|
direction = ASCENDING
|
188
201
|
end
|
189
|
-
name = if order.
|
202
|
+
name = if order.target.key?
|
190
203
|
'__key__'
|
191
204
|
else
|
192
|
-
property_name(order.
|
205
|
+
property_name(order.target)
|
193
206
|
end
|
194
207
|
@query.sort(name, direction)
|
195
208
|
end
|
@@ -197,13 +210,13 @@ module DataMapper
|
|
197
210
|
|
198
211
|
def parse_conditions(conditions)
|
199
212
|
case conditions
|
200
|
-
when
|
213
|
+
when NotOperation then
|
201
214
|
raise NotImplementedError, "NOT operator is not supported"
|
202
|
-
when
|
215
|
+
when AbstractComparison then
|
203
216
|
parse_comparison(conditions)
|
204
|
-
when
|
217
|
+
when OrOperation then
|
205
218
|
parse_or(conditions)
|
206
|
-
when
|
219
|
+
when AndOperation then
|
207
220
|
parse_and(conditions)
|
208
221
|
else
|
209
222
|
raise ArgumentError, "invalid conditions #{conditions.class}: #{conditions.inspect}"
|
@@ -229,14 +242,14 @@ module DataMapper
|
|
229
242
|
raise NotImplementedError, "OR only supported with key equality comparisons"
|
230
243
|
end
|
231
244
|
@must_be_get = true
|
232
|
-
or_op.
|
245
|
+
or_op.each do |op|
|
233
246
|
case op
|
234
|
-
when
|
247
|
+
when OrOperation then
|
235
248
|
parse_or(op)
|
236
|
-
when
|
249
|
+
when EqualToComparison then
|
237
250
|
key = parse_key(op.property, op.value)
|
238
251
|
@keys << key
|
239
|
-
when
|
252
|
+
when InclusionComparison then
|
240
253
|
parse_key_inclusion(op)
|
241
254
|
else
|
242
255
|
raise NotImplementedError, "Unsupported condition #{op.class} inside OR"
|
@@ -256,7 +269,7 @@ module DataMapper
|
|
256
269
|
@maybe_get = false
|
257
270
|
end
|
258
271
|
@found_and = true
|
259
|
-
op.
|
272
|
+
op.each do |conditions|
|
260
273
|
parse_conditions(conditions)
|
261
274
|
end
|
262
275
|
end
|
@@ -267,9 +280,9 @@ module DataMapper
|
|
267
280
|
if @maybe_get
|
268
281
|
if property.key?
|
269
282
|
case op
|
270
|
-
when
|
283
|
+
when EqualToComparison
|
271
284
|
@keys << parse_key(property, value)
|
272
|
-
when
|
285
|
+
when InclusionComparison
|
273
286
|
parse_key_inclusion(op)
|
274
287
|
@must_be_get = true
|
275
288
|
return
|
@@ -281,7 +294,7 @@ module DataMapper
|
|
281
294
|
end
|
282
295
|
end
|
283
296
|
|
284
|
-
if op.kind_of?
|
297
|
+
if op.kind_of? InclusionComparison
|
285
298
|
parse_range(op)
|
286
299
|
else
|
287
300
|
filter_op = @@OPERATORS[op.class]
|
@@ -348,8 +361,11 @@ module DataMapper
|
|
348
361
|
key = entity.get_key
|
349
362
|
hash = entity.to_hash
|
350
363
|
@dm_query.fields.each do |property|
|
364
|
+
name = property.field
|
351
365
|
if property.key?
|
352
|
-
hash[
|
366
|
+
hash[name] = key.get_name || key.get_id
|
367
|
+
else
|
368
|
+
hash[name] = property.typecast(hash[name])
|
353
369
|
end
|
354
370
|
end
|
355
371
|
hash
|
data/spec/dm-appengine_spec.rb
CHANGED
@@ -25,6 +25,22 @@ class TextTest
|
|
25
25
|
property :text, Text
|
26
26
|
end
|
27
27
|
|
28
|
+
class TypeTest
|
29
|
+
include DataMapper::Resource
|
30
|
+
|
31
|
+
property :name, String, :key => true
|
32
|
+
property :time, Time
|
33
|
+
property :date, Date
|
34
|
+
property :datetime, DateTime
|
35
|
+
property :bigd, BigDecimal
|
36
|
+
property :flower, Object
|
37
|
+
property :klass, Class
|
38
|
+
end
|
39
|
+
|
40
|
+
class Flower
|
41
|
+
attr_accessor :color
|
42
|
+
end
|
43
|
+
|
28
44
|
class FooBar
|
29
45
|
include DataMapper::Resource
|
30
46
|
|
@@ -97,4 +113,54 @@ describe DataMapper::Adapters::AppEngineAdapter do
|
|
97
113
|
b.string.should == 'c'
|
98
114
|
end
|
99
115
|
end
|
116
|
+
|
117
|
+
describe 'types' do
|
118
|
+
it 'should support Date' do
|
119
|
+
date = Date.parse('2007/12/23')
|
120
|
+
a = TypeTest.new(:name => 'date', :date => date)
|
121
|
+
a.save
|
122
|
+
a.reload
|
123
|
+
a.date.should == date
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should support Time' do
|
127
|
+
time = Time.at(Time.now.to_i) # Datastore store ms precision, not usec
|
128
|
+
a = TypeTest.new(:name => 'time', :time => time)
|
129
|
+
a.save
|
130
|
+
a.reload
|
131
|
+
a.time.should == time
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'should support DateTime' do
|
135
|
+
date = DateTime.parse('2007-12-23')
|
136
|
+
a = TypeTest.new(:name => 'datetime', :datetime => date)
|
137
|
+
a.save
|
138
|
+
a.reload
|
139
|
+
a.datetime.should == date
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should support BigDecimal' do
|
143
|
+
one = BigDecimal.new('1.0')
|
144
|
+
a = TypeTest.new(:name => 'bigd', :bigd => one)
|
145
|
+
a.save
|
146
|
+
a.reload
|
147
|
+
a.bigd.should == one
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'should support Object' do
|
151
|
+
flower = Flower.new
|
152
|
+
flower.color = 'red'
|
153
|
+
a = TypeTest.new(:name => 'color', :flower => flower)
|
154
|
+
a.save
|
155
|
+
a.reload
|
156
|
+
a.flower.color.should == flower.color
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'should support Class' do
|
160
|
+
a = TypeTest.new(:name => 'class', :klass => Flower)
|
161
|
+
a.save
|
162
|
+
a.reload
|
163
|
+
a.klass.should == Flower
|
164
|
+
end
|
165
|
+
end
|
100
166
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,82 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
name: dm-appengine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Brown
|
8
|
+
autorequire: dm-appengine
|
9
|
+
bindir: bin
|
9
10
|
cert_chain: []
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
date: 2009-07-27 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: appengine-apis
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.3
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: dm-core
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.10.0
|
34
|
+
version:
|
35
|
+
description: A DataMapper adapter for Google App Engine
|
36
|
+
email: ribrdb@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
13
41
|
extra_rdoc_files:
|
14
42
|
- README.rdoc
|
15
43
|
- LICENSE
|
16
|
-
homepage: http://code.google.com/p/appengine-jruby
|
17
|
-
signing_key:
|
18
|
-
name: dm-appengine
|
19
|
-
rdoc_options: []
|
20
|
-
|
21
|
-
autorequire: dm-appengine
|
22
|
-
rubyforge_project:
|
23
|
-
executables: []
|
24
|
-
|
25
|
-
description: A DataMapper adapter for Google App Engine
|
26
|
-
specification_version: 2
|
27
|
-
default_executable:
|
28
44
|
files:
|
29
45
|
- LICENSE
|
30
46
|
- README.rdoc
|
31
47
|
- Rakefile
|
32
|
-
- lib/
|
33
|
-
- lib/dm-appengine.rb
|
34
|
-
- lib/dm-appengine.rb-custom_resource
|
48
|
+
- lib/appengine_adapter.rb
|
35
49
|
- lib/dm-appengine/appengine_resource.rb
|
36
50
|
- lib/dm-appengine/transactions.rb
|
51
|
+
- lib/dm-appengine.rb-custom_resource
|
37
52
|
- spec/dm-appengine_spec.rb
|
38
53
|
- spec/spec_helper.rb
|
54
|
+
has_rdoc: true
|
55
|
+
homepage: http://code.google.com/p/appengine-jruby
|
56
|
+
licenses: []
|
57
|
+
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
39
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
70
|
requirements:
|
41
|
-
- -
|
71
|
+
- - ">="
|
42
72
|
- !ruby/object:Gem::Version
|
43
73
|
version: "0"
|
44
74
|
version:
|
45
|
-
extensions: []
|
46
|
-
|
47
|
-
rubygems_version: 1.3.1
|
48
75
|
requirements: []
|
49
76
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.3.5
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: A DataMapper adapter for Google App Engine
|
54
82
|
test_files: []
|
55
83
|
|
56
|
-
version: !ruby/object:Gem::Version
|
57
|
-
version: 0.0.1
|
58
|
-
require_paths:
|
59
|
-
- lib
|
60
|
-
dependencies:
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
version_requirements: !ruby/object:Gem::Requirement
|
63
|
-
requirements:
|
64
|
-
- - ~>
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: 0.0.3
|
67
|
-
version:
|
68
|
-
type: :runtime
|
69
|
-
version_requirement:
|
70
|
-
name: appengine-apis
|
71
|
-
- !ruby/object:Gem::Dependency
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
requirements:
|
74
|
-
- - ~>
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: 0.10.0
|
77
|
-
version:
|
78
|
-
type: :runtime
|
79
|
-
version_requirement:
|
80
|
-
name: dm-core
|
81
|
-
bindir: bin
|
82
|
-
has_rdoc: true
|