rom-sql 2.0.0.beta2 → 2.0.0.beta3

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 (170) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +66 -0
  3. data/lib/rom/plugins/relation/sql/postgres/explain.rb +54 -0
  4. data/lib/rom/sql.rb +1 -1
  5. data/lib/rom/sql/attribute.rb +17 -18
  6. data/lib/rom/sql/errors.rb +3 -0
  7. data/lib/rom/sql/extensions/mysql.rb +1 -1
  8. data/lib/rom/sql/extensions/mysql/type_builder.rb +28 -0
  9. data/lib/rom/sql/extensions/postgres.rb +3 -1
  10. data/lib/rom/sql/extensions/postgres/commands.rb +30 -13
  11. data/lib/rom/sql/extensions/postgres/{attributes_inferrer.rb → type_builder.rb} +24 -28
  12. data/lib/rom/sql/extensions/postgres/type_serializer.rb +39 -0
  13. data/lib/rom/sql/extensions/postgres/types.rb +24 -477
  14. data/lib/rom/sql/extensions/postgres/types/array.rb +163 -0
  15. data/lib/rom/sql/extensions/postgres/types/geometric.rb +135 -0
  16. data/lib/rom/sql/extensions/postgres/types/json.rb +235 -0
  17. data/lib/rom/sql/extensions/postgres/types/network.rb +15 -0
  18. data/lib/rom/sql/extensions/sqlite.rb +1 -1
  19. data/lib/rom/sql/extensions/sqlite/{attributes_inferrer.rb → type_builder.rb} +5 -5
  20. data/lib/rom/sql/extensions/sqlite/types.rb +8 -3
  21. data/lib/rom/sql/foreign_key.rb +17 -0
  22. data/lib/rom/sql/function.rb +86 -8
  23. data/lib/rom/sql/gateway.rb +26 -26
  24. data/lib/rom/sql/index.rb +4 -0
  25. data/lib/rom/sql/migration.rb +3 -3
  26. data/lib/rom/sql/migration/inline_runner.rb +9 -83
  27. data/lib/rom/sql/migration/migrator.rb +35 -12
  28. data/lib/rom/sql/migration/recorder.rb +21 -0
  29. data/lib/rom/sql/migration/runner.rb +115 -0
  30. data/lib/rom/sql/migration/schema_diff.rb +108 -53
  31. data/lib/rom/sql/migration/writer.rb +61 -0
  32. data/lib/rom/sql/relation.rb +2 -1
  33. data/lib/rom/sql/relation/reading.rb +63 -3
  34. data/lib/rom/sql/relation/writing.rb +38 -0
  35. data/lib/rom/sql/schema.rb +9 -3
  36. data/lib/rom/sql/schema/attributes_inferrer.rb +3 -119
  37. data/lib/rom/sql/schema/inferrer.rb +99 -18
  38. data/lib/rom/sql/schema/type_builder.rb +94 -0
  39. data/lib/rom/sql/type_dsl.rb +30 -0
  40. data/lib/rom/sql/type_extensions.rb +11 -6
  41. data/lib/rom/sql/type_serializer.rb +46 -0
  42. data/lib/rom/sql/types.rb +12 -0
  43. data/lib/rom/sql/version.rb +1 -1
  44. metadata +26 -244
  45. data/.codeclimate.yml +0 -15
  46. data/.gitignore +0 -17
  47. data/.rspec +0 -3
  48. data/.travis.yml +0 -39
  49. data/.yardopts +0 -2
  50. data/Gemfile +0 -33
  51. data/Guardfile +0 -24
  52. data/LICENSE.txt +0 -22
  53. data/Rakefile +0 -19
  54. data/circle.yml +0 -10
  55. data/lib/rom/sql/extensions/mysql/attributes_inferrer.rb +0 -10
  56. data/lib/rom/sql/relation/sequel_api.rb +0 -133
  57. data/log/.gitkeep +0 -0
  58. data/rom-sql.gemspec +0 -29
  59. data/spec/extensions/postgres/attribute_spec.rb +0 -217
  60. data/spec/extensions/postgres/integration_spec.rb +0 -59
  61. data/spec/extensions/postgres/types_spec.rb +0 -252
  62. data/spec/extensions/sqlite/types_spec.rb +0 -11
  63. data/spec/fixtures/migrations/20150403090603_create_carrots.rb +0 -8
  64. data/spec/integration/associations/many_to_many/custom_fks_spec.rb +0 -76
  65. data/spec/integration/associations/many_to_many/from_view_spec.rb +0 -88
  66. data/spec/integration/associations/many_to_many_spec.rb +0 -162
  67. data/spec/integration/associations/many_to_one/custom_fks_spec.rb +0 -64
  68. data/spec/integration/associations/many_to_one/from_view_spec.rb +0 -84
  69. data/spec/integration/associations/many_to_one/self_ref_spec.rb +0 -53
  70. data/spec/integration/associations/many_to_one_spec.rb +0 -117
  71. data/spec/integration/associations/one_to_many/custom_fks_spec.rb +0 -54
  72. data/spec/integration/associations/one_to_many/from_view_spec.rb +0 -57
  73. data/spec/integration/associations/one_to_many/self_ref_spec.rb +0 -54
  74. data/spec/integration/associations/one_to_many_spec.rb +0 -86
  75. data/spec/integration/associations/one_to_one_spec.rb +0 -69
  76. data/spec/integration/associations/one_to_one_through_spec.rb +0 -92
  77. data/spec/integration/auto_migrations/errors_spec.rb +0 -31
  78. data/spec/integration/auto_migrations/indexes_spec.rb +0 -253
  79. data/spec/integration/auto_migrations/managing_columns_spec.rb +0 -156
  80. data/spec/integration/auto_migrations/postgres/column_types_spec.rb +0 -63
  81. data/spec/integration/combine_with_spec.rb +0 -43
  82. data/spec/integration/commands/create_spec.rb +0 -304
  83. data/spec/integration/commands/delete_spec.rb +0 -84
  84. data/spec/integration/commands/update_spec.rb +0 -90
  85. data/spec/integration/commands/upsert_spec.rb +0 -83
  86. data/spec/integration/gateway_spec.rb +0 -107
  87. data/spec/integration/migration_spec.rb +0 -55
  88. data/spec/integration/plugins/associates/many_to_many_spec.rb +0 -69
  89. data/spec/integration/plugins/associates_spec.rb +0 -250
  90. data/spec/integration/plugins/auto_restrictions_spec.rb +0 -74
  91. data/spec/integration/relation_schema_spec.rb +0 -271
  92. data/spec/integration/schema/call_spec.rb +0 -24
  93. data/spec/integration/schema/inferrer/mysql_spec.rb +0 -45
  94. data/spec/integration/schema/inferrer/postgres_spec.rb +0 -203
  95. data/spec/integration/schema/inferrer/sqlite_spec.rb +0 -37
  96. data/spec/integration/schema/inferrer_spec.rb +0 -390
  97. data/spec/integration/schema/prefix_spec.rb +0 -16
  98. data/spec/integration/schema/qualified_spec.rb +0 -16
  99. data/spec/integration/schema/rename_spec.rb +0 -21
  100. data/spec/integration/schema/view_spec.rb +0 -29
  101. data/spec/integration/sequel_api_spec.rb +0 -36
  102. data/spec/integration/setup_spec.rb +0 -26
  103. data/spec/integration/support/active_support_notifications_spec.rb +0 -24
  104. data/spec/integration/support/rails_log_subscriber_spec.rb +0 -30
  105. data/spec/integration/wrap_spec.rb +0 -91
  106. data/spec/shared/accounts.rb +0 -48
  107. data/spec/shared/database_setup.rb +0 -70
  108. data/spec/shared/notes.rb +0 -23
  109. data/spec/shared/posts.rb +0 -34
  110. data/spec/shared/puppies.rb +0 -15
  111. data/spec/shared/relations.rb +0 -8
  112. data/spec/shared/users.rb +0 -32
  113. data/spec/shared/users_and_tasks.rb +0 -50
  114. data/spec/spec_helper.rb +0 -122
  115. data/spec/support/env_helper.rb +0 -25
  116. data/spec/support/helpers.rb +0 -24
  117. data/spec/support/oracle/create_users.sql +0 -7
  118. data/spec/support/oracle/set_sys_passwords.sql +0 -2
  119. data/spec/support/test_configuration.rb +0 -16
  120. data/spec/unit/attribute_spec.rb +0 -104
  121. data/spec/unit/function_spec.rb +0 -48
  122. data/spec/unit/gateway_spec.rb +0 -70
  123. data/spec/unit/logger_spec.rb +0 -14
  124. data/spec/unit/migration_tasks_spec.rb +0 -111
  125. data/spec/unit/migrator_spec.rb +0 -25
  126. data/spec/unit/order_dsl_spec.rb +0 -43
  127. data/spec/unit/plugin/associates_spec.rb +0 -94
  128. data/spec/unit/plugin/pagination_spec.rb +0 -91
  129. data/spec/unit/plugin/timestamp_spec.rb +0 -117
  130. data/spec/unit/projection_dsl_spec.rb +0 -110
  131. data/spec/unit/relation/assoc_spec.rb +0 -87
  132. data/spec/unit/relation/associations_spec.rb +0 -27
  133. data/spec/unit/relation/avg_spec.rb +0 -11
  134. data/spec/unit/relation/by_pk_spec.rb +0 -62
  135. data/spec/unit/relation/dataset_spec.rb +0 -50
  136. data/spec/unit/relation/distinct_spec.rb +0 -15
  137. data/spec/unit/relation/exclude_spec.rb +0 -11
  138. data/spec/unit/relation/exist_predicate_spec.rb +0 -25
  139. data/spec/unit/relation/exists_spec.rb +0 -18
  140. data/spec/unit/relation/fetch_spec.rb +0 -21
  141. data/spec/unit/relation/group_spec.rb +0 -61
  142. data/spec/unit/relation/having_spec.rb +0 -22
  143. data/spec/unit/relation/inner_join_spec.rb +0 -158
  144. data/spec/unit/relation/inspect_spec.rb +0 -11
  145. data/spec/unit/relation/instrument_spec.rb +0 -45
  146. data/spec/unit/relation/invert_spec.rb +0 -11
  147. data/spec/unit/relation/left_join_spec.rb +0 -55
  148. data/spec/unit/relation/lock_spec.rb +0 -93
  149. data/spec/unit/relation/map_spec.rb +0 -16
  150. data/spec/unit/relation/max_spec.rb +0 -11
  151. data/spec/unit/relation/min_spec.rb +0 -11
  152. data/spec/unit/relation/order_spec.rb +0 -51
  153. data/spec/unit/relation/pluck_spec.rb +0 -11
  154. data/spec/unit/relation/prefix_spec.rb +0 -29
  155. data/spec/unit/relation/primary_key_spec.rb +0 -27
  156. data/spec/unit/relation/project_spec.rb +0 -24
  157. data/spec/unit/relation/qualified_columns_spec.rb +0 -30
  158. data/spec/unit/relation/qualified_spec.rb +0 -25
  159. data/spec/unit/relation/read_spec.rb +0 -25
  160. data/spec/unit/relation/rename_spec.rb +0 -23
  161. data/spec/unit/relation/right_join_spec.rb +0 -57
  162. data/spec/unit/relation/select_append_spec.rb +0 -21
  163. data/spec/unit/relation/select_spec.rb +0 -40
  164. data/spec/unit/relation/sum_spec.rb +0 -11
  165. data/spec/unit/relation/union_spec.rb +0 -19
  166. data/spec/unit/relation/unique_predicate_spec.rb +0 -18
  167. data/spec/unit/relation/where_spec.rb +0 -133
  168. data/spec/unit/restriction_dsl_spec.rb +0 -34
  169. data/spec/unit/schema_spec.rb +0 -25
  170. data/spec/unit/types_spec.rb +0 -65
data/.codeclimate.yml DELETED
@@ -1,15 +0,0 @@
1
- engines:
2
- duplication:
3
- enabled: true
4
- config:
5
- languages:
6
- ruby:
7
- mass_threshold: 25
8
- rubocop:
9
- enabled: true
10
-
11
- ratings:
12
- paths:
13
- - "**.rb"
14
-
15
- exclude_paths:
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- /vendor/
2
- /db/
3
- /.bundle/
4
- /.yardoc
5
- /Gemfile.lock
6
- /_yardoc/
7
- /coverage/
8
- /doc/
9
- /pkg/
10
- /spec/reports/
11
- /tmp/
12
- *.bundle
13
- *.so
14
- *.o
15
- *.a
16
- mkmf.log
17
- log/*.log
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --color
2
- --order random
3
- --require ./spec/spec_helper
data/.travis.yml DELETED
@@ -1,39 +0,0 @@
1
- language: ruby
2
- dist: trusty
3
- sudo: required
4
- cache: bundler
5
- services:
6
- - postgresql
7
- - mysql
8
- bundler_args: --without yard guard benchmarks tools
9
- before_script:
10
- - psql -c 'create database rom_sql;' -U postgres
11
- - mysql -u root -e 'create database rom_sql;'
12
- - rvm get master
13
- after_success:
14
- - '[ -d coverage ] && bundle exec codeclimate-test-reporter'
15
- script: "bundle exec rake ci"
16
- rvm:
17
- - 2.2.7
18
- - 2.3.4
19
- - 2.4.1
20
- - jruby-9.1.8.0
21
- env:
22
- global:
23
- - CODECLIMATE_REPO_TOKEN=03d7f66589572702b12426d2bc71c4de6281a96139e33b335b894264b1f8f0b0
24
- - JRUBY_OPTS='--dev -J-Xmx1024M'
25
- - COVERAGE='true'
26
- notifications:
27
- webhooks:
28
- urls:
29
- - https://webhooks.gitter.im/e/39e1225f489f38b0bd09
30
- on_success: change
31
- on_failure: always
32
- on_start: false
33
- addons:
34
- postgresql: 9.5
35
- apt:
36
- packages:
37
- - mysql-server-5.6
38
- - mysql-client-core-5.6
39
- - mysql-client-5.6
data/.yardopts DELETED
@@ -1,2 +0,0 @@
1
- --query '@api.text != "private"'
2
- --embed-mixins
data/Gemfile DELETED
@@ -1,33 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- gem 'dry-types', git: 'https://github.com/dry-rb/dry-types', branch: 'master'
6
-
7
- gem 'rom', git: 'https://github.com/rom-rb/rom', branch: 'master' do
8
- gem 'rom-core'
9
- gem 'rom-mapper'
10
- gem 'rom-repository', group: :tools
11
- end
12
-
13
- group :test do
14
- gem 'pry-byebug', platforms: :mri
15
- gem 'pry', platforms: %i(jruby rbx)
16
- gem 'dry-struct'
17
- gem 'activesupport', '~> 5.0'
18
- gem 'codeclimate-test-reporter', require: false
19
- gem 'simplecov', require: false
20
-
21
- if RUBY_ENGINE == 'rbx'
22
- gem 'pg', '~> 0.18.0', platforms: :rbx
23
- else
24
- gem 'pg', '~> 0.19', platforms: :mri
25
- end
26
-
27
- gem 'mysql2', platforms: [:mri, :rbx]
28
- gem 'jdbc-postgres', platforms: :jruby
29
- gem 'jdbc-mysql', platforms: :jruby
30
- gem 'sqlite3', platforms: [:mri, :rbx]
31
- gem 'jdbc-sqlite3', platforms: :jruby
32
- gem 'ruby-oci8', platforms: :mri if ENV['ROM_USE_ORACLE']
33
- end
data/Guardfile DELETED
@@ -1,24 +0,0 @@
1
- group :red_green_refactor, halt_on_fail: true do
2
- guard :rspec, cmd: "rspec", all_on_start: true do
3
- # run all specs if Gemfile.lock is modified
4
- watch('Gemfile.lock') { 'spec' }
5
-
6
- # run all specs if any library code is modified
7
- watch(%r{\Alib/.+\.rb\z}) { 'spec' }
8
-
9
- # run all specs if supporting files are modified
10
- watch('spec/spec_helper.rb') { 'spec' }
11
- watch(%r{\Aspec/(?:lib|support|shared)/.+\.rb\z}) { 'spec' }
12
-
13
- # run a spec if it is modified
14
- watch(%r{\Aspec/(?:unit|integration)/.+_spec\.rb\z})
15
-
16
- notification :tmux, display_message: true if ENV.key?('TMUX')
17
- end
18
-
19
- guard :rubocop do
20
- # run rubocop on modified file
21
- watch(%r{\Alib/.+\.rb\z})
22
- watch(%r{\Aspec/.+\.rb\z})
23
- end
24
- end
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2014-2017 Piotr Solnica
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile DELETED
@@ -1,19 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
- task default: [:ci]
6
-
7
- desc "Run CI tasks"
8
- task ci: [:spec]
9
-
10
- begin
11
- require "rubocop/rake_task"
12
-
13
- Rake::Task[:default].enhance [:rubocop]
14
-
15
- RuboCop::RakeTask.new do |task|
16
- task.options << "--display-cop-names"
17
- end
18
- rescue LoadError
19
- end
data/circle.yml DELETED
@@ -1,10 +0,0 @@
1
- machine:
2
- ruby:
3
- version: 2.3.3
4
- dependencies:
5
- bundler:
6
- without: [yard guard benchmarks tools]
7
- database:
8
- override:
9
- - psql -c 'create database rom_sql;' -U postgres
10
- - mysql -e 'create database rom_sql;'
@@ -1,10 +0,0 @@
1
- require 'rom/sql/schema/attributes_inferrer'
2
-
3
- module ROM
4
- module SQL
5
- class Schema
6
- class MysqlInferrer < AttributesInferrer[:mysql]
7
- end
8
- end
9
- end
10
- end
@@ -1,133 +0,0 @@
1
- module ROM
2
- module SQL
3
- # Query API for SQL::Relation
4
- #
5
- # @api public
6
- module SequelAPI
7
- # Select specific columns for select clause
8
- #
9
- # @example
10
- # users.select(:id, :name).first
11
- # # {:id => 1, :name => "Jane" }
12
- #
13
- # @return [Relation]
14
- #
15
- # @api public
16
- def select(*args, &block)
17
- new(dataset.__send__(__method__, *args, &block))
18
- end
19
-
20
- # Append specific columns to select clause
21
- #
22
- # @example
23
- # users.select(:id, :name).select_append(:email)
24
- # # {:id => 1, :name => "Jane", :email => "jane@doe.org"}
25
- #
26
- # @param [Array<Symbol>] *args A list with column names
27
- #
28
- # @return [Relation]
29
- #
30
- # @api public
31
- def select_append(*args, &block)
32
- new(dataset.__send__(__method__, *args, &block))
33
- end
34
-
35
- # Restrict a relation to match criteria
36
- #
37
- # If block is passed it'll be executed in the context of a condition
38
- # builder object.
39
- #
40
- # @example
41
- # users.where(name: 'Jane')
42
- #
43
- # users.where { age >= 18 }
44
- #
45
- # @param [Hash] *args An optional hash with conditions for WHERE clause
46
- #
47
- # @return [Relation]
48
- #
49
- # @see http://sequel.jeremyevans.net/rdoc/files/doc/dataset_filtering_rdoc.html
50
- #
51
- # @api public
52
- def where(*args, &block)
53
- new(dataset.__send__(__method__, *args, &block))
54
- end
55
-
56
- # Restrict a relation to match grouping criteria
57
- #
58
- # @example
59
- # users.with_task_count.having( task_count: 2 )
60
- #
61
- # users.with_task_count.having { task_count > 3 }
62
- #
63
- # @param [Hash] *args An optional hash with conditions for HAVING clause
64
- #
65
- # @return [Relation]
66
- #
67
- # @see http://sequel.jeremyevans.net/rdoc/files/doc/dataset_filtering_rdoc.html
68
- #
69
- # @api public
70
- def having(*args, &block)
71
- new(dataset.__send__(__method__, *args, &block))
72
- end
73
-
74
- # Set order for the relation
75
- #
76
- # @example
77
- # users.order(:name)
78
- #
79
- # @param [Array<Symbol>] *args A list with column names
80
- #
81
- # @return [Relation]
82
- #
83
- # @api public
84
- def order(*args, &block)
85
- new(dataset.__send__(__method__, *args, &block))
86
- end
87
-
88
- # Join with another relation using INNER JOIN
89
- #
90
- # @example
91
- # users.inner_join(:tasks, id: :user_id)
92
- #
93
- # @param [Symbol] relation name
94
- # @param [Hash] join keys
95
- #
96
- # @return [Relation]
97
- #
98
- # @api public
99
- def inner_join(*args, &block)
100
- new(dataset.__send__(__method__, *args, &block))
101
- end
102
-
103
- # Join other relation using LEFT OUTER JOIN
104
- #
105
- # @example
106
- # users.left_join(:tasks, id: :user_id)
107
- #
108
- # @param [Symbol] relation name
109
- # @param [Hash] join keys
110
- #
111
- # @return [Relation]
112
- #
113
- # @api public
114
- def left_join(*args, &block)
115
- new(dataset.__send__(__method__, *args, &block))
116
- end
117
-
118
- # Group by specific columns
119
- #
120
- # @example
121
- # tasks.group(:user_id)
122
- #
123
- # @param [Array<Symbol>] *args A list of column names
124
- #
125
- # @return [Relation]
126
- #
127
- # @api public
128
- def group(*args, &block)
129
- new(dataset.__send__(__method__, *args, &block))
130
- end
131
- end
132
- end
133
- end
data/log/.gitkeep DELETED
File without changes
data/rom-sql.gemspec DELETED
@@ -1,29 +0,0 @@
1
- lib = File.expand_path('../lib', __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'rom/sql/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'rom-sql'
7
- spec.version = ROM::SQL::VERSION.dup
8
- spec.authors = ['Piotr Solnica']
9
- spec.email = ['piotr.solnica@gmail.com']
10
- spec.summary = 'SQL databases support for ROM'
11
- spec.description = spec.summary
12
- spec.homepage = 'http://rom-rb.org'
13
- spec.license = 'MIT'
14
-
15
- spec.files = `git ls-files -z`.split("\x0")
16
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
- spec.require_paths = ['lib']
19
-
20
- spec.add_runtime_dependency 'sequel', '~> 4.43'
21
- spec.add_runtime_dependency 'dry-equalizer', '~> 0.2'
22
- spec.add_runtime_dependency 'dry-types', '~> 0.11'
23
- spec.add_runtime_dependency 'dry-core', '~> 0.3'
24
- spec.add_runtime_dependency 'rom-core', '~> 4.0.0.beta'
25
-
26
- spec.add_development_dependency 'bundler'
27
- spec.add_development_dependency 'rake', '~> 10.0'
28
- spec.add_development_dependency 'rspec', '~> 3.5'
29
- end
@@ -1,217 +0,0 @@
1
- RSpec.describe 'ROM::SQL::Attribute', :postgres do
2
- include_context 'database setup'
3
-
4
- before do
5
- conn.drop_table?(:pg_people)
6
- conn.drop_table?(:people)
7
-
8
- conf.relation(:people) do
9
- schema(:pg_people, infer: true)
10
- end
11
- end
12
-
13
- let(:people) { relations[:people] }
14
- let(:create_person) { commands[:people].create }
15
-
16
- %i(json jsonb).each do |type|
17
- if type == :json
18
- json_hash = Sequel::Postgres::JSONHash.method(:new)
19
- json_array = Sequel::Postgres::JSONArray.method(:new)
20
- else
21
- json_hash = Sequel::Postgres::JSONBHash.method(:new)
22
- json_array = Sequel::Postgres::JSONBArray.method(:new)
23
- end
24
-
25
- describe "using arrays in #{ type }" do
26
- before do
27
- conn.create_table :pg_people do
28
- primary_key :id
29
- String :name
30
- column :fields, type
31
- end
32
-
33
- conf.commands(:people) do
34
- define(:create)
35
- define(:update)
36
- end
37
-
38
- create_person.(name: 'John Doe', fields: [{ name: 'age', value: '30' },
39
- { name: 'height', value: 180 }])
40
- create_person.(name: 'Jade Doe', fields: [{ name: 'age', value: '25' }])
41
- end
42
-
43
- it 'fetches data from jsonb array by index' do
44
- expect(people.select { [fields.get(1).as(:field)] }.where(name: 'John Doe').one).
45
- to eql(field: json_hash['name' => 'height', 'value' => 180])
46
- end
47
-
48
- it 'fetches data from jsonb array' do
49
- expect(people.select { fields.get(1).get_text('value').as(:height) }.where(name: 'John Doe').one).
50
- to eql(height: '180')
51
- end
52
-
53
- it 'fetches data with path' do
54
- expect(people.select(people[:fields].get_text('1', 'value').as(:height)).to_a).
55
- to eql([{ height: '180' }, { height: nil }])
56
- end
57
-
58
- if type == :jsonb
59
- it 'allows to query jsonb by inclusion' do
60
- expect(people.select(:name).where { fields.contain([value: '30']) }.one).
61
- to eql(name: 'John Doe')
62
- end
63
-
64
- it 'cat project result of contains' do
65
- expect(people.select { fields.contain([value: '30']).as(:contains) }.to_a).
66
- to eql([{ contains: true }, { contains: false }])
67
- end
68
-
69
- it 'deletes key from result' do
70
- expect(people.select { fields.delete(0).as(:result) }.limit(1).one).
71
- to eq(result: json_array[['name' => 'height', 'value' => 180]])
72
- end
73
-
74
- it 'deletes by path' do
75
- expect(people.select { fields.delete('0', 'name').delete('1', 'name').as(:result) }.limit(1).one).
76
- to eq(result: json_array[[{ 'value' => '30' }, { 'value' => 180 }]])
77
- end
78
-
79
- it 'concatenates JSON values' do
80
- expect(people.select { (fields + [name: 'height', value: 165]).as(:result) }.by_pk(2).one).
81
- to eq(result: json_array[[{ 'name' => 'age', 'value' => '25' },
82
- { 'name' => 'height', 'value' => 165 }]])
83
- end
84
- end
85
- end
86
-
87
- if type == :jsonb
88
- describe "using maps in #{ type }" do
89
- before do
90
- conn.create_table :pg_people do
91
- primary_key :id
92
- String :name
93
- column :data, type
94
- end
95
-
96
- conf.commands(:people) do
97
- define(:create)
98
- define(:update)
99
- end
100
-
101
- create_person.(name: 'John Doe', data: { age: 30, height: 180 })
102
- create_person.(name: 'Jade Doe', data: { age: 25 })
103
- end
104
-
105
- it 'queries data by inclusion' do
106
- expect(people.select(:name).where { data.contain(age: 30) }.one).
107
- to eql(name: 'John Doe')
108
- end
109
-
110
- it 'queries data by left inclusion' do
111
- expect(people.select(:name).where { data.contained_by(age: 25, foo: 'bar') }.one).
112
- to eql(name: 'Jade Doe')
113
- end
114
-
115
- it 'checks for key presence' do
116
- expect(people.select { data.has_key('height').as(:there) }.to_a).
117
- to eql([{ there: true }, { there: false }])
118
-
119
- expect(people.select(:name).where { data.has_any_key('height', 'width') }.one).
120
- to eql(name: 'John Doe')
121
-
122
- expect(people.select(:name).where { data.has_all_keys('height', 'age') }.one).
123
- to eql(name: 'John Doe')
124
- end
125
-
126
- it 'concatenates JSON values' do
127
- expect(people.select { data.merge(height: 165).as(:result) }.by_pk(2).one).
128
- to eql(result: json_hash['age' => 25, 'height' => 165])
129
- end
130
-
131
- it 'deletes key from result' do
132
- expect(people.select { data.delete('height').as(:result) }.to_a).
133
- to eql([{ result: json_hash['age' => 30] },
134
- { result: json_hash['age' => 25] }])
135
- end
136
- end
137
- end
138
- end
139
-
140
- describe 'using array types' do
141
- before do
142
- conn.create_table :pg_people do
143
- primary_key :id
144
- String :name
145
- column :emails, 'text[]'
146
- column :bigids, 'bigint[]'
147
- end
148
-
149
- conf.commands(:people) do
150
- define(:create)
151
- define(:update)
152
- end
153
-
154
- create_person.(name: 'John Doe', emails: %w(john@doe.com john@example.com), bigids: [84])
155
- create_person.(name: 'Jade Doe', emails: %w(jade@hotmail.com), bigids: [42])
156
- end
157
-
158
- it 'filters by email inclusion' do
159
- expect(people.select(:name).where { emails.contain(['john@doe.com']) }.one).
160
- to eql(name: 'John Doe')
161
- end
162
-
163
- it 'coerces values so that PG does not complain' do
164
- expect(people.select(:name).where { bigids.contain([84]) }.one).
165
- to eql(name: 'John Doe')
166
- end
167
-
168
- it 'fetches element by index' do
169
- expect(people.select { [name, emails.get(2).as(:second_email)] }.to_a).
170
- to eql([{ name: 'John Doe', second_email: 'john@example.com' },
171
- { name: 'Jade Doe', second_email: nil }])
172
- end
173
-
174
- it 'restricts with ANY' do
175
- expect(people.select(:name).where { bigids.any(84)}.one).
176
- to eql(name: 'John Doe')
177
- end
178
-
179
- it 'restricts by <@' do
180
- expect(people.select(:name).where { bigids.contained_by((30..50).to_a) }.one).
181
- to eql(name: 'Jade Doe')
182
- end
183
-
184
- it 'returns array length' do
185
- expect(people.select { [name, emails.length.as(:size)] }.to_a).
186
- to eql([{ name: 'John Doe', size: 2 }, { name: 'Jade Doe', size: 1 }])
187
- end
188
-
189
- it 'restrict by overlapping with other array' do
190
- expect(people.select(:name).where { emails.overlaps(%w(jade@hotmail.com)) }.one).
191
- to eql(name: 'Jade Doe')
192
-
193
- expect(people.select(:name).where { bigids.overlaps([42]) }.one).
194
- to eql(name: 'Jade Doe')
195
- end
196
-
197
- it 'removes element by value' do
198
- expect(people.select { emails.remove_value('john@example.com').as(:emails) }.to_a).
199
- to eq([{ emails: %w(john@doe.com) }, { emails: %w(jade@hotmail.com) }])
200
-
201
- pending "doesn't have auto-casting yet"
202
- expect(people.select(:name).where { bigids.remove_value(100).contains([42]) }.one).
203
- to eql(name: 'Jade Doe')
204
- end
205
-
206
- it 'joins values' do
207
- expect(people.select { emails.join(',').as(:emails) }.to_a).
208
- to eql([{ emails: 'john@doe.com,john@example.com' },
209
- { emails: 'jade@hotmail.com' }])
210
- end
211
-
212
- it 'concatenates arrays' do
213
- expect(people.select { (emails + %w(foo@bar.com)).as(:emails) }.where { name.is('Jade Doe') }.one).
214
- to eq(emails: %w(jade@hotmail.com foo@bar.com))
215
- end
216
- end
217
- end