ansr 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.md +35 -0
- data/ansr.gemspec +2 -1
- data/ansr_blacklight/Gemfile +3 -0
- data/ansr_blacklight/README.md +37 -0
- data/ansr_blacklight/ansr_blacklight.gemspec +28 -0
- data/ansr_blacklight/lib/ansr_blacklight.rb +57 -0
- data/ansr_blacklight/lib/ansr_blacklight/arel.rb +6 -0
- data/ansr_blacklight/lib/ansr_blacklight/arel/big_table.rb +57 -0
- data/ansr_blacklight/lib/ansr_blacklight/arel/visitors.rb +6 -0
- data/ansr_blacklight/lib/ansr_blacklight/arel/visitors/query_builder.rb +217 -0
- data/ansr_blacklight/lib/ansr_blacklight/arel/visitors/to_no_sql.rb +14 -0
- data/ansr_blacklight/lib/ansr_blacklight/base.rb +21 -0
- data/ansr_blacklight/lib/ansr_blacklight/connection_adapters/no_sql_adapter.rb +38 -0
- data/ansr_blacklight/lib/ansr_blacklight/model/querying.rb +29 -0
- data/ansr_blacklight/lib/ansr_blacklight/relation.rb +50 -0
- data/ansr_blacklight/lib/ansr_blacklight/relation/solr_projection_methods.rb +55 -0
- data/ansr_blacklight/lib/ansr_blacklight/request_builders.rb +141 -0
- data/ansr_blacklight/lib/ansr_blacklight/solr.rb +4 -0
- data/ansr_blacklight/lib/ansr_blacklight/solr/request.rb +46 -0
- data/ansr_blacklight/lib/ansr_blacklight/solr/response.rb +94 -0
- data/ansr_blacklight/lib/ansr_blacklight/solr/response/group.rb +32 -0
- data/ansr_blacklight/lib/ansr_blacklight/solr/response/group_response.rb +50 -0
- data/ansr_blacklight/lib/ansr_blacklight/solr/response/more_like_this.rb +14 -0
- data/ansr_blacklight/lib/ansr_blacklight/solr/response/pagination_methods.rb +35 -0
- data/ansr_blacklight/lib/ansr_blacklight/solr/response/spelling.rb +92 -0
- data/ansr_blacklight/spec/fixtures/config.yml +0 -0
- data/ansr_blacklight/spec/lib/loaded_relation_spec.rb +223 -0
- data/ansr_blacklight/spec/lib/queryable_relation_spec.rb +133 -0
- data/ansr_blacklight/spec/lib/relation/faceting_spec.rb +475 -0
- data/ansr_blacklight/spec/lib/relation/grouping_spec.rb +159 -0
- data/ansr_blacklight/spec/spec_helper.rb +72 -0
- data/ansr_dpla/Gemfile +3 -0
- data/ansr_dpla/Gemfile.lock +138 -0
- data/ansr_dpla/README.md +2 -2
- data/ansr_dpla/ansr_dpla.gemspec +2 -2
- data/ansr_dpla/lib/ansr_dpla.rb +3 -0
- data/ansr_dpla/lib/ansr_dpla/api.rb +3 -3
- data/ansr_dpla/lib/ansr_dpla/arel.rb +1 -2
- data/ansr_dpla/lib/ansr_dpla/arel/big_table.rb +4 -0
- data/ansr_dpla/lib/ansr_dpla/arel/visitors.rb +6 -0
- data/ansr_dpla/lib/ansr_dpla/arel/visitors/query_builder.rb +188 -0
- data/ansr_dpla/lib/ansr_dpla/arel/visitors/to_no_sql.rb +9 -0
- data/ansr_dpla/lib/ansr_dpla/connection_adapters/no_sql_adapter.rb +58 -0
- data/ansr_dpla/lib/ansr_dpla/model/base.rb +7 -0
- data/ansr_dpla/lib/ansr_dpla/model/querying.rb +6 -10
- data/ansr_dpla/lib/ansr_dpla/relation.rb +61 -0
- data/ansr_dpla/lib/ansr_dpla/request.rb +5 -0
- data/ansr_dpla/spec/lib/api_spec.rb +8 -5
- data/ansr_dpla/spec/lib/item_spec.rb +2 -2
- data/ansr_dpla/spec/lib/relation/facet_spec.rb +27 -19
- data/ansr_dpla/spec/lib/relation/select_spec.rb +10 -8
- data/ansr_dpla/spec/lib/relation/where_spec.rb +1 -1
- data/ansr_dpla/spec/lib/relation_spec.rb +31 -29
- data/ansr_dpla/test/system.rb +4 -2
- data/lib/ansr.rb +7 -0
- data/lib/ansr/arel.rb +3 -0
- data/lib/ansr/arel/big_table.rb +43 -3
- data/lib/ansr/arel/configured_field.rb +19 -0
- data/lib/ansr/arel/nodes.rb +41 -0
- data/lib/ansr/arel/visitors.rb +7 -0
- data/lib/ansr/arel/visitors/context.rb +13 -0
- data/lib/ansr/arel/visitors/query_builder.rb +47 -0
- data/lib/ansr/arel/visitors/to_no_sql.rb +41 -0
- data/lib/ansr/base.rb +29 -1
- data/lib/ansr/configurable.rb +6 -12
- data/lib/ansr/connection_adapters.rb +5 -0
- data/lib/ansr/connection_adapters/no_sql_adapter.rb +80 -0
- data/lib/ansr/dummy_associations.rb +105 -0
- data/lib/ansr/facets.rb +103 -0
- data/lib/ansr/model.rb +17 -107
- data/lib/ansr/model/connection_handler.rb +6 -0
- data/lib/ansr/relation.rb +40 -23
- data/lib/ansr/relation/group.rb +31 -0
- data/lib/ansr/relation/predicate_builder.rb +106 -0
- data/lib/ansr/relation/query_methods.rb +192 -45
- data/lib/ansr/sanitization.rb +5 -18
- data/lib/ansr/utils.rb +89 -0
- data/lib/ansr/version.rb +1 -1
- metadata +73 -25
- data/ansr_dpla/lib/ansr_dpla/arel/connection.rb +0 -81
- data/ansr_dpla/lib/ansr_dpla/arel/query_builder.rb +0 -131
- data/lib/ansr/model/connection.rb +0 -103
data/lib/ansr/sanitization.rb
CHANGED
@@ -2,11 +2,8 @@ module Ansr
|
|
2
2
|
module Sanitization
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
module ClassMethods
|
5
|
-
def reflect_on_association(column_sym)
|
6
|
-
DummyReflection.new(column_sym)
|
7
|
-
end
|
8
|
-
|
9
5
|
def expand_hash_conditions_for_sql_aggregates(conditions)
|
6
|
+
conditions.reduce({}) {|memo, k, v| }
|
10
7
|
conditions
|
11
8
|
end
|
12
9
|
|
@@ -14,22 +11,12 @@ module Ansr
|
|
14
11
|
condition
|
15
12
|
end
|
16
13
|
|
17
|
-
def
|
18
|
-
|
14
|
+
def sanitize_sql_hash_for_conditions(attrs, default_table_name = self.table_name)
|
15
|
+
attrs
|
19
16
|
end
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
def initialize(symbol)
|
24
|
-
@symbol = symbol
|
25
|
-
end
|
26
|
-
|
27
|
-
def polymorphic?
|
28
|
-
false
|
29
|
-
end
|
30
|
-
|
31
|
-
def foreign_key
|
32
|
-
@symbol
|
18
|
+
def sanitize_sql(condition, table_name = table_name())
|
19
|
+
sanitize_sql_for_conditions(condition, table_name)
|
33
20
|
end
|
34
21
|
end
|
35
22
|
end
|
data/lib/ansr/utils.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
module Ansr
|
3
|
+
class OpenStructWithHashAccess < OpenStruct
|
4
|
+
delegate :keys, :each, :map, :has_key?, :empty?, :delete, :length, :reject!, :select!, :include, :fetch, :to_json, :as_json, :to => :to_h
|
5
|
+
|
6
|
+
def []=(key, value)
|
7
|
+
send "#{key}=", value
|
8
|
+
end
|
9
|
+
|
10
|
+
def [](key)
|
11
|
+
send key
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_h
|
15
|
+
@table
|
16
|
+
end
|
17
|
+
|
18
|
+
def merge other_hash
|
19
|
+
self.class.new to_h.merge((other_hash if other_hash.is_a? Hash) || other_hash.to_h)
|
20
|
+
end
|
21
|
+
|
22
|
+
def merge! other_hash
|
23
|
+
@table.merge!((other_hash if other_hash.is_a? Hash) || other_hash.to_h)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class NestedOpenStructWithHashAccess < OpenStructWithHashAccess
|
28
|
+
attr_reader :nested_class
|
29
|
+
delegate :default_proc=, :to => :to_h
|
30
|
+
|
31
|
+
def initialize klass, *args
|
32
|
+
@nested_class = klass
|
33
|
+
hash = {}
|
34
|
+
|
35
|
+
hashes_and_keys = args.flatten
|
36
|
+
lazy_configs = hashes_and_keys.extract_options!
|
37
|
+
|
38
|
+
args.each do |v|
|
39
|
+
if v.is_a? Hash
|
40
|
+
key = v.first
|
41
|
+
value = v[key]
|
42
|
+
|
43
|
+
hash[key] = nested_class.new value
|
44
|
+
else
|
45
|
+
hash[v] = nested_class.new
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
lazy_configs.each do |k,v|
|
50
|
+
hash[k] = nested_class.new v
|
51
|
+
end
|
52
|
+
|
53
|
+
super hash
|
54
|
+
set_default_proc!
|
55
|
+
end
|
56
|
+
|
57
|
+
def << key
|
58
|
+
@table[key]
|
59
|
+
end
|
60
|
+
|
61
|
+
def []=(key, value)
|
62
|
+
if value.is_a? Hash
|
63
|
+
send "#{key}=", nested_class.new(value)
|
64
|
+
else
|
65
|
+
send "#{key}=", value
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def marshal_dump
|
70
|
+
h = to_h.dup
|
71
|
+
h.default = nil
|
72
|
+
|
73
|
+
[nested_class, h]
|
74
|
+
end
|
75
|
+
|
76
|
+
def marshal_load x
|
77
|
+
@nested_class = x.first
|
78
|
+
super x.last
|
79
|
+
set_default_proc!
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
def set_default_proc!
|
84
|
+
self.default_proc = lambda do |hash, key|
|
85
|
+
hash[key] = self.nested_class.new
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/lib/ansr/version.rb
CHANGED
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ansr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Benjamin Armintor
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-04-24 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: loggable
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,31 +20,41 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
28
|
+
name: arel
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ! '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
33
|
+
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ! '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activerecord
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
46
55
|
- !ruby/object:Gem::Dependency
|
47
56
|
name: rake
|
48
57
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
58
|
requirements:
|
51
59
|
- - ! '>='
|
52
60
|
- !ruby/object:Gem::Version
|
@@ -54,7 +62,6 @@ dependencies:
|
|
54
62
|
type: :development
|
55
63
|
prerelease: false
|
56
64
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
65
|
requirements:
|
59
66
|
- - ! '>='
|
60
67
|
- !ruby/object:Gem::Version
|
@@ -62,7 +69,6 @@ dependencies:
|
|
62
69
|
- !ruby/object:Gem::Dependency
|
63
70
|
name: bundler
|
64
71
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
72
|
requirements:
|
67
73
|
- - ! '>='
|
68
74
|
- !ruby/object:Gem::Version
|
@@ -70,7 +76,6 @@ dependencies:
|
|
70
76
|
type: :development
|
71
77
|
prerelease: false
|
72
78
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
79
|
requirements:
|
75
80
|
- - ! '>='
|
76
81
|
- !ruby/object:Gem::Version
|
@@ -78,7 +83,6 @@ dependencies:
|
|
78
83
|
- !ruby/object:Gem::Dependency
|
79
84
|
name: rspec
|
80
85
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
86
|
requirements:
|
83
87
|
- - ! '>='
|
84
88
|
- !ruby/object:Gem::Version
|
@@ -86,7 +90,6 @@ dependencies:
|
|
86
90
|
type: :development
|
87
91
|
prerelease: false
|
88
92
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
93
|
requirements:
|
91
94
|
- - ! '>='
|
92
95
|
- !ruby/object:Gem::Version
|
@@ -94,7 +97,6 @@ dependencies:
|
|
94
97
|
- !ruby/object:Gem::Dependency
|
95
98
|
name: yard
|
96
99
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
100
|
requirements:
|
99
101
|
- - ! '>='
|
100
102
|
- !ruby/object:Gem::Version
|
@@ -102,7 +104,6 @@ dependencies:
|
|
102
104
|
type: :development
|
103
105
|
prerelease: false
|
104
106
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
107
|
requirements:
|
107
108
|
- - ! '>='
|
108
109
|
- !ruby/object:Gem::Version
|
@@ -117,7 +118,39 @@ files:
|
|
117
118
|
- .gitignore
|
118
119
|
- Gemfile
|
119
120
|
- Gemfile.lock
|
121
|
+
- README.md
|
120
122
|
- ansr.gemspec
|
123
|
+
- ansr_blacklight/Gemfile
|
124
|
+
- ansr_blacklight/README.md
|
125
|
+
- ansr_blacklight/ansr_blacklight.gemspec
|
126
|
+
- ansr_blacklight/lib/ansr_blacklight.rb
|
127
|
+
- ansr_blacklight/lib/ansr_blacklight/arel.rb
|
128
|
+
- ansr_blacklight/lib/ansr_blacklight/arel/big_table.rb
|
129
|
+
- ansr_blacklight/lib/ansr_blacklight/arel/visitors.rb
|
130
|
+
- ansr_blacklight/lib/ansr_blacklight/arel/visitors/query_builder.rb
|
131
|
+
- ansr_blacklight/lib/ansr_blacklight/arel/visitors/to_no_sql.rb
|
132
|
+
- ansr_blacklight/lib/ansr_blacklight/base.rb
|
133
|
+
- ansr_blacklight/lib/ansr_blacklight/connection_adapters/no_sql_adapter.rb
|
134
|
+
- ansr_blacklight/lib/ansr_blacklight/model/querying.rb
|
135
|
+
- ansr_blacklight/lib/ansr_blacklight/relation.rb
|
136
|
+
- ansr_blacklight/lib/ansr_blacklight/relation/solr_projection_methods.rb
|
137
|
+
- ansr_blacklight/lib/ansr_blacklight/request_builders.rb
|
138
|
+
- ansr_blacklight/lib/ansr_blacklight/solr.rb
|
139
|
+
- ansr_blacklight/lib/ansr_blacklight/solr/request.rb
|
140
|
+
- ansr_blacklight/lib/ansr_blacklight/solr/response.rb
|
141
|
+
- ansr_blacklight/lib/ansr_blacklight/solr/response/group.rb
|
142
|
+
- ansr_blacklight/lib/ansr_blacklight/solr/response/group_response.rb
|
143
|
+
- ansr_blacklight/lib/ansr_blacklight/solr/response/more_like_this.rb
|
144
|
+
- ansr_blacklight/lib/ansr_blacklight/solr/response/pagination_methods.rb
|
145
|
+
- ansr_blacklight/lib/ansr_blacklight/solr/response/spelling.rb
|
146
|
+
- ansr_blacklight/spec/fixtures/config.yml
|
147
|
+
- ansr_blacklight/spec/lib/loaded_relation_spec.rb
|
148
|
+
- ansr_blacklight/spec/lib/queryable_relation_spec.rb
|
149
|
+
- ansr_blacklight/spec/lib/relation/faceting_spec.rb
|
150
|
+
- ansr_blacklight/spec/lib/relation/grouping_spec.rb
|
151
|
+
- ansr_blacklight/spec/spec_helper.rb
|
152
|
+
- ansr_dpla/Gemfile
|
153
|
+
- ansr_dpla/Gemfile.lock
|
121
154
|
- ansr_dpla/README.md
|
122
155
|
- ansr_dpla/ansr_dpla.gemspec
|
123
156
|
- ansr_dpla/app/models/collection.rb
|
@@ -138,12 +171,16 @@ files:
|
|
138
171
|
- ansr_dpla/lib/ansr_dpla/api.rb
|
139
172
|
- ansr_dpla/lib/ansr_dpla/arel.rb
|
140
173
|
- ansr_dpla/lib/ansr_dpla/arel/big_table.rb
|
141
|
-
- ansr_dpla/lib/ansr_dpla/arel/
|
142
|
-
- ansr_dpla/lib/ansr_dpla/arel/query_builder.rb
|
174
|
+
- ansr_dpla/lib/ansr_dpla/arel/visitors.rb
|
175
|
+
- ansr_dpla/lib/ansr_dpla/arel/visitors/query_builder.rb
|
176
|
+
- ansr_dpla/lib/ansr_dpla/arel/visitors/to_no_sql.rb
|
177
|
+
- ansr_dpla/lib/ansr_dpla/connection_adapters/no_sql_adapter.rb
|
143
178
|
- ansr_dpla/lib/ansr_dpla/model.rb
|
144
179
|
- ansr_dpla/lib/ansr_dpla/model/base.rb
|
145
180
|
- ansr_dpla/lib/ansr_dpla/model/pseudo_associate.rb
|
146
181
|
- ansr_dpla/lib/ansr_dpla/model/querying.rb
|
182
|
+
- ansr_dpla/lib/ansr_dpla/relation.rb
|
183
|
+
- ansr_dpla/lib/ansr_dpla/request.rb
|
147
184
|
- ansr_dpla/spec/adpla_test_api.rb
|
148
185
|
- ansr_dpla/spec/lib/api_spec.rb
|
149
186
|
- ansr_dpla/spec/lib/item_spec.rb
|
@@ -158,39 +195,50 @@ files:
|
|
158
195
|
- lib/ansr/.DS_Store
|
159
196
|
- lib/ansr/arel.rb
|
160
197
|
- lib/ansr/arel/big_table.rb
|
198
|
+
- lib/ansr/arel/configured_field.rb
|
199
|
+
- lib/ansr/arel/nodes.rb
|
200
|
+
- lib/ansr/arel/visitors.rb
|
201
|
+
- lib/ansr/arel/visitors/context.rb
|
202
|
+
- lib/ansr/arel/visitors/query_builder.rb
|
203
|
+
- lib/ansr/arel/visitors/to_no_sql.rb
|
161
204
|
- lib/ansr/base.rb
|
162
205
|
- lib/ansr/configurable.rb
|
206
|
+
- lib/ansr/connection_adapters.rb
|
207
|
+
- lib/ansr/connection_adapters/no_sql_adapter.rb
|
208
|
+
- lib/ansr/dummy_associations.rb
|
209
|
+
- lib/ansr/facets.rb
|
163
210
|
- lib/ansr/model.rb
|
164
|
-
- lib/ansr/model/connection.rb
|
165
211
|
- lib/ansr/model/connection_handler.rb
|
166
212
|
- lib/ansr/relation.rb
|
167
213
|
- lib/ansr/relation/arel_methods.rb
|
214
|
+
- lib/ansr/relation/group.rb
|
215
|
+
- lib/ansr/relation/predicate_builder.rb
|
168
216
|
- lib/ansr/relation/query_methods.rb
|
169
217
|
- lib/ansr/sanitization.rb
|
218
|
+
- lib/ansr/utils.rb
|
170
219
|
- lib/ansr/version.rb
|
171
220
|
homepage: http://github.com/barmintor/ansr
|
172
221
|
licenses: []
|
222
|
+
metadata: {}
|
173
223
|
post_install_message:
|
174
224
|
rdoc_options: []
|
175
225
|
require_paths:
|
176
226
|
- lib
|
177
227
|
required_ruby_version: !ruby/object:Gem::Requirement
|
178
|
-
none: false
|
179
228
|
requirements:
|
180
229
|
- - ! '>='
|
181
230
|
- !ruby/object:Gem::Version
|
182
231
|
version: '0'
|
183
232
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
|
-
none: false
|
185
233
|
requirements:
|
186
234
|
- - ! '>='
|
187
235
|
- !ruby/object:Gem::Version
|
188
236
|
version: '0'
|
189
237
|
requirements: []
|
190
238
|
rubyforge_project:
|
191
|
-
rubygems_version:
|
239
|
+
rubygems_version: 2.2.2
|
192
240
|
signing_key:
|
193
|
-
specification_version:
|
241
|
+
specification_version: 4
|
194
242
|
summary: ActiveRecord-style relations for no-sql data sources
|
195
243
|
test_files: []
|
196
244
|
has_rdoc:
|
@@ -1,81 +0,0 @@
|
|
1
|
-
module Ansr::Dpla
|
2
|
-
module Arel
|
3
|
-
class Connection < Ansr::Model::Connection
|
4
|
-
def initialize(klass)
|
5
|
-
super(klass)
|
6
|
-
@method = klass.name.downcase.pluralize.to_sym
|
7
|
-
@api = @table.engine.api
|
8
|
-
end
|
9
|
-
|
10
|
-
def to_sql(*args)
|
11
|
-
to_nosql(*args)
|
12
|
-
end
|
13
|
-
|
14
|
-
# the object generated by this method will be passed to the self#execute
|
15
|
-
def to_nosql(select_manager, bind_values)
|
16
|
-
qb = Ansr::Dpla::Arel::QueryBuilder.new(@table)
|
17
|
-
if ::Arel::Nodes::Intersect === select_manager
|
18
|
-
filter_context = select_manager.right
|
19
|
-
select_manager = select_manager.left
|
20
|
-
constraints(filter_context).each {|c| qb.where(c)}
|
21
|
-
projections(filter_context).each {|c| qb.add_facet(c)}
|
22
|
-
end
|
23
|
-
constraints(select_manager).each {|c| qb.where(c)}
|
24
|
-
orders(select_manager).each {|c| qb.order(c)}
|
25
|
-
projections(select_manager).each {|c| qb.select(c)}
|
26
|
-
if (limit = limit(select_manager))
|
27
|
-
qb.take(limit)
|
28
|
-
end
|
29
|
-
if (offset = offset(select_manager))
|
30
|
-
qb.skip(offset)
|
31
|
-
end
|
32
|
-
qb.query_opts
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
def to_aliases(select_manager, bind_values)
|
37
|
-
qb = Ansr::Dpla::Arel::QueryBuilder.new(@table)
|
38
|
-
if ::Arel::Nodes::Intersect === select_manager
|
39
|
-
select_manager = select_manager.left
|
40
|
-
end
|
41
|
-
projections(select_manager).each {|c| qb.select(c)}
|
42
|
-
qb.aliases
|
43
|
-
end
|
44
|
-
|
45
|
-
def execute(query, aliases = {})
|
46
|
-
json = @api.send(@method, query)
|
47
|
-
json = json.length > 0 ? JSON.load(json) : {}
|
48
|
-
if json['docs'] and aliases
|
49
|
-
json['docs'].each do |doc|
|
50
|
-
aliases.each do |k,v|
|
51
|
-
if doc[k]
|
52
|
-
old = doc.delete(k)
|
53
|
-
if old and doc[v]
|
54
|
-
doc[v] = Array(doc[v]) if doc[v]
|
55
|
-
Array(old).each {|ov| doc[v] << ov}
|
56
|
-
else
|
57
|
-
doc[v] = old
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
json
|
64
|
-
end
|
65
|
-
|
66
|
-
def table_exists?(table_name)
|
67
|
-
['Collection', 'Item'].include? table_name
|
68
|
-
end
|
69
|
-
|
70
|
-
def sanitize_limit(limit_value)
|
71
|
-
if (0..500) === limit_value.to_s.to_i
|
72
|
-
limit_value
|
73
|
-
else
|
74
|
-
Ansr::Relation::DEFAULT_PAGE_SIZE
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|