rasti-db 2.2.0 → 3.0.0

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.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/lib/rasti/db.rb +16 -5
  4. data/lib/rasti/db/collection.rb +10 -10
  5. data/lib/rasti/db/data_source.rb +1 -1
  6. data/lib/rasti/db/model.rb +3 -104
  7. data/lib/rasti/db/nql/filter_condition_strategies/base.rb +17 -0
  8. data/lib/rasti/db/nql/filter_condition_strategies/postgres.rb +21 -0
  9. data/lib/rasti/db/nql/filter_condition_strategies/sqlite.rb +21 -0
  10. data/lib/rasti/db/nql/filter_condition_strategies/types/generic.rb +49 -0
  11. data/lib/rasti/db/nql/filter_condition_strategies/types/pg_array.rb +32 -0
  12. data/lib/rasti/db/nql/filter_condition_strategies/types/sqlite_array.rb +34 -0
  13. data/lib/rasti/db/nql/filter_condition_strategies/unsupported_type_comparison.rb +22 -0
  14. data/lib/rasti/db/nql/nodes/array_content.rb +21 -0
  15. data/lib/rasti/db/nql/nodes/binary_node.rb +1 -1
  16. data/lib/rasti/db/nql/nodes/comparisons/base.rb +10 -0
  17. data/lib/rasti/db/nql/nodes/comparisons/equal.rb +0 -4
  18. data/lib/rasti/db/nql/nodes/comparisons/greater_than.rb +0 -4
  19. data/lib/rasti/db/nql/nodes/comparisons/greater_than_or_equal.rb +0 -4
  20. data/lib/rasti/db/nql/nodes/comparisons/include.rb +0 -4
  21. data/lib/rasti/db/nql/nodes/comparisons/less_than.rb +0 -4
  22. data/lib/rasti/db/nql/nodes/comparisons/less_than_or_equal.rb +0 -4
  23. data/lib/rasti/db/nql/nodes/comparisons/like.rb +0 -4
  24. data/lib/rasti/db/nql/nodes/comparisons/not_equal.rb +0 -4
  25. data/lib/rasti/db/nql/nodes/comparisons/not_include.rb +0 -4
  26. data/lib/rasti/db/nql/nodes/constants/array.rb +17 -0
  27. data/lib/rasti/db/nql/nodes/constants/base.rb +17 -0
  28. data/lib/rasti/db/nql/nodes/constants/false.rb +1 -1
  29. data/lib/rasti/db/nql/nodes/constants/float.rb +1 -1
  30. data/lib/rasti/db/nql/nodes/constants/integer.rb +1 -1
  31. data/lib/rasti/db/nql/nodes/constants/literal_string.rb +1 -1
  32. data/lib/rasti/db/nql/nodes/constants/string.rb +1 -1
  33. data/lib/rasti/db/nql/nodes/constants/time.rb +1 -1
  34. data/lib/rasti/db/nql/nodes/constants/true.rb +1 -1
  35. data/lib/rasti/db/nql/nodes/parenthesis_sentence.rb +1 -1
  36. data/lib/rasti/db/nql/syntax.rb +229 -11
  37. data/lib/rasti/db/nql/syntax.treetop +24 -11
  38. data/lib/rasti/db/relations/base.rb +3 -3
  39. data/lib/rasti/db/relations/graph.rb +15 -15
  40. data/lib/rasti/db/relations/many_to_many.rb +4 -4
  41. data/lib/rasti/db/relations/many_to_one.rb +4 -4
  42. data/lib/rasti/db/relations/one_to_many.rb +2 -2
  43. data/lib/rasti/db/type_converters/postgres.rb +32 -36
  44. data/lib/rasti/db/type_converters/postgres_types/array.rb +11 -9
  45. data/lib/rasti/db/type_converters/postgres_types/hstore.rb +10 -9
  46. data/lib/rasti/db/type_converters/postgres_types/json.rb +17 -14
  47. data/lib/rasti/db/type_converters/postgres_types/jsonb.rb +17 -14
  48. data/lib/rasti/db/type_converters/sqlite.rb +62 -0
  49. data/lib/rasti/db/type_converters/sqlite_types/array.rb +34 -0
  50. data/lib/rasti/db/type_converters/time_in_zone.rb +1 -1
  51. data/lib/rasti/db/version.rb +1 -1
  52. data/rasti-db.gemspec +2 -0
  53. data/spec/collection_spec.rb +36 -28
  54. data/spec/minitest_helper.rb +4 -2
  55. data/spec/nql/filter_condition_spec.rb +19 -2
  56. data/spec/nql/filter_condition_strategies_spec.rb +112 -0
  57. data/spec/nql/syntax_parser_spec.rb +24 -0
  58. data/spec/query_spec.rb +89 -0
  59. data/spec/relations_spec.rb +17 -17
  60. data/spec/type_converters/sqlite_spec.rb +66 -0
  61. data/spec/type_converters/time_in_zone_spec.rb +1 -1
  62. metadata +46 -4
  63. data/spec/model_spec.rb +0 -90
data/spec/model_spec.rb DELETED
@@ -1,90 +0,0 @@
1
- require 'minitest_helper'
2
-
3
- describe 'Model' do
4
-
5
- describe 'Attribues' do
6
-
7
- it 'Valid definition' do
8
- model = Rasti::DB::Model[:id, :name]
9
- model.attributes.must_equal [:id, :name]
10
- end
11
-
12
- it 'Invalid definition' do
13
- error = proc { Rasti::DB::Model[:id, :name, :name] }.must_raise ArgumentError
14
- error.message.must_equal 'Attribute name already exists'
15
- end
16
-
17
- it 'Accessors' do
18
- post = Post.new id: 1, title: 'Title'
19
-
20
- post.id.must_equal 1
21
- post.title.must_equal 'Title'
22
-
23
- [:body, :user, :comments].each do |attribute|
24
- error = proc { post.send attribute }.must_raise Rasti::DB::Model::UninitializedAttributeError
25
- error.message.must_equal "Uninitialized attribute #{attribute}"
26
- end
27
-
28
- proc { post.invalid_method }.must_raise NoMethodError
29
- end
30
-
31
- end
32
-
33
-
34
- it 'Inheritance' do
35
- subclass = Class.new(User) do
36
- attribute :additional_attribute
37
- end
38
-
39
- subclass.attributes.must_equal (User.attributes + [:additional_attribute])
40
- end
41
-
42
- describe 'To String' do
43
-
44
- it 'Class' do
45
- User.to_s.must_equal 'User[id, name, posts, comments, person, comments_count]'
46
- end
47
-
48
- it 'Instance' do
49
- user = User.new id: 1, name: 'User 1'
50
- user.to_s.must_equal '#<User[id: 1, name: "User 1"]>'
51
- end
52
-
53
- end
54
-
55
- it 'To Hash' do
56
- post = Post.new id: 2,
57
- title: 'Title',
58
- body: 'body',
59
- user_id: 1,
60
- user: User.new(id: 1, name: 'User 1'),
61
- comments: [Comment.new(id: 4, text: 'comment text', user_id: 5)]
62
-
63
- post.to_h.must_equal id: 2,
64
- title: 'Title',
65
- body: 'body',
66
- user_id: 1,
67
- user: {id: 1, name: 'User 1'},
68
- comments: [{id: 4, text: 'comment text', user_id: 5}]
69
- end
70
-
71
- it 'Equality' do
72
- assert User.new(id: 1, name: 'User 1') == User.new(id: 1, name: 'User 1')
73
- refute User.new(id: 1, name: 'User 1') == User.new(id: 2, name: 'User 2')
74
-
75
- assert User.new(id: 1, name: 'User 1').eql? User.new(id: 1, name: 'User 1')
76
- refute User.new(id: 1, name: 'User 1').eql? User.new(id: 2, name: 'User 2')
77
-
78
- assert_equal User.new(id: 1, name: 'User 1').hash, User.new(id: 1, name: 'User 1').hash
79
- refute_equal User.new(id: 1, name: 'User 1').hash, User.new(id: 2, name: 'User 2').hash
80
- end
81
-
82
- it 'Merge' do
83
- user = User.new(id: 1, name: 'User 1')
84
- changed_user = user.merge(name: 'User 2')
85
-
86
- user.must_equal User.new(id: 1, name: 'User 1')
87
- changed_user.must_equal User.new(id: 1, name: 'User 2')
88
- end
89
-
90
- end