rasti-db 1.5.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +52 -19
  3. data/lib/rasti/db.rb +11 -2
  4. data/lib/rasti/db/collection.rb +67 -36
  5. data/lib/rasti/db/computed_attribute.rb +22 -0
  6. data/lib/rasti/db/data_source.rb +18 -0
  7. data/lib/rasti/db/environment.rb +32 -0
  8. data/lib/rasti/db/nql/filter_condition_strategies/base.rb +17 -0
  9. data/lib/rasti/db/nql/filter_condition_strategies/postgres.rb +21 -0
  10. data/lib/rasti/db/nql/filter_condition_strategies/sqlite.rb +21 -0
  11. data/lib/rasti/db/nql/filter_condition_strategies/types/generic.rb +49 -0
  12. data/lib/rasti/db/nql/filter_condition_strategies/types/pg_array.rb +32 -0
  13. data/lib/rasti/db/nql/filter_condition_strategies/types/sqlite_array.rb +34 -0
  14. data/lib/rasti/db/nql/filter_condition_strategies/unsupported_type_comparison.rb +22 -0
  15. data/lib/rasti/db/nql/nodes/array_content.rb +21 -0
  16. data/lib/rasti/db/nql/nodes/attribute.rb +37 -0
  17. data/lib/rasti/db/nql/nodes/binary_node.rb +4 -0
  18. data/lib/rasti/db/nql/nodes/comparisons/base.rb +15 -1
  19. data/lib/rasti/db/nql/nodes/comparisons/equal.rb +0 -4
  20. data/lib/rasti/db/nql/nodes/comparisons/greater_than.rb +0 -4
  21. data/lib/rasti/db/nql/nodes/comparisons/greater_than_or_equal.rb +0 -4
  22. data/lib/rasti/db/nql/nodes/comparisons/include.rb +0 -4
  23. data/lib/rasti/db/nql/nodes/comparisons/less_than.rb +0 -4
  24. data/lib/rasti/db/nql/nodes/comparisons/less_than_or_equal.rb +0 -4
  25. data/lib/rasti/db/nql/nodes/comparisons/like.rb +0 -4
  26. data/lib/rasti/db/nql/nodes/comparisons/not_equal.rb +0 -4
  27. data/lib/rasti/db/nql/nodes/comparisons/not_include.rb +0 -4
  28. data/lib/rasti/db/nql/nodes/conjunction.rb +2 -2
  29. data/lib/rasti/db/nql/nodes/constants/array.rb +17 -0
  30. data/lib/rasti/db/nql/nodes/constants/base.rb +17 -0
  31. data/lib/rasti/db/nql/nodes/constants/false.rb +1 -1
  32. data/lib/rasti/db/nql/nodes/constants/float.rb +1 -1
  33. data/lib/rasti/db/nql/nodes/constants/integer.rb +1 -1
  34. data/lib/rasti/db/nql/nodes/constants/literal_string.rb +1 -1
  35. data/lib/rasti/db/nql/nodes/constants/string.rb +1 -1
  36. data/lib/rasti/db/nql/nodes/constants/time.rb +1 -1
  37. data/lib/rasti/db/nql/nodes/constants/true.rb +1 -1
  38. data/lib/rasti/db/nql/nodes/disjunction.rb +2 -2
  39. data/lib/rasti/db/nql/nodes/parenthesis_sentence.rb +6 -2
  40. data/lib/rasti/db/nql/nodes/sentence.rb +6 -2
  41. data/lib/rasti/db/nql/syntax.rb +262 -44
  42. data/lib/rasti/db/nql/syntax.treetop +27 -14
  43. data/lib/rasti/db/query.rb +55 -23
  44. data/lib/rasti/db/relations/base.rb +22 -8
  45. data/lib/rasti/db/relations/graph.rb +10 -16
  46. data/lib/rasti/db/relations/many_to_many.rb +57 -23
  47. data/lib/rasti/db/relations/many_to_one.rb +9 -7
  48. data/lib/rasti/db/relations/one_to_many.rb +21 -13
  49. data/lib/rasti/db/type_converters/sqlite.rb +62 -0
  50. data/lib/rasti/db/type_converters/sqlite_types/array.rb +34 -0
  51. data/lib/rasti/db/version.rb +1 -1
  52. data/rasti-db.gemspec +1 -0
  53. data/spec/collection_spec.rb +210 -50
  54. data/spec/computed_attribute_spec.rb +32 -0
  55. data/spec/minitest_helper.rb +77 -15
  56. data/spec/model_spec.rb +4 -2
  57. data/spec/nql/computed_attributes_spec.rb +29 -0
  58. data/spec/nql/filter_condition_spec.rb +23 -4
  59. data/spec/nql/filter_condition_strategies_spec.rb +112 -0
  60. data/spec/nql/syntax_parser_spec.rb +36 -5
  61. data/spec/query_spec.rb +340 -54
  62. data/spec/relations_spec.rb +27 -7
  63. data/spec/type_converters/sqlite_spec.rb +66 -0
  64. metadata +40 -4
  65. data/lib/rasti/db/helpers.rb +0 -16
  66. data/lib/rasti/db/nql/nodes/field.rb +0 -23
@@ -30,14 +30,19 @@ describe 'Relations' do
30
30
  relation.many_to_one?.must_equal false
31
31
  relation.many_to_many?.must_equal false
32
32
  relation.one_to_one?.must_equal false
33
+
34
+ relation.from_one?.must_equal true
35
+ relation.from_many?.must_equal false
36
+ relation.to_one?.must_equal false
37
+ relation.to_many?.must_equal true
33
38
  end
34
39
 
35
40
  it 'Graph' do
36
41
  user_id = db[:users].insert name: 'User 1'
37
- 1.upto(2) { |i| db[:posts].insert user_id: user_id, title: "Post #{i}", body: '...' }
42
+ 1.upto(2) { |i| db[:posts].insert user_id: user_id, title: "Post #{i}", body: '...', language_id: 1 }
38
43
  rows = db[:users].all
39
44
 
40
- Users.relations[:posts].fetch_graph rows, db
45
+ Users.relations[:posts].fetch_graph environment, rows
41
46
 
42
47
  rows[0][:posts].must_equal posts.where(user_id: user_id).all
43
48
  end
@@ -72,14 +77,19 @@ describe 'Relations' do
72
77
  relation.many_to_one?.must_equal true
73
78
  relation.many_to_many?.must_equal false
74
79
  relation.one_to_one?.must_equal false
80
+
81
+ relation.from_one?.must_equal false
82
+ relation.from_many?.must_equal true
83
+ relation.to_one?.must_equal true
84
+ relation.to_many?.must_equal false
75
85
  end
76
86
 
77
87
  it 'Graph' do
78
88
  user_id = db[:users].insert name: 'User 1'
79
- db[:posts].insert user_id: user_id, title: 'Post 1', body: '...'
89
+ db[:posts].insert user_id: user_id, title: 'Post 1', body: '...', language_id: 1
80
90
  rows = db[:posts].all
81
91
 
82
- Posts.relations[:user].fetch_graph rows, db
92
+ Posts.relations[:user].fetch_graph environment, rows
83
93
 
84
94
  rows[0][:user].must_equal users.first
85
95
  end
@@ -120,12 +130,17 @@ describe 'Relations' do
120
130
  relation.many_to_one?.must_equal false
121
131
  relation.many_to_many?.must_equal true
122
132
  relation.one_to_one?.must_equal false
133
+
134
+ relation.from_one?.must_equal false
135
+ relation.from_many?.must_equal true
136
+ relation.to_one?.must_equal false
137
+ relation.to_many?.must_equal true
123
138
  end
124
139
 
125
140
  it 'Graph' do
126
141
  user_id = db[:users].insert name: 'User 1'
127
142
 
128
- 1.upto(2) { |i| db[:posts].insert user_id: user_id, title: "Post #{i}", body: '...' }
143
+ 1.upto(2) { |i| db[:posts].insert user_id: user_id, title: "Post #{i}", body: '...', language_id: 1 }
129
144
 
130
145
  1.upto(4) { |i| db[:categories].insert name: "Category #{i}" }
131
146
 
@@ -136,7 +151,7 @@ describe 'Relations' do
136
151
 
137
152
  rows = db[:posts].all
138
153
 
139
- Posts.relations[:categories].fetch_graph rows, db
154
+ Posts.relations[:categories].fetch_graph environment, rows
140
155
 
141
156
  rows[0][:categories].must_equal categories.where(id: [1,2]).all
142
157
  rows[1][:categories].must_equal categories.where(id: [3,4]).all
@@ -172,6 +187,11 @@ describe 'Relations' do
172
187
  relation.many_to_one?.must_equal false
173
188
  relation.many_to_many?.must_equal false
174
189
  relation.one_to_one?.must_equal true
190
+
191
+ relation.from_one?.must_equal true
192
+ relation.from_many?.must_equal false
193
+ relation.to_one?.must_equal true
194
+ relation.to_many?.must_equal false
175
195
  end
176
196
 
177
197
  it 'Graph' do
@@ -186,7 +206,7 @@ describe 'Relations' do
186
206
 
187
207
  rows = db[:users].all
188
208
 
189
- Users.relations[:person].fetch_graph rows, db
209
+ Users.relations[:person].fetch_graph environment, rows
190
210
 
191
211
  2.times do |i|
192
212
  rows[i][:person].must_equal people.find("document_#{i}")
@@ -0,0 +1,66 @@
1
+ require 'minitest_helper'
2
+
3
+ describe Rasti::DB::TypeConverters::SQLite do
4
+
5
+ let(:type_converter) { Rasti::DB::TypeConverters::SQLite }
6
+
7
+ let(:sqlite) do
8
+ Object.new.tap do |sqlite|
9
+
10
+ def sqlite.opts
11
+ {
12
+ database: 'database'
13
+ }
14
+ end
15
+
16
+ def sqlite.schema(table_name, opts={})
17
+ [
18
+ [:text_array, {db_type: 'text[]'}],
19
+ ]
20
+ end
21
+
22
+ end
23
+ end
24
+
25
+ describe 'Default' do
26
+
27
+ it 'must not change value in to_db if column not found in mapping' do
28
+ string = type_converter.to_db sqlite, :table_name, :column, "hola"
29
+ string.class.must_equal String
30
+ string.must_equal "hola"
31
+ end
32
+
33
+ it 'must not change value in from_db if class not found in mapping' do
34
+ string = type_converter.from_db "hola"
35
+ string.class.must_equal String
36
+ string.must_equal "hola"
37
+ end
38
+
39
+ end
40
+
41
+ describe 'Array' do
42
+
43
+ describe 'To DB' do
44
+
45
+ it 'must transform Array to SQLiteArray' do
46
+ sqlite_array = type_converter.to_db sqlite, :table_name, :text_array, ['a', 'b', 'c']
47
+ sqlite_array.class.must_equal String
48
+ sqlite_array.must_equal '["a","b","c"]'
49
+ end
50
+
51
+ end
52
+
53
+ describe 'From DB' do
54
+
55
+ it 'must transform SQLiteArray to Array' do
56
+ sqlite_array = '["a","b","c"]'
57
+ array = type_converter.from_db sqlite_array
58
+ array.class.must_equal Array
59
+ array.must_equal ['a', 'b', 'c']
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+
66
+ 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.5.0
4
+ version: 2.3.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: 2020-04-17 00:00:00.000000000 Z
11
+ date: 2020-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -140,6 +140,20 @@ dependencies:
140
140
  - - "~>"
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0.5'
143
+ - !ruby/object:Gem::Dependency
144
+ name: inflecto
145
+ requirement: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '0.0'
150
+ type: :runtime
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - "~>"
155
+ - !ruby/object:Gem::Version
156
+ version: '0.0'
143
157
  - !ruby/object:Gem::Dependency
144
158
  name: rake
145
159
  requirement: !ruby/object:Gem::Requirement
@@ -277,9 +291,20 @@ files:
277
291
  - lib/rasti-db.rb
278
292
  - lib/rasti/db.rb
279
293
  - lib/rasti/db/collection.rb
280
- - lib/rasti/db/helpers.rb
294
+ - lib/rasti/db/computed_attribute.rb
295
+ - lib/rasti/db/data_source.rb
296
+ - lib/rasti/db/environment.rb
281
297
  - lib/rasti/db/model.rb
298
+ - lib/rasti/db/nql/filter_condition_strategies/base.rb
299
+ - lib/rasti/db/nql/filter_condition_strategies/postgres.rb
300
+ - lib/rasti/db/nql/filter_condition_strategies/sqlite.rb
301
+ - lib/rasti/db/nql/filter_condition_strategies/types/generic.rb
302
+ - lib/rasti/db/nql/filter_condition_strategies/types/pg_array.rb
303
+ - lib/rasti/db/nql/filter_condition_strategies/types/sqlite_array.rb
304
+ - lib/rasti/db/nql/filter_condition_strategies/unsupported_type_comparison.rb
282
305
  - lib/rasti/db/nql/invalid_expression_error.rb
306
+ - lib/rasti/db/nql/nodes/array_content.rb
307
+ - lib/rasti/db/nql/nodes/attribute.rb
283
308
  - lib/rasti/db/nql/nodes/binary_node.rb
284
309
  - lib/rasti/db/nql/nodes/comparisons/base.rb
285
310
  - lib/rasti/db/nql/nodes/comparisons/equal.rb
@@ -292,6 +317,8 @@ files:
292
317
  - lib/rasti/db/nql/nodes/comparisons/not_equal.rb
293
318
  - lib/rasti/db/nql/nodes/comparisons/not_include.rb
294
319
  - lib/rasti/db/nql/nodes/conjunction.rb
320
+ - lib/rasti/db/nql/nodes/constants/array.rb
321
+ - lib/rasti/db/nql/nodes/constants/base.rb
295
322
  - lib/rasti/db/nql/nodes/constants/false.rb
296
323
  - lib/rasti/db/nql/nodes/constants/float.rb
297
324
  - lib/rasti/db/nql/nodes/constants/integer.rb
@@ -300,7 +327,6 @@ files:
300
327
  - lib/rasti/db/nql/nodes/constants/time.rb
301
328
  - lib/rasti/db/nql/nodes/constants/true.rb
302
329
  - lib/rasti/db/nql/nodes/disjunction.rb
303
- - lib/rasti/db/nql/nodes/field.rb
304
330
  - lib/rasti/db/nql/nodes/parenthesis_sentence.rb
305
331
  - lib/rasti/db/nql/nodes/sentence.rb
306
332
  - lib/rasti/db/nql/syntax.rb
@@ -317,19 +343,25 @@ files:
317
343
  - lib/rasti/db/type_converters/postgres_types/hstore.rb
318
344
  - lib/rasti/db/type_converters/postgres_types/json.rb
319
345
  - lib/rasti/db/type_converters/postgres_types/jsonb.rb
346
+ - lib/rasti/db/type_converters/sqlite.rb
347
+ - lib/rasti/db/type_converters/sqlite_types/array.rb
320
348
  - lib/rasti/db/type_converters/time_in_zone.rb
321
349
  - lib/rasti/db/version.rb
322
350
  - rasti-db.gemspec
323
351
  - spec/collection_spec.rb
352
+ - spec/computed_attribute_spec.rb
324
353
  - spec/coverage_helper.rb
325
354
  - spec/minitest_helper.rb
326
355
  - spec/model_spec.rb
356
+ - spec/nql/computed_attributes_spec.rb
327
357
  - spec/nql/dependency_tables_spec.rb
328
358
  - spec/nql/filter_condition_spec.rb
359
+ - spec/nql/filter_condition_strategies_spec.rb
329
360
  - spec/nql/syntax_parser_spec.rb
330
361
  - spec/query_spec.rb
331
362
  - spec/relations_spec.rb
332
363
  - spec/type_converters/postgres_spec.rb
364
+ - spec/type_converters/sqlite_spec.rb
333
365
  - spec/type_converters/time_in_zone_spec.rb
334
366
  homepage: https://github.com/gabynaiman/rasti-db
335
367
  licenses:
@@ -356,13 +388,17 @@ specification_version: 4
356
388
  summary: Database collections and relations
357
389
  test_files:
358
390
  - spec/collection_spec.rb
391
+ - spec/computed_attribute_spec.rb
359
392
  - spec/coverage_helper.rb
360
393
  - spec/minitest_helper.rb
361
394
  - spec/model_spec.rb
395
+ - spec/nql/computed_attributes_spec.rb
362
396
  - spec/nql/dependency_tables_spec.rb
363
397
  - spec/nql/filter_condition_spec.rb
398
+ - spec/nql/filter_condition_strategies_spec.rb
364
399
  - spec/nql/syntax_parser_spec.rb
365
400
  - spec/query_spec.rb
366
401
  - spec/relations_spec.rb
367
402
  - spec/type_converters/postgres_spec.rb
403
+ - spec/type_converters/sqlite_spec.rb
368
404
  - spec/type_converters/time_in_zone_spec.rb
@@ -1,16 +0,0 @@
1
- module Rasti
2
- module DB
3
- module Helpers
4
- module WithSchema
5
-
6
- private
7
-
8
- def with_schema(table, field=nil)
9
- qualified_table = schema ? Sequel[schema][table] : Sequel[table]
10
- field ? Sequel[qualified_table][field] : qualified_table
11
- end
12
-
13
- end
14
- end
15
- end
16
- end
@@ -1,23 +0,0 @@
1
- module Rasti
2
- module DB
3
- module NQL
4
- module Nodes
5
- class Field < Treetop::Runtime::SyntaxNode
6
-
7
- def identifier
8
- tables.empty? ? Sequel[column.to_sym] : Sequel[tables.join('__').to_sym][column.to_sym]
9
- end
10
-
11
- def tables
12
- _tables.elements.map{ |e| e.table.text_value }
13
- end
14
-
15
- def column
16
- _column.text_value
17
- end
18
-
19
- end
20
- end
21
- end
22
- end
23
- end