shanna-dm-tokyo-adapter 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/Rakefile +1 -1
- data/VERSION.yml +2 -2
- data/lib/dm-tokyo-adapter/query.rb +35 -14
- data/test/helper.rb +1 -0
- metadata +7 -9
- data/.gitignore +0 -6
- data/dm-tokyo-adapter.gemspec +0 -56
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ begin
|
|
5
5
|
require 'jeweler'
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = 'dm-tokyo-adapter'
|
8
|
-
gem.summary = %Q{
|
8
|
+
gem.summary = %Q{Tokyo Cabinet/Tyrant Table DataMapper Adapter.}
|
9
9
|
gem.email = 'shane.hanna@gmail.com'
|
10
10
|
gem.homepage = 'http://github.com/shanna/dm-tokyo-adapter'
|
11
11
|
gem.authors = ['Shane Hanna']
|
data/VERSION.yml
CHANGED
@@ -18,31 +18,29 @@ module DataMapper
|
|
18
18
|
def initialize(connection, query)
|
19
19
|
assert_kind_of 'connection', connection, Rufus::Tokyo::Table
|
20
20
|
assert_kind_of 'query', query, DataMapper::Query
|
21
|
-
@connection, @query, @native = connection, query,
|
21
|
+
@connection, @query, @native = connection, query, []
|
22
22
|
end
|
23
23
|
|
24
24
|
#--
|
25
|
-
# TODO: Log when a query cannot be performed natively by TC.
|
26
|
-
# TODO: Use native sorting if there is only a single order condition.
|
27
25
|
# TODO: connection[] if I have everything I need to fetch by the primary key.
|
28
26
|
def read
|
29
27
|
records = @connection.query do |statements|
|
30
28
|
if @query.conditions.kind_of?(OrOperation)
|
31
|
-
@
|
29
|
+
fail_native("Operation '#{@query.conditions.slug}'.")
|
32
30
|
else
|
33
31
|
@query.conditions.each do |condition|
|
34
32
|
condition_statement(statements, condition)
|
35
33
|
end
|
36
34
|
end
|
37
35
|
|
38
|
-
|
39
|
-
|
40
|
-
statements.limit(@query.limit) if @query.limit
|
41
|
-
# TODO: Native sorting when only one order field.
|
36
|
+
if native? && !@query.order.empty?
|
37
|
+
sort_statement(statements, @query.order)
|
42
38
|
end
|
39
|
+
|
40
|
+
statements.limit(@query.limit) if native? && @query.limit
|
41
|
+
statements.no_pk
|
43
42
|
end
|
44
43
|
|
45
|
-
# Typecast return values.
|
46
44
|
records.each do |record|
|
47
45
|
@query.fields.each do |property|
|
48
46
|
field = property.field
|
@@ -50,9 +48,18 @@ module DataMapper
|
|
50
48
|
end
|
51
49
|
end
|
52
50
|
|
51
|
+
return records if native?
|
52
|
+
# TODO: Move log entry out to adapter sublcass and use #name?
|
53
|
+
DataMapper.logger.warn(
|
54
|
+
"TokyoAdapter: No native TableQuery support for conditions: #{@native.join(' ')}"
|
55
|
+
)
|
53
56
|
@query.filter_records(records)
|
54
57
|
end
|
55
58
|
|
59
|
+
def native?
|
60
|
+
@native.empty?
|
61
|
+
end
|
62
|
+
|
56
63
|
private
|
57
64
|
def condition_statement(statements, conditions, affirmative = true)
|
58
65
|
case conditions
|
@@ -63,9 +70,9 @@ module DataMapper
|
|
63
70
|
|
64
71
|
def operation_statement(statements, operation, affirmative = true)
|
65
72
|
case operation
|
66
|
-
when OrOperation then @native = false
|
67
73
|
when NotOperation then condition_statement(statements, operation.first, !affirmative)
|
68
74
|
when AndOperation then operation.each{|op| condition_statement(statements, op, affirmative)}
|
75
|
+
else fail_native("Operation '#{operation.slug}'.")
|
69
76
|
end
|
70
77
|
end
|
71
78
|
|
@@ -91,18 +98,32 @@ module DataMapper
|
|
91
98
|
when LessThanComparison then :lt
|
92
99
|
when GreaterThanOrEqualToComparison then :gte
|
93
100
|
when LessThanOrEqualToComparison then :lte
|
101
|
+
else fail_native("Comparison #{comparison.slug}'.") && return
|
94
102
|
end
|
95
103
|
|
96
|
-
unless operator
|
97
|
-
@native = false
|
98
|
-
return
|
99
|
-
end
|
100
104
|
statements.add(comparison.property.field, operator, quote_value(value), affirmative)
|
101
105
|
end
|
102
106
|
|
103
107
|
def quote_value(value)
|
104
108
|
"#{value}"
|
105
109
|
end
|
110
|
+
|
111
|
+
def sort_statement(statements, conditions)
|
112
|
+
fail_native("Multiple (#{conditions.size}) order conditions.") if conditions.size > 1
|
113
|
+
|
114
|
+
sort_order = conditions.first
|
115
|
+
primitive = sort_order.target.primitive
|
116
|
+
direction = case sort_order.operator
|
117
|
+
when :asc then primitive == Integer ? :numasc : :asc
|
118
|
+
when :desc then primitive == Integer ? :numdesc : :desc
|
119
|
+
end
|
120
|
+
|
121
|
+
statements.order_by(sort_order.target.field, direction)
|
122
|
+
end
|
123
|
+
|
124
|
+
def fail_native(why)
|
125
|
+
@native << why
|
126
|
+
end
|
106
127
|
end # Query
|
107
128
|
end # Tokyo
|
108
129
|
end # Adapters
|
data/test/helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shanna-dm-tokyo-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Hanna
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-08 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -32,12 +32,10 @@ extra_rdoc_files:
|
|
32
32
|
- LICENSE
|
33
33
|
- README.rdoc
|
34
34
|
files:
|
35
|
-
- .gitignore
|
36
35
|
- LICENSE
|
37
36
|
- README.rdoc
|
38
37
|
- Rakefile
|
39
38
|
- VERSION.yml
|
40
|
-
- dm-tokyo-adapter.gemspec
|
41
39
|
- lib/dm-tokyo-adapter.rb
|
42
40
|
- lib/dm-tokyo-adapter/cabinet.rb
|
43
41
|
- lib/dm-tokyo-adapter/query.rb
|
@@ -46,7 +44,7 @@ files:
|
|
46
44
|
- test/test_cabinet.rb
|
47
45
|
- test/test_query.rb
|
48
46
|
- test/test_tyrant.rb
|
49
|
-
has_rdoc:
|
47
|
+
has_rdoc: false
|
50
48
|
homepage: http://github.com/shanna/dm-tokyo-adapter
|
51
49
|
post_install_message:
|
52
50
|
rdoc_options:
|
@@ -70,10 +68,10 @@ requirements: []
|
|
70
68
|
rubyforge_project:
|
71
69
|
rubygems_version: 1.2.0
|
72
70
|
signing_key:
|
73
|
-
specification_version:
|
74
|
-
summary:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Tokyo Cabinet/Tyrant Table DataMapper Adapter.
|
75
73
|
test_files:
|
76
|
-
- test/test_cabinet.rb
|
77
|
-
- test/test_tyrant.rb
|
78
74
|
- test/helper.rb
|
75
|
+
- test/test_cabinet.rb
|
79
76
|
- test/test_query.rb
|
77
|
+
- test/test_tyrant.rb
|
data/.gitignore
DELETED
data/dm-tokyo-adapter.gemspec
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = %q{dm-tokyo-adapter}
|
5
|
-
s.version = "0.2.1"
|
6
|
-
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = ["Shane Hanna"]
|
9
|
-
s.date = %q{2009-06-01}
|
10
|
-
s.email = %q{shane.hanna@gmail.com}
|
11
|
-
s.extra_rdoc_files = [
|
12
|
-
"LICENSE",
|
13
|
-
"README.rdoc"
|
14
|
-
]
|
15
|
-
s.files = [
|
16
|
-
".gitignore",
|
17
|
-
"LICENSE",
|
18
|
-
"README.rdoc",
|
19
|
-
"Rakefile",
|
20
|
-
"VERSION.yml",
|
21
|
-
"dm-tokyo-adapter.gemspec",
|
22
|
-
"lib/dm-tokyo-adapter.rb",
|
23
|
-
"lib/dm-tokyo-adapter/cabinet.rb",
|
24
|
-
"lib/dm-tokyo-adapter/query.rb",
|
25
|
-
"lib/dm-tokyo-adapter/tyrant.rb",
|
26
|
-
"test/helper.rb",
|
27
|
-
"test/test_cabinet.rb",
|
28
|
-
"test/test_query.rb",
|
29
|
-
"test/test_tyrant.rb"
|
30
|
-
]
|
31
|
-
s.has_rdoc = true
|
32
|
-
s.homepage = %q{http://github.com/shanna/dm-tokyo-adapter}
|
33
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
-
s.require_paths = ["lib"]
|
35
|
-
s.rubygems_version = %q{1.3.1}
|
36
|
-
s.summary = %q{TODO}
|
37
|
-
s.test_files = [
|
38
|
-
"test/test_cabinet.rb",
|
39
|
-
"test/test_tyrant.rb",
|
40
|
-
"test/helper.rb",
|
41
|
-
"test/test_query.rb"
|
42
|
-
]
|
43
|
-
|
44
|
-
if s.respond_to? :specification_version then
|
45
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
46
|
-
s.specification_version = 2
|
47
|
-
|
48
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
49
|
-
s.add_runtime_dependency(%q<dm-core>, ["~> 0.10.0"])
|
50
|
-
else
|
51
|
-
s.add_dependency(%q<dm-core>, ["~> 0.10.0"])
|
52
|
-
end
|
53
|
-
else
|
54
|
-
s.add_dependency(%q<dm-core>, ["~> 0.10.0"])
|
55
|
-
end
|
56
|
-
end
|