rasti-db 2.0.1 → 2.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -3
- data/lib/rasti/db.rb +11 -1
- data/lib/rasti/db/collection.rb +10 -1
- data/lib/rasti/db/computed_attribute.rb +22 -0
- 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/attribute.rb +37 -0
- data/lib/rasti/db/nql/nodes/binary_node.rb +4 -0
- data/lib/rasti/db/nql/nodes/comparisons/base.rb +15 -1
- 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/conjunction.rb +2 -2
- 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/disjunction.rb +2 -2
- data/lib/rasti/db/nql/nodes/parenthesis_sentence.rb +6 -2
- data/lib/rasti/db/nql/nodes/sentence.rb +6 -2
- data/lib/rasti/db/nql/syntax.rb +262 -44
- data/lib/rasti/db/nql/syntax.treetop +27 -14
- data/lib/rasti/db/query.rb +38 -8
- 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/version.rb +1 -1
- data/rasti-db.gemspec +1 -0
- data/spec/collection_spec.rb +8 -0
- data/spec/computed_attribute_spec.rb +32 -0
- data/spec/minitest_helper.rb +32 -5
- data/spec/model_spec.rb +1 -1
- data/spec/nql/computed_attributes_spec.rb +29 -0
- data/spec/nql/filter_condition_spec.rb +23 -4
- data/spec/nql/filter_condition_strategies_spec.rb +112 -0
- data/spec/nql/syntax_parser_spec.rb +36 -5
- data/spec/query_spec.rb +235 -34
- data/spec/type_converters/sqlite_spec.rb +66 -0
- metadata +38 -3
- data/lib/rasti/db/nql/nodes/field.rb +0 -23
@@ -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: 2.
|
4
|
+
version: 2.3.2
|
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-01 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,10 +291,20 @@ files:
|
|
277
291
|
- lib/rasti-db.rb
|
278
292
|
- lib/rasti/db.rb
|
279
293
|
- lib/rasti/db/collection.rb
|
294
|
+
- lib/rasti/db/computed_attribute.rb
|
280
295
|
- lib/rasti/db/data_source.rb
|
281
296
|
- lib/rasti/db/environment.rb
|
282
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
|
283
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
|
284
308
|
- lib/rasti/db/nql/nodes/binary_node.rb
|
285
309
|
- lib/rasti/db/nql/nodes/comparisons/base.rb
|
286
310
|
- lib/rasti/db/nql/nodes/comparisons/equal.rb
|
@@ -293,6 +317,8 @@ files:
|
|
293
317
|
- lib/rasti/db/nql/nodes/comparisons/not_equal.rb
|
294
318
|
- lib/rasti/db/nql/nodes/comparisons/not_include.rb
|
295
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
|
296
322
|
- lib/rasti/db/nql/nodes/constants/false.rb
|
297
323
|
- lib/rasti/db/nql/nodes/constants/float.rb
|
298
324
|
- lib/rasti/db/nql/nodes/constants/integer.rb
|
@@ -301,7 +327,6 @@ files:
|
|
301
327
|
- lib/rasti/db/nql/nodes/constants/time.rb
|
302
328
|
- lib/rasti/db/nql/nodes/constants/true.rb
|
303
329
|
- lib/rasti/db/nql/nodes/disjunction.rb
|
304
|
-
- lib/rasti/db/nql/nodes/field.rb
|
305
330
|
- lib/rasti/db/nql/nodes/parenthesis_sentence.rb
|
306
331
|
- lib/rasti/db/nql/nodes/sentence.rb
|
307
332
|
- lib/rasti/db/nql/syntax.rb
|
@@ -318,19 +343,25 @@ files:
|
|
318
343
|
- lib/rasti/db/type_converters/postgres_types/hstore.rb
|
319
344
|
- lib/rasti/db/type_converters/postgres_types/json.rb
|
320
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
|
321
348
|
- lib/rasti/db/type_converters/time_in_zone.rb
|
322
349
|
- lib/rasti/db/version.rb
|
323
350
|
- rasti-db.gemspec
|
324
351
|
- spec/collection_spec.rb
|
352
|
+
- spec/computed_attribute_spec.rb
|
325
353
|
- spec/coverage_helper.rb
|
326
354
|
- spec/minitest_helper.rb
|
327
355
|
- spec/model_spec.rb
|
356
|
+
- spec/nql/computed_attributes_spec.rb
|
328
357
|
- spec/nql/dependency_tables_spec.rb
|
329
358
|
- spec/nql/filter_condition_spec.rb
|
359
|
+
- spec/nql/filter_condition_strategies_spec.rb
|
330
360
|
- spec/nql/syntax_parser_spec.rb
|
331
361
|
- spec/query_spec.rb
|
332
362
|
- spec/relations_spec.rb
|
333
363
|
- spec/type_converters/postgres_spec.rb
|
364
|
+
- spec/type_converters/sqlite_spec.rb
|
334
365
|
- spec/type_converters/time_in_zone_spec.rb
|
335
366
|
homepage: https://github.com/gabynaiman/rasti-db
|
336
367
|
licenses:
|
@@ -357,13 +388,17 @@ specification_version: 4
|
|
357
388
|
summary: Database collections and relations
|
358
389
|
test_files:
|
359
390
|
- spec/collection_spec.rb
|
391
|
+
- spec/computed_attribute_spec.rb
|
360
392
|
- spec/coverage_helper.rb
|
361
393
|
- spec/minitest_helper.rb
|
362
394
|
- spec/model_spec.rb
|
395
|
+
- spec/nql/computed_attributes_spec.rb
|
363
396
|
- spec/nql/dependency_tables_spec.rb
|
364
397
|
- spec/nql/filter_condition_spec.rb
|
398
|
+
- spec/nql/filter_condition_strategies_spec.rb
|
365
399
|
- spec/nql/syntax_parser_spec.rb
|
366
400
|
- spec/query_spec.rb
|
367
401
|
- spec/relations_spec.rb
|
368
402
|
- spec/type_converters/postgres_spec.rb
|
403
|
+
- spec/type_converters/sqlite_spec.rb
|
369
404
|
- spec/type_converters/time_in_zone_spec.rb
|
@@ -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
|