rasti-db 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/README.md +8 -0
  4. data/lib/rasti/db.rb +9 -18
  5. data/lib/rasti/db/collection.rb +1 -1
  6. data/lib/rasti/db/nql/invalid_expression_error.rb +19 -0
  7. data/lib/rasti/db/nql/nodes/binary_node.rb +25 -0
  8. data/lib/rasti/db/nql/nodes/comparisons/base.rb +17 -0
  9. data/lib/rasti/db/nql/nodes/comparisons/equal.rb +17 -0
  10. data/lib/rasti/db/nql/nodes/comparisons/greater_than.rb +17 -0
  11. data/lib/rasti/db/nql/nodes/comparisons/greater_than_or_equal.rb +17 -0
  12. data/lib/rasti/db/nql/nodes/comparisons/include.rb +17 -0
  13. data/lib/rasti/db/nql/nodes/comparisons/less_than.rb +17 -0
  14. data/lib/rasti/db/nql/nodes/comparisons/less_than_or_equal.rb +17 -0
  15. data/lib/rasti/db/nql/nodes/comparisons/like.rb +17 -0
  16. data/lib/rasti/db/nql/nodes/comparisons/not_equal.rb +17 -0
  17. data/lib/rasti/db/nql/nodes/comparisons/not_include.rb +17 -0
  18. data/lib/rasti/db/nql/nodes/conjunction.rb +15 -0
  19. data/lib/rasti/db/nql/nodes/constants/false.rb +17 -0
  20. data/lib/rasti/db/nql/nodes/constants/float.rb +17 -0
  21. data/lib/rasti/db/nql/nodes/constants/integer.rb +17 -0
  22. data/lib/rasti/db/nql/nodes/constants/literal_string.rb +17 -0
  23. data/lib/rasti/db/nql/nodes/constants/string.rb +17 -0
  24. data/lib/rasti/db/nql/nodes/constants/time.rb +23 -0
  25. data/lib/rasti/db/nql/nodes/constants/true.rb +17 -0
  26. data/lib/rasti/db/nql/nodes/disjunction.rb +15 -0
  27. data/lib/rasti/db/nql/nodes/field.rb +23 -0
  28. data/lib/rasti/db/nql/nodes/parenthesis_sentence.rb +19 -0
  29. data/lib/rasti/db/nql/nodes/sentence.rb +19 -0
  30. data/lib/rasti/db/nql/syntax.rb +2266 -0
  31. data/lib/rasti/db/nql/syntax.treetop +168 -0
  32. data/lib/rasti/db/query.rb +15 -0
  33. data/lib/rasti/db/relations/graph_builder.rb +3 -3
  34. data/lib/rasti/db/version.rb +1 -1
  35. data/rasti-db.gemspec +3 -1
  36. data/spec/coverage_helper.rb +5 -1
  37. data/spec/nql/dependency_tables_spec.rb +35 -0
  38. data/spec/nql/filter_condition_spec.rb +146 -0
  39. data/spec/nql/syntax_parser_spec.rb +209 -0
  40. data/spec/query_spec.rb +53 -0
  41. metadata +68 -2
data/spec/query_spec.rb CHANGED
@@ -177,4 +177,57 @@ describe 'Query' do
177
177
 
178
178
  end
179
179
 
180
+ describe 'NQL' do
181
+
182
+ before do
183
+ 1.upto(10) do |i|
184
+ db[:people].insert user_id: i,
185
+ document_number: i,
186
+ first_name: "Name #{i}",
187
+ last_name: "Last Name #{i}",
188
+ birth_date: Time.now
189
+ end
190
+
191
+ 1.upto(3) { |i| db[:categories].insert name: "Category #{i}" }
192
+
193
+ db[:comments].insert post_id: 1, user_id: 5, text: 'Comment 1'
194
+ db[:comments].insert post_id: 1, user_id: 7, text: 'Comment 2'
195
+ db[:comments].insert post_id: 2, user_id: 2, text: 'Comment 3'
196
+
197
+ db[:categories_posts].insert post_id: 1, category_id: 1
198
+ db[:categories_posts].insert post_id: 1, category_id: 2
199
+ db[:categories_posts].insert post_id: 2, category_id: 2
200
+ db[:categories_posts].insert post_id: 2, category_id: 3
201
+ db[:categories_posts].insert post_id: 3, category_id: 3
202
+ end
203
+
204
+ it 'Invalid expression' do
205
+ error = proc { posts_query.nql('a + b') }.must_raise Rasti::DB::NQL::InvalidExpressionError
206
+ error.message.must_equal 'Invalid filter expression: a + b'
207
+ end
208
+
209
+ it 'Filter to self table' do
210
+ people_query = Rasti::DB::Query.new People, db[:people]
211
+
212
+ people_query.nql('user_id > 7')
213
+ .map(&:user_id)
214
+ .sort
215
+ .must_equal [8, 9, 10]
216
+ end
217
+
218
+ it 'Filter to join table' do
219
+ posts_query.nql('categories.name = Category 2')
220
+ .map(&:id)
221
+ .sort
222
+ .must_equal [1, 2]
223
+ end
224
+
225
+ it 'Filter to 2nd order relation' do
226
+ posts_query.nql('comments.user.person.document_number = 7')
227
+ .map(&:id)
228
+ .must_equal [1]
229
+ end
230
+
231
+ end
232
+
180
233
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rasti-db
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Naiman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-06 00:00:00.000000000 Z
11
+ date: 2019-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: treetop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.4.8
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.4.8
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: consty
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -84,6 +98,20 @@ dependencies:
84
98
  - - ">="
85
99
  - !ruby/object:Gem::Version
86
100
  version: 0.0.2
101
+ - !ruby/object:Gem::Dependency
102
+ name: multi_require
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: '1.0'
108
+ type: :runtime
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - "~>"
113
+ - !ruby/object:Gem::Version
114
+ version: '1.0'
87
115
  - !ruby/object:Gem::Dependency
88
116
  name: bundler
89
117
  requirement: !ruby/object:Gem::Requirement
@@ -119,6 +147,9 @@ dependencies:
119
147
  - - "~>"
120
148
  - !ruby/object:Gem::Version
121
149
  version: '5.0'
150
+ - - "<"
151
+ - !ruby/object:Gem::Version
152
+ version: '5.11'
122
153
  type: :development
123
154
  prerelease: false
124
155
  version_requirements: !ruby/object:Gem::Requirement
@@ -126,6 +157,9 @@ dependencies:
126
157
  - - "~>"
127
158
  - !ruby/object:Gem::Version
128
159
  version: '5.0'
160
+ - - "<"
161
+ - !ruby/object:Gem::Version
162
+ version: '5.11'
129
163
  - !ruby/object:Gem::Dependency
130
164
  name: minitest-colorin
131
165
  requirement: !ruby/object:Gem::Requirement
@@ -231,6 +265,32 @@ files:
231
265
  - lib/rasti/db/collection.rb
232
266
  - lib/rasti/db/helpers.rb
233
267
  - lib/rasti/db/model.rb
268
+ - lib/rasti/db/nql/invalid_expression_error.rb
269
+ - lib/rasti/db/nql/nodes/binary_node.rb
270
+ - lib/rasti/db/nql/nodes/comparisons/base.rb
271
+ - lib/rasti/db/nql/nodes/comparisons/equal.rb
272
+ - lib/rasti/db/nql/nodes/comparisons/greater_than.rb
273
+ - lib/rasti/db/nql/nodes/comparisons/greater_than_or_equal.rb
274
+ - lib/rasti/db/nql/nodes/comparisons/include.rb
275
+ - lib/rasti/db/nql/nodes/comparisons/less_than.rb
276
+ - lib/rasti/db/nql/nodes/comparisons/less_than_or_equal.rb
277
+ - lib/rasti/db/nql/nodes/comparisons/like.rb
278
+ - lib/rasti/db/nql/nodes/comparisons/not_equal.rb
279
+ - lib/rasti/db/nql/nodes/comparisons/not_include.rb
280
+ - lib/rasti/db/nql/nodes/conjunction.rb
281
+ - lib/rasti/db/nql/nodes/constants/false.rb
282
+ - lib/rasti/db/nql/nodes/constants/float.rb
283
+ - lib/rasti/db/nql/nodes/constants/integer.rb
284
+ - lib/rasti/db/nql/nodes/constants/literal_string.rb
285
+ - lib/rasti/db/nql/nodes/constants/string.rb
286
+ - lib/rasti/db/nql/nodes/constants/time.rb
287
+ - lib/rasti/db/nql/nodes/constants/true.rb
288
+ - lib/rasti/db/nql/nodes/disjunction.rb
289
+ - lib/rasti/db/nql/nodes/field.rb
290
+ - lib/rasti/db/nql/nodes/parenthesis_sentence.rb
291
+ - lib/rasti/db/nql/nodes/sentence.rb
292
+ - lib/rasti/db/nql/syntax.rb
293
+ - lib/rasti/db/nql/syntax.treetop
234
294
  - lib/rasti/db/query.rb
235
295
  - lib/rasti/db/relations/base.rb
236
296
  - lib/rasti/db/relations/graph_builder.rb
@@ -250,6 +310,9 @@ files:
250
310
  - spec/coverage_helper.rb
251
311
  - spec/minitest_helper.rb
252
312
  - spec/model_spec.rb
313
+ - spec/nql/dependency_tables_spec.rb
314
+ - spec/nql/filter_condition_spec.rb
315
+ - spec/nql/syntax_parser_spec.rb
253
316
  - spec/query_spec.rb
254
317
  - spec/relations_spec.rb
255
318
  - spec/type_converters/postgres_spec.rb
@@ -283,6 +346,9 @@ test_files:
283
346
  - spec/coverage_helper.rb
284
347
  - spec/minitest_helper.rb
285
348
  - spec/model_spec.rb
349
+ - spec/nql/dependency_tables_spec.rb
350
+ - spec/nql/filter_condition_spec.rb
351
+ - spec/nql/syntax_parser_spec.rb
286
352
  - spec/query_spec.rb
287
353
  - spec/relations_spec.rb
288
354
  - spec/type_converters/postgres_spec.rb