rasti-db 2.2.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/lib/rasti/db.rb +16 -5
- data/lib/rasti/db/collection.rb +10 -10
- data/lib/rasti/db/data_source.rb +1 -1
- data/lib/rasti/db/model.rb +3 -104
- data/lib/rasti/db/nql/filter_condition_strategies/base.rb +17 -0
- data/lib/rasti/db/nql/filter_condition_strategies/postgres.rb +21 -0
- data/lib/rasti/db/nql/filter_condition_strategies/sqlite.rb +21 -0
- data/lib/rasti/db/nql/filter_condition_strategies/types/generic.rb +49 -0
- data/lib/rasti/db/nql/filter_condition_strategies/types/pg_array.rb +32 -0
- data/lib/rasti/db/nql/filter_condition_strategies/types/sqlite_array.rb +34 -0
- data/lib/rasti/db/nql/filter_condition_strategies/unsupported_type_comparison.rb +22 -0
- data/lib/rasti/db/nql/nodes/array_content.rb +21 -0
- data/lib/rasti/db/nql/nodes/binary_node.rb +1 -1
- data/lib/rasti/db/nql/nodes/comparisons/base.rb +10 -0
- data/lib/rasti/db/nql/nodes/comparisons/equal.rb +0 -4
- data/lib/rasti/db/nql/nodes/comparisons/greater_than.rb +0 -4
- data/lib/rasti/db/nql/nodes/comparisons/greater_than_or_equal.rb +0 -4
- data/lib/rasti/db/nql/nodes/comparisons/include.rb +0 -4
- data/lib/rasti/db/nql/nodes/comparisons/less_than.rb +0 -4
- data/lib/rasti/db/nql/nodes/comparisons/less_than_or_equal.rb +0 -4
- data/lib/rasti/db/nql/nodes/comparisons/like.rb +0 -4
- data/lib/rasti/db/nql/nodes/comparisons/not_equal.rb +0 -4
- data/lib/rasti/db/nql/nodes/comparisons/not_include.rb +0 -4
- data/lib/rasti/db/nql/nodes/constants/array.rb +17 -0
- data/lib/rasti/db/nql/nodes/constants/base.rb +17 -0
- data/lib/rasti/db/nql/nodes/constants/false.rb +1 -1
- data/lib/rasti/db/nql/nodes/constants/float.rb +1 -1
- data/lib/rasti/db/nql/nodes/constants/integer.rb +1 -1
- data/lib/rasti/db/nql/nodes/constants/literal_string.rb +1 -1
- data/lib/rasti/db/nql/nodes/constants/string.rb +1 -1
- data/lib/rasti/db/nql/nodes/constants/time.rb +1 -1
- data/lib/rasti/db/nql/nodes/constants/true.rb +1 -1
- data/lib/rasti/db/nql/nodes/parenthesis_sentence.rb +1 -1
- data/lib/rasti/db/nql/syntax.rb +229 -11
- data/lib/rasti/db/nql/syntax.treetop +24 -11
- data/lib/rasti/db/relations/base.rb +3 -3
- data/lib/rasti/db/relations/graph.rb +15 -15
- data/lib/rasti/db/relations/many_to_many.rb +4 -4
- data/lib/rasti/db/relations/many_to_one.rb +4 -4
- data/lib/rasti/db/relations/one_to_many.rb +2 -2
- data/lib/rasti/db/type_converters/postgres.rb +32 -36
- data/lib/rasti/db/type_converters/postgres_types/array.rb +11 -9
- data/lib/rasti/db/type_converters/postgres_types/hstore.rb +10 -9
- data/lib/rasti/db/type_converters/postgres_types/json.rb +17 -14
- data/lib/rasti/db/type_converters/postgres_types/jsonb.rb +17 -14
- data/lib/rasti/db/type_converters/sqlite.rb +62 -0
- data/lib/rasti/db/type_converters/sqlite_types/array.rb +34 -0
- data/lib/rasti/db/type_converters/time_in_zone.rb +1 -1
- data/lib/rasti/db/version.rb +1 -1
- data/rasti-db.gemspec +2 -0
- data/spec/collection_spec.rb +36 -28
- data/spec/minitest_helper.rb +4 -2
- data/spec/nql/filter_condition_spec.rb +19 -2
- data/spec/nql/filter_condition_strategies_spec.rb +112 -0
- data/spec/nql/syntax_parser_spec.rb +24 -0
- data/spec/query_spec.rb +89 -0
- data/spec/relations_spec.rb +17 -17
- data/spec/type_converters/sqlite_spec.rb +66 -0
- data/spec/type_converters/time_in_zone_spec.rb +1 -1
- metadata +46 -4
- data/spec/model_spec.rb +0 -90
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
describe 'NQL::FilterConditionStrategies' do
|
4
|
+
|
5
|
+
let(:comments_query) { Rasti::DB::Query.new collection_class: Comments, dataset: db[:comments], environment: environment }
|
6
|
+
|
7
|
+
def sqls_where(query)
|
8
|
+
"#<Rasti::DB::Query: \"SELECT `comments`.* FROM `comments` WHERE (#{query})\">"
|
9
|
+
end
|
10
|
+
|
11
|
+
def sqls_where_not(query)
|
12
|
+
"#<Rasti::DB::Query: \"SELECT `comments`.* FROM `comments` WHERE NOT (#{query})\">"
|
13
|
+
end
|
14
|
+
|
15
|
+
def nql_s(nql_query)
|
16
|
+
comments_query.nql(nql_query).to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'Generic' do
|
20
|
+
|
21
|
+
it 'Equal' do
|
22
|
+
nql_s('text = hola').must_equal sqls_where("`comments`.`text` = 'hola'")
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'Not Equal' do
|
26
|
+
nql_s('text != hola').must_equal sqls_where("`comments`.`text` != 'hola'")
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'Greather Than' do
|
30
|
+
nql_s('id > 1').must_equal sqls_where("`comments`.`id` > 1")
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'Greather Than or Equal' do
|
34
|
+
nql_s('id >= 1').must_equal sqls_where("`comments`.`id` >= 1")
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'Less Than' do
|
38
|
+
nql_s('id < 1').must_equal sqls_where("`comments`.`id` < 1")
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'Less Than or Equal' do
|
42
|
+
nql_s('id <= 1').must_equal sqls_where("`comments`.`id` <= 1")
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'Like' do
|
46
|
+
nql_s('text ~ hola').must_equal sqls_where("UPPER(`comments`.`text`) LIKE UPPER('hola') ESCAPE '\\'")
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'Include' do
|
50
|
+
nql_s('text: hola').must_equal sqls_where("UPPER(`comments`.`text`) LIKE UPPER('%hola%') ESCAPE '\\'")
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'Not Include' do
|
54
|
+
nql_s('text!: hola').must_equal sqls_where_not("UPPER(`comments`.`text`) LIKE UPPER('%hola%') ESCAPE '\\'")
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'SQLite Array' do
|
60
|
+
|
61
|
+
it 'Equal' do
|
62
|
+
nql_s('tags = [notice]').must_equal sqls_where("`comments`.`tags` = '[\"notice\"]'")
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'Not Equal' do
|
66
|
+
nql_s('tags != [notice]').must_equal sqls_where_not("`comments`.`tags` LIKE '%\"notice\"%' ESCAPE '\\'")
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'Like' do
|
70
|
+
nql_s('tags ~ [notice]').must_equal sqls_where("`comments`.`tags` LIKE '%notice%' ESCAPE '\\'")
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'Include' do
|
74
|
+
nql_s('tags: [notice]').must_equal sqls_where("`comments`.`tags` LIKE '%\"notice\"%' ESCAPE '\\'")
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'Not Include' do
|
78
|
+
nql_s('tags!: [notice]').must_equal sqls_where_not("`comments`.`tags` LIKE '%\"notice\"%' ESCAPE '\\'")
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
describe 'Postgres Array' do
|
84
|
+
|
85
|
+
before do
|
86
|
+
Rasti::DB.nql_filter_condition_strategy = Rasti::DB::NQL::FilterConditionStrategies::Postgres.new
|
87
|
+
Sequel.extension :pg_array_ops
|
88
|
+
end
|
89
|
+
|
90
|
+
after do
|
91
|
+
Rasti::DB.nql_filter_condition_strategy = Rasti::DB::NQL::FilterConditionStrategies::SQLite.new
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'Equal' do
|
95
|
+
nql_s('tags = [notice]').must_equal sqls_where("(`comments`.`tags` @> ARRAY['notice']) AND (`comments`.`tags` <@ ARRAY['notice'])")
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'Not Equal' do
|
99
|
+
nql_s('tags != [notice]').must_equal sqls_where("NOT (`comments`.`tags` @> ARRAY['notice']) OR NOT (`comments`.`tags` <@ ARRAY['notice'])")
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'Include' do
|
103
|
+
nql_s('tags: [notice]').must_equal sqls_where("`comments`.`tags` && ARRAY['notice']")
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'Not Include' do
|
107
|
+
nql_s('tags!: [notice]').must_equal sqls_where_not("`comments`.`tags` && ARRAY['notice']")
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
@@ -213,4 +213,28 @@ describe 'NQL::SyntaxParser' do
|
|
213
213
|
|
214
214
|
end
|
215
215
|
|
216
|
+
describe 'Array' do
|
217
|
+
|
218
|
+
it 'must parse array with one element' do
|
219
|
+
tree = parse 'column = [ a ]'
|
220
|
+
tree.proposition.argument.value.must_equal ['a']
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'must parse array with many elements' do
|
224
|
+
tree = parse 'column = [ a, b, c ]'
|
225
|
+
tree.proposition.argument.value.must_equal ['a', 'b', 'c']
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'must parse array respecting content types' do
|
229
|
+
tree = parse 'column = [ true, 12:00, 1.1, 1, "literal string", string ]'
|
230
|
+
tree.proposition.argument.value.must_equal [true, Timing::TimeInZone.parse('12:00').to_s, 1.1, 1, "literal string", 'string']
|
231
|
+
end
|
232
|
+
|
233
|
+
it 'must parse array with literal string allowing reserved characters in conflict with array' do
|
234
|
+
tree = parse 'column = [ ",", "[", "]", "[,", "],", "[,]", "simple literal" ]'
|
235
|
+
tree.proposition.argument.value.must_equal [ ',', '[', ']', '[,', '],', '[,]', 'simple literal' ]
|
236
|
+
end
|
237
|
+
|
238
|
+
end
|
239
|
+
|
216
240
|
end
|
data/spec/query_spec.rb
CHANGED
@@ -462,6 +462,95 @@ describe 'Query' do
|
|
462
462
|
|
463
463
|
end
|
464
464
|
|
465
|
+
describe 'Filter Array' do
|
466
|
+
|
467
|
+
def filter_condition_must_raise(comparison_symbol, comparison_name)
|
468
|
+
error = proc { comments_query.nql("tags #{comparison_symbol} [fake, notice]") }.must_raise Rasti::DB::NQL::FilterConditionStrategies::UnsupportedTypeComparison
|
469
|
+
error.argument_type.must_equal Rasti::DB::NQL::FilterConditionStrategies::Types::SQLiteArray
|
470
|
+
error.comparison_name.must_equal comparison_name
|
471
|
+
error.message.must_equal "Unsupported comparison #{comparison_name} for Rasti::DB::NQL::FilterConditionStrategies::Types::SQLiteArray"
|
472
|
+
end
|
473
|
+
|
474
|
+
it 'Must raise exception from not supported methods' do
|
475
|
+
comparisons = {
|
476
|
+
greater_than: '>',
|
477
|
+
greater_than_or_equal: '>=',
|
478
|
+
less_than: '<',
|
479
|
+
less_than_or_equal: '<='
|
480
|
+
}
|
481
|
+
|
482
|
+
comparisons.each do |name, symbol|
|
483
|
+
filter_condition_must_raise symbol, name
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
487
|
+
it 'Included any of these elements' do
|
488
|
+
db[:comments].insert post_id: 1, user_id: 5, text: 'fake notice', tags: '["fake","notice"]'
|
489
|
+
db[:comments].insert post_id: 1, user_id: 5, text: 'fake notice 2', tags: '["notice"]'
|
490
|
+
db[:comments].insert post_id: 1, user_id: 5, text: 'fake notice 3', tags: '["fake_notice"]'
|
491
|
+
expected_comments = [
|
492
|
+
Comment.new(id: 4, text: 'fake notice', tags: ['fake','notice'], user_id: 5, post_id: 1),
|
493
|
+
Comment.new(id: 5, text: 'fake notice 2', tags: ['notice'], user_id: 5, post_id: 1)
|
494
|
+
]
|
495
|
+
|
496
|
+
comments_query.nql('tags: [ fake, notice ]')
|
497
|
+
.all
|
498
|
+
.must_equal expected_comments
|
499
|
+
end
|
500
|
+
|
501
|
+
it 'Included exactly all these elements' do
|
502
|
+
db[:comments].insert post_id: 1, user_id: 5, text: 'fake notice', tags: '["fake","notice"]'
|
503
|
+
db[:comments].insert post_id: 1, user_id: 5, text: 'fake notice 2', tags: '["notice"]'
|
504
|
+
comments_query.nql('tags = [fake, notice]')
|
505
|
+
.all
|
506
|
+
.must_equal [Comment.new(id: 4, text: 'fake notice', tags: ['fake','notice'], user_id: 5, post_id: 1)]
|
507
|
+
end
|
508
|
+
|
509
|
+
it 'Not included anyone of these elements' do
|
510
|
+
db[:comments].insert post_id: 1, user_id: 5, text: 'fake notice', tags: '["fake","notice"]'
|
511
|
+
db[:comments].insert post_id: 1, user_id: 5, text: 'Good notice!', tags: '["good"]'
|
512
|
+
db[:comments].insert post_id: 1, user_id: 5, text: 'fake notice', tags: '["fake"]'
|
513
|
+
expected_comments = [
|
514
|
+
Comment.new(id: 1, text: 'Comment 1', tags: [], user_id: 5, post_id: 1),
|
515
|
+
Comment.new(id: 2, text: 'Comment 2', tags: [], user_id: 7, post_id: 1),
|
516
|
+
Comment.new(id: 3, text: 'Comment 3', tags: [], user_id: 2, post_id: 2),
|
517
|
+
Comment.new(id: 5, text: 'Good notice!', tags: ['good'], user_id: 5, post_id: 1)
|
518
|
+
]
|
519
|
+
comments_query.nql('tags !: [fake, notice]')
|
520
|
+
.all
|
521
|
+
.must_equal expected_comments
|
522
|
+
end
|
523
|
+
|
524
|
+
it 'Not include any of these elements' do
|
525
|
+
db[:comments].insert post_id: 1, user_id: 5, text: 'fake notice', tags: '["fake","notice"]'
|
526
|
+
db[:comments].insert post_id: 1, user_id: 5, text: 'Good notice!', tags: '["good"]'
|
527
|
+
db[:comments].insert post_id: 1, user_id: 5, text: 'fake notice', tags: '["fake"]'
|
528
|
+
expected_comments = [
|
529
|
+
Comment.new(id: 1, text: 'Comment 1', tags: '[]', user_id: 5, post_id: 1),
|
530
|
+
Comment.new(id: 2, text: 'Comment 2', tags: '[]', user_id: 7, post_id: 1),
|
531
|
+
Comment.new(id: 3, text: 'Comment 3', tags: '[]', user_id: 2, post_id: 2),
|
532
|
+
Comment.new(id: 5, text: 'Good notice!', tags: ['good'], user_id: 5, post_id: 1),
|
533
|
+
Comment.new(id: 6, text: 'fake notice', tags: ['fake'], user_id: 5, post_id: 1)
|
534
|
+
]
|
535
|
+
comments_query.nql('tags != [fake, notice]')
|
536
|
+
.all
|
537
|
+
.must_equal expected_comments
|
538
|
+
end
|
539
|
+
|
540
|
+
it 'Include any like these elements' do
|
541
|
+
db[:comments].insert post_id: 1, user_id: 5, text: 'fake notice', tags: '["fake","notice"]'
|
542
|
+
db[:comments].insert post_id: 1, user_id: 5, text: 'this is a fake notice!', tags: '["fake_notice"]'
|
543
|
+
expected_comments = [
|
544
|
+
Comment.new(id: 4, text: 'fake notice', tags: ['fake','notice'], user_id: 5, post_id: 1),
|
545
|
+
Comment.new(id: 5, text: 'this is a fake notice!', tags: ['fake_notice'], user_id: 5, post_id: 1)
|
546
|
+
]
|
547
|
+
comments_query.nql('tags ~ [fake]')
|
548
|
+
.all
|
549
|
+
.must_equal expected_comments
|
550
|
+
end
|
551
|
+
|
552
|
+
end
|
553
|
+
|
465
554
|
end
|
466
555
|
|
467
556
|
end
|
data/spec/relations_spec.rb
CHANGED
@@ -8,15 +8,15 @@ describe 'Relations' do
|
|
8
8
|
|
9
9
|
it 'Implicit' do
|
10
10
|
relation = Rasti::DB::Relations::OneToMany.new :posts, Users
|
11
|
-
|
11
|
+
|
12
12
|
relation.target_collection_class.must_equal Posts
|
13
13
|
relation.foreign_key.must_equal :user_id
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'Explicit' do
|
17
|
-
relation = Rasti::DB::Relations::OneToMany.new :articles, Users, collection: 'Posts',
|
17
|
+
relation = Rasti::DB::Relations::OneToMany.new :articles, Users, collection: 'Posts',
|
18
18
|
foreign_key: :id_user
|
19
|
-
|
19
|
+
|
20
20
|
relation.target_collection_class.must_equal Posts
|
21
21
|
relation.foreign_key.must_equal :id_user
|
22
22
|
end
|
@@ -41,9 +41,9 @@ describe 'Relations' do
|
|
41
41
|
user_id = db[:users].insert name: 'User 1'
|
42
42
|
1.upto(2) { |i| db[:posts].insert user_id: user_id, title: "Post #{i}", body: '...', language_id: 1 }
|
43
43
|
rows = db[:users].all
|
44
|
-
|
44
|
+
|
45
45
|
Users.relations[:posts].fetch_graph environment, rows
|
46
|
-
|
46
|
+
|
47
47
|
rows[0][:posts].must_equal posts.where(user_id: user_id).all
|
48
48
|
end
|
49
49
|
|
@@ -55,15 +55,15 @@ describe 'Relations' do
|
|
55
55
|
|
56
56
|
it 'Implicit' do
|
57
57
|
relation = Rasti::DB::Relations::ManyToOne.new :user, Posts
|
58
|
-
|
58
|
+
|
59
59
|
relation.target_collection_class.must_equal Users
|
60
60
|
relation.foreign_key.must_equal :user_id
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'Explicit' do
|
64
|
-
relation = Rasti::DB::Relations::ManyToOne.new :publisher, Posts, collection: 'Users',
|
64
|
+
relation = Rasti::DB::Relations::ManyToOne.new :publisher, Posts, collection: 'Users',
|
65
65
|
foreign_key: :publisher_id
|
66
|
-
|
66
|
+
|
67
67
|
relation.target_collection_class.must_equal Users
|
68
68
|
relation.foreign_key.must_equal :publisher_id
|
69
69
|
end
|
@@ -102,7 +102,7 @@ describe 'Relations' do
|
|
102
102
|
|
103
103
|
it 'Implicit' do
|
104
104
|
relation = Rasti::DB::Relations::ManyToMany.new :categories, Posts
|
105
|
-
|
105
|
+
|
106
106
|
relation.target_collection_class.must_equal Categories
|
107
107
|
relation.source_foreign_key.must_equal :post_id
|
108
108
|
relation.target_foreign_key.must_equal :category_id
|
@@ -110,11 +110,11 @@ describe 'Relations' do
|
|
110
110
|
end
|
111
111
|
|
112
112
|
it 'Explicit' do
|
113
|
-
relation = Rasti::DB::Relations::ManyToMany.new :tags, Posts, collection: 'Categories',
|
114
|
-
source_foreign_key: :article_id,
|
115
|
-
target_foreign_key: :tag_id,
|
113
|
+
relation = Rasti::DB::Relations::ManyToMany.new :tags, Posts, collection: 'Categories',
|
114
|
+
source_foreign_key: :article_id,
|
115
|
+
target_foreign_key: :tag_id,
|
116
116
|
relation_collection_name: :tags_articles
|
117
|
-
|
117
|
+
|
118
118
|
relation.target_collection_class.must_equal Categories
|
119
119
|
relation.source_foreign_key.must_equal :article_id
|
120
120
|
relation.target_foreign_key.must_equal :tag_id
|
@@ -165,15 +165,15 @@ describe 'Relations' do
|
|
165
165
|
|
166
166
|
it 'Implicit' do
|
167
167
|
relation = Rasti::DB::Relations::OneToOne.new :person, Users
|
168
|
-
|
168
|
+
|
169
169
|
relation.target_collection_class.must_equal People
|
170
170
|
relation.foreign_key.must_equal :user_id
|
171
171
|
end
|
172
172
|
|
173
173
|
it 'Explicit' do
|
174
|
-
relation = Rasti::DB::Relations::OneToOne.new :person, Users, collection: 'Users',
|
174
|
+
relation = Rasti::DB::Relations::OneToOne.new :person, Users, collection: 'Users',
|
175
175
|
foreign_key: :id_user
|
176
|
-
|
176
|
+
|
177
177
|
relation.target_collection_class.must_equal Users
|
178
178
|
relation.foreign_key.must_equal :id_user
|
179
179
|
end
|
@@ -197,7 +197,7 @@ describe 'Relations' do
|
|
197
197
|
it 'Graph' do
|
198
198
|
2.times do |i|
|
199
199
|
user_id = db[:users].insert name: "User #{i}"
|
200
|
-
db[:people].insert document_number: "document_#{i}",
|
200
|
+
db[:people].insert document_number: "document_#{i}",
|
201
201
|
first_name: "John #{i}",
|
202
202
|
last_name: "Doe #{i}",
|
203
203
|
birth_date: Time.now - 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:
|
4
|
+
version: 3.0.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:
|
11
|
+
date: 2021-03-11 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: rasti-model
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: treetop
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,6 +154,20 @@ dependencies:
|
|
140
154
|
- - "~>"
|
141
155
|
- !ruby/object:Gem::Version
|
142
156
|
version: '0.5'
|
157
|
+
- !ruby/object:Gem::Dependency
|
158
|
+
name: inflecto
|
159
|
+
requirement: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - "~>"
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0.0'
|
164
|
+
type: :runtime
|
165
|
+
prerelease: false
|
166
|
+
version_requirements: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - "~>"
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0.0'
|
143
171
|
- !ruby/object:Gem::Dependency
|
144
172
|
name: rake
|
145
173
|
requirement: !ruby/object:Gem::Requirement
|
@@ -281,7 +309,15 @@ files:
|
|
281
309
|
- lib/rasti/db/data_source.rb
|
282
310
|
- lib/rasti/db/environment.rb
|
283
311
|
- lib/rasti/db/model.rb
|
312
|
+
- lib/rasti/db/nql/filter_condition_strategies/base.rb
|
313
|
+
- lib/rasti/db/nql/filter_condition_strategies/postgres.rb
|
314
|
+
- lib/rasti/db/nql/filter_condition_strategies/sqlite.rb
|
315
|
+
- lib/rasti/db/nql/filter_condition_strategies/types/generic.rb
|
316
|
+
- lib/rasti/db/nql/filter_condition_strategies/types/pg_array.rb
|
317
|
+
- lib/rasti/db/nql/filter_condition_strategies/types/sqlite_array.rb
|
318
|
+
- lib/rasti/db/nql/filter_condition_strategies/unsupported_type_comparison.rb
|
284
319
|
- lib/rasti/db/nql/invalid_expression_error.rb
|
320
|
+
- lib/rasti/db/nql/nodes/array_content.rb
|
285
321
|
- lib/rasti/db/nql/nodes/attribute.rb
|
286
322
|
- lib/rasti/db/nql/nodes/binary_node.rb
|
287
323
|
- lib/rasti/db/nql/nodes/comparisons/base.rb
|
@@ -295,6 +331,8 @@ files:
|
|
295
331
|
- lib/rasti/db/nql/nodes/comparisons/not_equal.rb
|
296
332
|
- lib/rasti/db/nql/nodes/comparisons/not_include.rb
|
297
333
|
- lib/rasti/db/nql/nodes/conjunction.rb
|
334
|
+
- lib/rasti/db/nql/nodes/constants/array.rb
|
335
|
+
- lib/rasti/db/nql/nodes/constants/base.rb
|
298
336
|
- lib/rasti/db/nql/nodes/constants/false.rb
|
299
337
|
- lib/rasti/db/nql/nodes/constants/float.rb
|
300
338
|
- lib/rasti/db/nql/nodes/constants/integer.rb
|
@@ -319,6 +357,8 @@ files:
|
|
319
357
|
- lib/rasti/db/type_converters/postgres_types/hstore.rb
|
320
358
|
- lib/rasti/db/type_converters/postgres_types/json.rb
|
321
359
|
- lib/rasti/db/type_converters/postgres_types/jsonb.rb
|
360
|
+
- lib/rasti/db/type_converters/sqlite.rb
|
361
|
+
- lib/rasti/db/type_converters/sqlite_types/array.rb
|
322
362
|
- lib/rasti/db/type_converters/time_in_zone.rb
|
323
363
|
- lib/rasti/db/version.rb
|
324
364
|
- rasti-db.gemspec
|
@@ -326,14 +366,15 @@ files:
|
|
326
366
|
- spec/computed_attribute_spec.rb
|
327
367
|
- spec/coverage_helper.rb
|
328
368
|
- spec/minitest_helper.rb
|
329
|
-
- spec/model_spec.rb
|
330
369
|
- spec/nql/computed_attributes_spec.rb
|
331
370
|
- spec/nql/dependency_tables_spec.rb
|
332
371
|
- spec/nql/filter_condition_spec.rb
|
372
|
+
- spec/nql/filter_condition_strategies_spec.rb
|
333
373
|
- spec/nql/syntax_parser_spec.rb
|
334
374
|
- spec/query_spec.rb
|
335
375
|
- spec/relations_spec.rb
|
336
376
|
- spec/type_converters/postgres_spec.rb
|
377
|
+
- spec/type_converters/sqlite_spec.rb
|
337
378
|
- spec/type_converters/time_in_zone_spec.rb
|
338
379
|
homepage: https://github.com/gabynaiman/rasti-db
|
339
380
|
licenses:
|
@@ -363,12 +404,13 @@ test_files:
|
|
363
404
|
- spec/computed_attribute_spec.rb
|
364
405
|
- spec/coverage_helper.rb
|
365
406
|
- spec/minitest_helper.rb
|
366
|
-
- spec/model_spec.rb
|
367
407
|
- spec/nql/computed_attributes_spec.rb
|
368
408
|
- spec/nql/dependency_tables_spec.rb
|
369
409
|
- spec/nql/filter_condition_spec.rb
|
410
|
+
- spec/nql/filter_condition_strategies_spec.rb
|
370
411
|
- spec/nql/syntax_parser_spec.rb
|
371
412
|
- spec/query_spec.rb
|
372
413
|
- spec/relations_spec.rb
|
373
414
|
- spec/type_converters/postgres_spec.rb
|
415
|
+
- spec/type_converters/sqlite_spec.rb
|
374
416
|
- spec/type_converters/time_in_zone_spec.rb
|