active-orient 0.6 → 0.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/Gemfile +4 -10
- data/Guardfile +4 -12
- data/README.md +198 -261
- data/VERSION +1 -1
- data/active-orient-0.4.gem +0 -0
- data/active-orient-0.41.gem +0 -0
- data/active-orient.gemspec +5 -6
- data/config/boot.rb +0 -84
- data/config/connect.yml +4 -8
- data/examples/books.rb +39 -86
- data/examples/streets.rb +84 -85
- data/lib/active-orient.rb +9 -57
- data/lib/base.rb +145 -172
- data/lib/base_properties.rb +44 -40
- data/lib/model.rb +468 -0
- data/lib/orient.rb +60 -114
- data/lib/query.rb +73 -71
- data/lib/rest.rb +1059 -0
- data/lib/support.rb +319 -386
- data/test.rb +4 -0
- data/usecase.md +91 -0
- metadata +20 -65
- data/bin/active-orient-console +0 -38
- data/config/config.yml +0 -10
- data/create_project +0 -19
- data/examples/test_commands.rb +0 -92
- data/examples/test_commands_2.rb +0 -54
- data/examples/test_commands_3.rb +0 -48
- data/examples/test_commands_4.rb +0 -28
- data/examples/time_graph.md +0 -162
- data/gratefuldeadconcerts.md +0 -94
- data/lib/class_utils.rb +0 -300
- data/lib/database_utils.rb +0 -106
- data/lib/init.rb +0 -45
- data/lib/java-api.rb +0 -437
- data/lib/jdbc.rb +0 -211
- data/lib/model/edge.rb +0 -55
- data/lib/model/model.rb +0 -91
- data/lib/model/the_class.rb +0 -500
- data/lib/model/the_record.rb +0 -322
- data/lib/model/vertex.rb +0 -136
- data/lib/orientdb_private.rb +0 -48
- data/lib/other.rb +0 -330
- data/lib/rest/change.rb +0 -137
- data/lib/rest/create.rb +0 -488
- data/lib/rest/delete.rb +0 -134
- data/lib/rest/operations.rb +0 -160
- data/lib/rest/read.rb +0 -150
- data/lib/rest/rest.rb +0 -112
- data/lib/rest_disabled.rb +0 -24
- data/linkmap.md +0 -75
- data/namespace.md +0 -111
- data/old_lib_functions/two_general_class.rb +0 -139
- data/rails.md +0 -125
- data/rails/activeorient.rb +0 -53
- data/rails/config.yml +0 -10
- data/rails/connect.yml +0 -17
- data/usecase_oo.md +0 -61
data/lib/support.rb
CHANGED
@@ -1,439 +1,372 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
where: 'string'
|
8
|
-
where: { property: 'value', property: value, ... }
|
9
|
-
where: ['string, { property: value, ... }, ... ]
|
10
|
-
Used by update and select
|
11
|
-
=end
|
12
|
-
|
13
|
-
## ORD.compose_where 'z=34', {u:6}
|
14
|
-
# => "where z=34 and u = 6"
|
15
|
-
#
|
16
|
-
def compose_where *arg
|
17
|
-
arg = arg.flatten
|
18
|
-
return "" if arg.blank? || arg.size == 1 && arg.first.blank?
|
19
|
-
"where " + arg.map do |issue|
|
20
|
-
case issue
|
21
|
-
when String
|
22
|
-
issue
|
23
|
-
else
|
24
|
-
generate_sql_list issue
|
25
|
-
end
|
26
|
-
end.join(' and ')
|
27
|
-
end
|
28
|
-
|
29
|
-
=begin
|
30
|
-
designs a list of "Key = Value" pairs combined by "and" or the fillword provided by the block
|
31
|
-
ORD.generate_sql_list where: 25 , upper: '65'
|
32
|
-
=> "where = 25 and upper = '65'"
|
33
|
-
ORD.generate_sql_list( con_id: 25 , symbol: :G) { ',' }
|
34
|
-
=> "con_id = 25 , symbol = 'G'"
|
35
|
-
=end
|
36
|
-
def generate_sql_list attributes = {}
|
37
|
-
fill = block_given? ? yield : 'and'
|
38
|
-
attributes.map do |key, value|
|
39
|
-
case value
|
40
|
-
when ActiveOrient::Model
|
41
|
-
"#{key} = #{value.rrid}"
|
42
|
-
when Numeric
|
43
|
-
"#{key} = #{value}"
|
44
|
-
when ::Array
|
45
|
-
"#{key} in [#{value.to_orient}]"
|
46
|
-
when Range
|
47
|
-
"#{key} between #{value.first} and #{value.last} "
|
48
|
-
when DateTime
|
49
|
-
"#{key} = date(\'#{value.strftime("%Y%m%d%H%M%S")}\',\'yyyyMMddHHmmss\')"
|
50
|
-
when Date
|
51
|
-
"#{key} = date(\'#{value.to_s}\',\'yyyy-MM-dd\')"
|
52
|
-
else # String, Symbol, Time, Trueclass, Falseclass ...
|
53
|
-
"#{key} = \'#{value.to_s}\'"
|
54
|
-
end
|
55
|
-
end.join(" #{fill} ")
|
1
|
+
class String
|
2
|
+
def to_classname
|
3
|
+
if self[0] =='$'
|
4
|
+
self[1..-1]
|
5
|
+
else
|
6
|
+
self.camelize
|
56
7
|
end
|
57
8
|
end
|
9
|
+
def to_orient
|
10
|
+
self.gsub /%/, '(percent)'
|
58
11
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
def direction= dir
|
70
|
-
@direction = dir
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
def direction
|
75
|
-
fillup = @edge.present? ? @edge : ''
|
76
|
-
case @direction
|
77
|
-
when :both
|
78
|
-
" -#{fillup}- "
|
79
|
-
when :in
|
80
|
-
" <-#{fillup}- "
|
81
|
-
when :out
|
82
|
-
" -#{fillup}-> "
|
83
|
-
end
|
84
|
-
|
12
|
+
end
|
13
|
+
def rid?
|
14
|
+
self =~ /\A[#]{,1}[0-9]{1,}:[0-9]{1,}\z/
|
15
|
+
end
|
16
|
+
def from_orient
|
17
|
+
if rid?
|
18
|
+
ActiveOrient::Model.autoload_object self
|
19
|
+
else
|
20
|
+
self
|
21
|
+
end
|
85
22
|
end
|
23
|
+
## this enables the universal use of an rid-string as pseudonym for a ActiveOrient::Model
|
24
|
+
alias :reload! from_orient
|
25
|
+
end
|
26
|
+
class NilClass
|
27
|
+
def to_orient
|
28
|
+
self
|
29
|
+
end
|
30
|
+
end
|
31
|
+
class Symbol
|
32
|
+
def to_orient
|
33
|
+
self.to_s.to_orient
|
34
|
+
end
|
35
|
+
def from_orient
|
36
|
+
self
|
37
|
+
end
|
38
|
+
end
|
86
39
|
|
87
|
-
|
88
|
-
|
89
|
-
|
40
|
+
class Numeric
|
41
|
+
def from_orient
|
42
|
+
self
|
43
|
+
end
|
44
|
+
def to_orient
|
45
|
+
self
|
46
|
+
end
|
47
|
+
end
|
90
48
|
|
91
|
-
|
92
|
-
|
49
|
+
class Time
|
50
|
+
def from_orient
|
51
|
+
self
|
93
52
|
end
|
53
|
+
def to_orient
|
54
|
+
self
|
55
|
+
end
|
56
|
+
end
|
57
|
+
class Date
|
58
|
+
def from_orient
|
59
|
+
self
|
60
|
+
end
|
61
|
+
def to_orient
|
62
|
+
self
|
63
|
+
end
|
64
|
+
end
|
94
65
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
case k
|
112
|
-
when :as
|
113
|
-
@as = v
|
114
|
-
when :while
|
115
|
-
@while << v
|
116
|
-
when :where
|
117
|
-
@where << v
|
118
|
-
when :class
|
119
|
-
@match_class = v
|
120
|
-
@as = v.pluralize
|
121
|
-
else
|
122
|
-
self.send k, v
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def while_s
|
128
|
-
compose_where( @while ).gsub( /where/, 'while:(' )<< ")" unless @while.blank?
|
129
|
-
end
|
66
|
+
class TrueClass
|
67
|
+
def from_orient
|
68
|
+
self
|
69
|
+
end
|
70
|
+
def to_orient
|
71
|
+
self
|
72
|
+
end
|
73
|
+
end
|
74
|
+
class FalseClass
|
75
|
+
def from_orient
|
76
|
+
self
|
77
|
+
end
|
78
|
+
def to_orient
|
79
|
+
self
|
80
|
+
end
|
81
|
+
end
|
130
82
|
|
131
|
-
|
132
|
-
|
83
|
+
class Array
|
84
|
+
def to_orient
|
85
|
+
map &:to_orient
|
133
86
|
end
|
134
|
-
def
|
135
|
-
|
136
|
-
end
|
137
|
-
|
138
|
-
def maxdepth=x
|
139
|
-
@maxdepth = x
|
140
|
-
end
|
141
|
-
|
142
|
-
def method_missing method, *arg, &b
|
143
|
-
@misc << method.to_s << " " << arg.map(&:to_s).join(' ')
|
87
|
+
def from_orient
|
88
|
+
map &:from_orient
|
144
89
|
end
|
90
|
+
end
|
91
|
+
class Hash #WithIndifferentAccess
|
92
|
+
def from_orient
|
93
|
+
substitute_hash = HashWithIndifferentAccess.new
|
94
|
+
keys.each{ |k| puts self[k].inspect }
|
95
|
+
keys.each{| k | substitute_hash[k] = self[k].from_orient }
|
96
|
+
substitute_hash
|
145
97
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
'{'+ [ "class: #{@match_class}",
|
152
|
-
"as: #{@as}" ,
|
153
|
-
where_s ].compact.join(', ') + '}'
|
154
|
-
end
|
98
|
+
end
|
99
|
+
def to_orient
|
100
|
+
substitute_hash = Hash.new
|
101
|
+
keys.each{| k | substitute_hash[k] = self[k].to_orient }
|
102
|
+
substitute_hash
|
155
103
|
|
156
|
-
|
104
|
+
end
|
157
105
|
|
158
|
-
|
159
|
-
|
160
|
-
where_s,
|
161
|
-
while_s,
|
162
|
-
@maxdepth >0 ? "maxdepth: #{maxdepth}": nil ].compact.join(', ')+'}'
|
106
|
+
def nested_under_indifferent_access
|
107
|
+
HashWithIndifferentAccess.new self
|
163
108
|
end
|
164
|
-
alias :to_s :compose
|
165
109
|
end
|
166
110
|
|
167
|
-
class OrientQuery
|
168
|
-
include Support
|
169
111
|
|
170
|
-
|
171
|
-
Call where without a parameter to request the saved where-string
|
172
|
-
To create the where-part of the query a string, a hash or an Array is supported
|
112
|
+
module OrientSupport
|
173
113
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
=end
|
114
|
+
module Support
|
115
|
+
=begin
|
116
|
+
supports
|
178
117
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
attr_accessor :order
|
183
|
-
attr_accessor :match_statements
|
184
|
-
|
185
|
-
def initialize **args
|
186
|
-
@projection = []
|
187
|
-
@misc = []
|
188
|
-
@let = []
|
189
|
-
@where = []
|
190
|
-
@order = []
|
191
|
-
@aliases = []
|
192
|
-
@match_statements = []
|
193
|
-
@class = nil
|
194
|
-
@kind = 'select'
|
195
|
-
args.each do |k, v|
|
196
|
-
case k
|
197
|
-
when :projection
|
198
|
-
@projection << v
|
199
|
-
when :let
|
200
|
-
@let << v
|
201
|
-
when :order
|
202
|
-
@order << v
|
203
|
-
when :where
|
204
|
-
@where << v
|
205
|
-
when :kind
|
206
|
-
@kind = v
|
207
|
-
when :start
|
208
|
-
@match_statements[0] = MatchStatement.new **v
|
209
|
-
# @match_statements[1] = MatchConnection.new
|
210
|
-
when :connection
|
211
|
-
@match_statements[1] = MatchConnection.new **v
|
212
|
-
when :return
|
213
|
-
@aliases << v
|
214
|
-
else
|
215
|
-
self.send k, v
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
118
|
+
where: 'string'
|
119
|
+
where: { property: 'value', property: value, ... }
|
120
|
+
where: ['string, { property: value, ... }, ... ]
|
219
121
|
|
220
|
-
def method_missing method, *arg, &b
|
221
|
-
@misc << method.to_s << " " << arg.map(&:to_s).join(' ')
|
222
|
-
end
|
223
122
|
|
224
|
-
|
225
|
-
|
226
|
-
end
|
123
|
+
Used by update and select
|
124
|
+
=end
|
227
125
|
|
228
|
-
def
|
229
|
-
|
126
|
+
def compose_where *arg
|
127
|
+
arg=arg.flatten
|
128
|
+
return "" if arg.blank? || arg.size == 1 && arg.first.blank?
|
129
|
+
"where " + arg.map do |issue|
|
130
|
+
case issue
|
131
|
+
when String
|
132
|
+
issue
|
133
|
+
when Hash
|
134
|
+
generate_sql_list issue
|
135
|
+
end
|
136
|
+
end.join( ' and ' )
|
137
|
+
end
|
138
|
+
def generate_sql_list attributes={}
|
139
|
+
attributes.map do | key, value |
|
140
|
+
case value
|
141
|
+
when Numeric
|
142
|
+
key.to_s << " = " << value.to_s
|
143
|
+
else # String, Symbol, Date, Time, Trueclass, Falseclass ...
|
144
|
+
key.to_s << ' = ' << "\'#{ value }\'"
|
145
|
+
end
|
146
|
+
end.join( ' and ' )
|
230
147
|
end
|
148
|
+
end # module
|
231
149
|
|
232
150
|
|
151
|
+
class OrientQuery
|
233
152
|
|
234
|
-
|
235
|
-
(only if kind == :match): connect
|
236
|
-
|
237
|
-
Add a connection to the match-query
|
238
|
-
|
239
|
-
A Match-Query alwas has an Entry-Stratement and maybe other Statements.
|
240
|
-
They are connected via " -> " (outE), "<-" (inE) or "--" (both).
|
241
|
-
|
242
|
-
The connection method adds a connection to the statement-stack.
|
153
|
+
include Support
|
243
154
|
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
155
|
+
def initialize **args
|
156
|
+
@projection = []
|
157
|
+
@misc = []
|
158
|
+
@let = []
|
159
|
+
@where = []
|
160
|
+
@order = []
|
161
|
+
@kind = 'select'
|
162
|
+
args.each do | k,v|
|
163
|
+
case k
|
164
|
+
when :projection
|
165
|
+
@projection << v
|
166
|
+
when :let
|
167
|
+
@let << v
|
168
|
+
when :order
|
169
|
+
@order << v
|
170
|
+
when :where
|
171
|
+
@where << v
|
172
|
+
when :kind
|
173
|
+
@kind = v
|
174
|
+
else
|
175
|
+
self.send k, v
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
250
179
|
|
251
|
-
|
252
|
-
|
253
|
-
|
180
|
+
def method_missing method, *arg, &b
|
181
|
+
@misc << method.to_s << " " << arg.map(&:to_s).join(' ')
|
182
|
+
end
|
254
183
|
|
255
|
-
def
|
256
|
-
|
257
|
-
|
258
|
-
m
|
259
|
-
end
|
184
|
+
def misc
|
185
|
+
@misc.join(' ') unless @misc.empty?
|
186
|
+
end
|
260
187
|
|
188
|
+
def subquery
|
189
|
+
nil
|
190
|
+
end
|
261
191
|
=begin
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
( classname and where-condition ), a connection followd by other Statement-connection-pairs.
|
266
|
-
It performs a sub-query starting at the given entry-point.
|
267
|
-
|
268
|
-
Statement adds a statement to the statement-stack.
|
269
|
-
Statement returns the created OrientSupport::MatchStatement-record for further modifications.
|
270
|
-
It is compiled by calling »compose«.
|
271
|
-
|
272
|
-
OrientSupport::OrientQuery collects any "as"-directive for inclusion in the return-statement
|
273
|
-
|
274
|
-
Parameter (all optional)
|
275
|
-
Class: classname, :where: {}, while: {}, as: string, maxdepth: >0 ,
|
276
|
-
|
192
|
+
Output the compiled query
|
193
|
+
parmeter: destination (rest, batch )
|
194
|
+
If the query is submitted via the REST-Interface (as get-command), the limit parameter is extracted.
|
277
195
|
=end
|
278
|
-
def
|
279
|
-
|
280
|
-
|
281
|
-
|
196
|
+
def compose( destination: :batch )
|
197
|
+
if destination == :rest
|
198
|
+
[ @kind, projection_s, from, let_s, where_s , subquery, misc, order_s , group_by, unwind, skip ].compact.join(' ')
|
199
|
+
else
|
200
|
+
[ @kind, projection_s, from, let_s, where_s , subquery, misc, order_s , group_by, limit, unwind, skip ].compact.join(' ')
|
201
|
+
end
|
202
|
+
end
|
203
|
+
alias :to_s :compose
|
282
204
|
=begin
|
283
|
-
|
284
|
-
Parameter: destination (rest, batch )
|
285
|
-
If the query is submitted via the REST-Interface (as get-command), the limit parameter is extracted.
|
205
|
+
from can either be a Databaseclass to operate on or a Subquery providing data to query further
|
286
206
|
=end
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
207
|
+
def from arg=nil
|
208
|
+
if arg.present?
|
209
|
+
@database = case arg
|
210
|
+
when Class
|
211
|
+
arg.new.classname
|
212
|
+
when ActiveOrient::Model
|
213
|
+
classname
|
214
|
+
when String
|
215
|
+
arg
|
216
|
+
when Symbol
|
217
|
+
arg
|
218
|
+
when OrientQuery
|
219
|
+
' ( '+ arg.to_s + ' ) '
|
220
|
+
end
|
221
|
+
compose # return the complete query
|
222
|
+
else # read from
|
223
|
+
"from " << @database.to_s unless @database.nil?
|
224
|
+
end
|
225
|
+
end
|
226
|
+
alias :from= :from
|
227
|
+
def database_class= arg
|
228
|
+
@database = arg if @database.present?
|
229
|
+
if @from.is_a? OrientQuery
|
230
|
+
@from.database_class= arg
|
231
|
+
end
|
232
|
+
end
|
233
|
+
def database_class
|
234
|
+
if @database.present?
|
235
|
+
@database
|
236
|
+
elsif @from.is_a? OrientQuery
|
237
|
+
@from.database_class
|
238
|
+
else
|
239
|
+
nil
|
294
240
|
end
|
295
|
-
elsif destination == :rest
|
296
|
-
[@kind, projection_s, from, let_s, where_s, subquery, misc, order_s, group_by, unwind, skip].compact.join(' ')
|
297
|
-
else
|
298
|
-
[@kind, projection_s, from, let_s, where_s, subquery, misc, order_s, group_by, limit, unwind, skip].compact.join(' ')
|
299
241
|
end
|
300
|
-
|
301
|
-
alias :to_s :compose
|
242
|
+
|
302
243
|
|
303
244
|
=begin
|
304
|
-
|
305
|
-
=end
|
245
|
+
Call where without a parameter to request the saved where-string
|
306
246
|
|
247
|
+
to create the where-part of the query a string, a hash or an Array is supported
|
307
248
|
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
when Class
|
316
|
-
arg.ref_name
|
317
|
-
else
|
318
|
-
if arg.to_s.rid? # a string with "#ab:cd"
|
319
|
-
arg
|
320
|
-
else # a databas-class-name
|
321
|
-
arg.to_s
|
322
|
-
end
|
323
|
-
end
|
324
|
-
compose # return the complete query
|
325
|
-
else # read from
|
326
|
-
"from #{@database}" unless @database.nil?
|
249
|
+
where: "r > 9" --> where r > 9
|
250
|
+
where: {a: 9, b: 's'} --> where a = 9 and b = 's'
|
251
|
+
where:[{ a: 2} , 'b > 3',{ c: 'ufz' }] --> where a = 2 and b > 3 and c = 'ufz'
|
252
|
+
=end
|
253
|
+
attr_accessor :where
|
254
|
+
def where_s
|
255
|
+
compose_where @where
|
327
256
|
end
|
328
|
-
end
|
329
|
-
alias :from= :from
|
330
|
-
|
331
|
-
def database_class
|
332
|
-
if @database.present?
|
333
|
-
@database
|
334
|
-
elsif @from.is_a? OrientQuery
|
335
|
-
@from.database_class
|
336
|
-
else
|
337
|
-
nil
|
338
|
-
end
|
339
|
-
end
|
340
257
|
|
341
|
-
def database_class= arg
|
342
|
-
@database = arg if @database.present?
|
343
|
-
if @from.is_a? OrientQuery
|
344
|
-
@from.database_class= arg
|
345
|
-
end
|
346
|
-
end
|
347
258
|
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
end
|
364
|
-
end.join(', ')
|
365
|
-
end
|
366
|
-
end
|
259
|
+
attr_accessor :let
|
260
|
+
def let_s
|
261
|
+
unless @let.empty?
|
262
|
+
"let " << @let.map do |s|
|
263
|
+
case s
|
264
|
+
when Hash
|
265
|
+
s.map{ |x,y| "$#{x} = ( #{y} )"}.join( ', ')
|
266
|
+
when Array
|
267
|
+
s.join(', ')
|
268
|
+
else
|
269
|
+
s
|
270
|
+
end
|
271
|
+
end.join(', ')
|
272
|
+
end
|
273
|
+
end
|
367
274
|
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
275
|
+
def distinct d
|
276
|
+
@projection << case d
|
277
|
+
when String, Symbol
|
278
|
+
"distinct( #{d.to_s} )"
|
279
|
+
when Array
|
280
|
+
"distinct( #{d.first} ) as #{d.last}"
|
281
|
+
when Hash
|
282
|
+
"distinct( #{d.first.first} ) as #{d.first.last}"
|
283
|
+
else
|
284
|
+
""
|
285
|
+
end
|
286
|
+
compose # return the hole query
|
287
|
+
end
|
288
|
+
alias :distinct= :distinct
|
289
|
+
|
290
|
+
attr_accessor :projection
|
291
|
+
def projection_s
|
292
|
+
|
293
|
+
@projection.map do | s |
|
294
|
+
case s
|
295
|
+
when Hash
|
296
|
+
s.map{ |x,y| "#{x} as #{y}"}.join( ', ')
|
297
|
+
when Array
|
298
|
+
s.join(', ')
|
299
|
+
else
|
300
|
+
s
|
301
|
+
end
|
302
|
+
end.join( ', ' )
|
392
303
|
|
393
|
-
|
394
|
-
@limit = "limit #{l.to_s}" if l.present?
|
395
|
-
# only a string is allowed
|
396
|
-
@limit # return_value
|
397
|
-
end
|
398
|
-
alias :limit= :limit
|
304
|
+
end
|
399
305
|
|
400
|
-
def get_limit
|
401
|
-
@limit.nil? ? -1 : @limit.split(' ').last.to_i
|
402
|
-
end
|
403
306
|
|
404
|
-
|
405
|
-
@group = "group by #{g.to_s}" if g.present?
|
406
|
-
# only a string is allowed
|
407
|
-
@group # return_value
|
408
|
-
end
|
307
|
+
# def where= w
|
409
308
|
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
@unwind # return_value
|
414
|
-
end
|
309
|
+
# end
|
310
|
+
# select_string = ("select " + select_string + distinct_string + ' from ' + class_name(o_class) ).squeeze(' ')
|
311
|
+
# where_string = compose_where( where )
|
415
312
|
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
313
|
+
def limit l=nil
|
314
|
+
@limit = "limit #{l.to_s}" if l.present?
|
315
|
+
# only a string is allowed
|
316
|
+
@limit # return_value
|
317
|
+
end
|
318
|
+
alias :limit= :limit
|
319
|
+
=begin :nodoc
|
320
|
+
The Rest-Interface needs to separate the limit-value.
|
321
|
+
This Method extracts the number, usage in REST::get_documents
|
420
322
|
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
end
|
435
|
-
end # def
|
436
|
-
end # class
|
323
|
+
=end
|
324
|
+
def get_limit
|
325
|
+
@limit.nil? ? -1 : @limit.split(' ').last.to_i
|
326
|
+
end
|
327
|
+
def group_by g=nil
|
328
|
+
@group = "group by #{g.to_s}" if g.present?
|
329
|
+
# only a string is allowed
|
330
|
+
@group # return_value
|
331
|
+
end
|
332
|
+
def unwind u=nil
|
333
|
+
@unwind = "unwind #{u.to_s}" if u.present?
|
334
|
+
# only a string is allowed
|
335
|
+
@unwind # return_value
|
336
|
+
end
|
437
337
|
|
338
|
+
def skip n=nil
|
339
|
+
@skip= n if n.present?
|
340
|
+
"skip #{@skip}" if @skip.present?
|
341
|
+
end
|
438
342
|
|
439
|
-
|
343
|
+
attr_accessor :order
|
344
|
+
|
345
|
+
def order_s
|
346
|
+
unless @order.empty?
|
347
|
+
# the [@order] is nessesary to enable query.order= "..." oder query.order= { a: :b }
|
348
|
+
"order by " << [@order].flatten.map do | o |
|
349
|
+
case o
|
350
|
+
when Hash
|
351
|
+
o.map{ |x,y| "#{x} #{y}" }.join( " " )
|
352
|
+
else
|
353
|
+
o.to_s
|
354
|
+
end # case
|
355
|
+
end.join(', ')
|
356
|
+
else
|
357
|
+
''
|
358
|
+
end
|
359
|
+
end
|
360
|
+
# misc_string = if skip > 0 && limit > 0
|
361
|
+
# " skip: #{skip} "
|
362
|
+
# else
|
363
|
+
# ""
|
364
|
+
# end
|
365
|
+
# #
|
366
|
+
#
|
367
|
+
# def compose
|
368
|
+
#
|
369
|
+
# end
|
370
|
+
|
371
|
+
end
|
372
|
+
end # module
|