rom-sql 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/lib/rom-sql.rb +2 -0
  4. data/lib/rom/plugins/relation/sql/auto_restrictions.rb +2 -0
  5. data/lib/rom/plugins/relation/sql/instrumentation.rb +2 -0
  6. data/lib/rom/plugins/relation/sql/postgres/explain.rb +6 -7
  7. data/lib/rom/sql.rb +2 -0
  8. data/lib/rom/sql/associations.rb +2 -0
  9. data/lib/rom/sql/associations/core.rb +3 -1
  10. data/lib/rom/sql/associations/many_to_many.rb +2 -0
  11. data/lib/rom/sql/associations/many_to_one.rb +2 -0
  12. data/lib/rom/sql/associations/one_to_many.rb +2 -0
  13. data/lib/rom/sql/associations/one_to_one.rb +2 -0
  14. data/lib/rom/sql/associations/one_to_one_through.rb +2 -0
  15. data/lib/rom/sql/associations/self_ref.rb +2 -0
  16. data/lib/rom/sql/attribute.rb +9 -5
  17. data/lib/rom/sql/commands.rb +2 -0
  18. data/lib/rom/sql/commands/create.rb +2 -0
  19. data/lib/rom/sql/commands/delete.rb +2 -0
  20. data/lib/rom/sql/commands/error_wrapper.rb +2 -0
  21. data/lib/rom/sql/commands/update.rb +2 -0
  22. data/lib/rom/sql/dsl.rb +11 -3
  23. data/lib/rom/sql/error.rb +2 -0
  24. data/lib/rom/sql/errors.rb +2 -0
  25. data/lib/rom/sql/extensions.rb +2 -0
  26. data/lib/rom/sql/extensions/active_support_notifications.rb +2 -0
  27. data/lib/rom/sql/extensions/mysql.rb +2 -0
  28. data/lib/rom/sql/extensions/mysql/type_builder.rb +2 -0
  29. data/lib/rom/sql/extensions/postgres.rb +2 -0
  30. data/lib/rom/sql/extensions/postgres/commands.rb +2 -0
  31. data/lib/rom/sql/extensions/postgres/type_builder.rb +6 -4
  32. data/lib/rom/sql/extensions/postgres/type_serializer.rb +2 -0
  33. data/lib/rom/sql/extensions/postgres/types.rb +2 -0
  34. data/lib/rom/sql/extensions/postgres/types/array.rb +6 -4
  35. data/lib/rom/sql/extensions/postgres/types/array_types.rb +3 -1
  36. data/lib/rom/sql/extensions/postgres/types/geometric.rb +2 -0
  37. data/lib/rom/sql/extensions/postgres/types/json.rb +13 -11
  38. data/lib/rom/sql/extensions/postgres/types/ltree.rb +25 -23
  39. data/lib/rom/sql/extensions/postgres/types/network.rb +2 -0
  40. data/lib/rom/sql/extensions/postgres/types/range.rb +2 -0
  41. data/lib/rom/sql/extensions/rails_log_subscriber.rb +2 -0
  42. data/lib/rom/sql/extensions/sqlite.rb +2 -0
  43. data/lib/rom/sql/extensions/sqlite/type_builder.rb +2 -0
  44. data/lib/rom/sql/extensions/sqlite/types.rb +2 -0
  45. data/lib/rom/sql/foreign_key.rb +3 -1
  46. data/lib/rom/sql/function.rb +3 -1
  47. data/lib/rom/sql/gateway.rb +3 -1
  48. data/lib/rom/sql/group_dsl.rb +2 -0
  49. data/lib/rom/sql/index.rb +2 -0
  50. data/lib/rom/sql/join_dsl.rb +2 -0
  51. data/lib/rom/sql/mapper_compiler.rb +2 -0
  52. data/lib/rom/sql/migration.rb +5 -3
  53. data/lib/rom/sql/migration/inline_runner.rb +2 -0
  54. data/lib/rom/sql/migration/migrator.rb +4 -2
  55. data/lib/rom/sql/migration/recorder.rb +2 -0
  56. data/lib/rom/sql/migration/runner.rb +4 -2
  57. data/lib/rom/sql/migration/schema_diff.rb +2 -0
  58. data/lib/rom/sql/migration/template.rb +2 -0
  59. data/lib/rom/sql/migration/writer.rb +12 -4
  60. data/lib/rom/sql/order_dsl.rb +2 -0
  61. data/lib/rom/sql/plugin/associates.rb +4 -2
  62. data/lib/rom/sql/plugin/nullify.rb +2 -0
  63. data/lib/rom/sql/plugin/pagination.rb +2 -0
  64. data/lib/rom/sql/plugins.rb +2 -0
  65. data/lib/rom/sql/projection_dsl.rb +2 -0
  66. data/lib/rom/sql/rake_task.rb +2 -0
  67. data/lib/rom/sql/relation.rb +2 -0
  68. data/lib/rom/sql/relation/reading.rb +5 -3
  69. data/lib/rom/sql/relation/writing.rb +2 -0
  70. data/lib/rom/sql/restriction_dsl.rb +9 -1
  71. data/lib/rom/sql/schema.rb +3 -1
  72. data/lib/rom/sql/schema/attributes_inferrer.rb +5 -3
  73. data/lib/rom/sql/schema/dsl.rb +3 -1
  74. data/lib/rom/sql/schema/index_dsl.rb +5 -2
  75. data/lib/rom/sql/schema/inferrer.rb +12 -8
  76. data/lib/rom/sql/schema/type_builder.rb +4 -2
  77. data/lib/rom/sql/spec/support.rb +5 -3
  78. data/lib/rom/sql/tasks/migration_tasks.rake +16 -11
  79. data/lib/rom/sql/transaction.rb +2 -0
  80. data/lib/rom/sql/type_dsl.rb +2 -0
  81. data/lib/rom/sql/type_extensions.rb +2 -0
  82. data/lib/rom/sql/type_serializer.rb +2 -0
  83. data/lib/rom/sql/types.rb +2 -0
  84. data/lib/rom/sql/version.rb +3 -1
  85. data/lib/rom/sql/wrap.rb +2 -0
  86. data/lib/rom/types/values.rb +2 -0
  87. metadata +7 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f52d96de5f0817d048ca81908d0e1548fde8437314ce2842732fa0de1bc2a45
4
- data.tar.gz: e194b0a48c85a5a4651dcc1ff073f34e256aad05d22ff8255d16c17418948acf
3
+ metadata.gz: a1b112ea9690e7cc6292907784ff4a1fa4b5104156b49f15ce7aa8e5b0f7ffac
4
+ data.tar.gz: 2812251110ba0677d9187564f199a6d28e0f61b198f36f4c241455132e789123
5
5
  SHA512:
6
- metadata.gz: 7b9c43411663f8c89bc6df66df77afae600c1b053deb786b23aa7aabafcce6692b8265a11fe9431ea985cdff4d186d8d27cad7407729e2ddf8db8fc38dbb8d09
7
- data.tar.gz: 9ccb96a9bf4d8d2a6dd638313317fd992e925b1ad5bd4447813e74f6ff2e4a916a10376f37e8982bb0ac09647299a412bbcd27be2f95966f7d28d27e23789559
6
+ metadata.gz: 72d567632369f93fed528c8bc469532f14d564054f85ef24f8a9a5dc23c57979f12345e54e3a44b2a2ef2db33d6a468489fa9d65ca006532b1c4ca04354ac545
7
+ data.tar.gz: 35703da2994cd323a3af2980ca624b2fdced01593f0a06aa78cafc0b9d8670e8c11129d38894b3df4d65063e1d62b4fdc5a7515e9ee4281e483d86acdda4a73c
@@ -1,3 +1,11 @@
1
+ ## 3.2.0 2020-01-11
2
+
3
+ ### Fixed
4
+
5
+ - Keyword warnings on Ruby 2.7 (@flash-gordon)
6
+
7
+ [Compare v3.1.0...v3.2.0](https://github.com/rom-rb/rom-sql/compare/v3.1.0...v3.2.0)
8
+
1
9
  ## 3.1.0 2019-12-16
2
10
 
3
11
  ### Added
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/sql'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/support/notifications'
2
4
 
3
5
  module ROM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module Plugins
3
5
  module Relation
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module Plugins
3
5
  module Relation
@@ -24,14 +26,11 @@ module ROM
24
26
  #
25
27
  # @api public
26
28
  def explain(format: :text, **options)
27
- bool_options = options.map { |opt, value| "#{ opt.to_s.upcase } #{ !!value }" }
28
- format_option = "FORMAT #{ format.to_s.upcase }"
29
+ bool_options = options.map { |opt, value| "#{opt.to_s.upcase} #{!!value}" }
30
+ format_option = "FORMAT #{format.to_s.upcase}"
31
+ explain_value = [format_option, *bool_options].join(', ')
29
32
 
30
- query =
31
- "EXPLAIN (" <<
32
- [format_option, *bool_options].join(', ') <<
33
- ") " <<
34
- dataset.sql
33
+ query = "EXPLAIN (#{explain_value}) #{dataset.sql}"
35
34
 
36
35
  rows = dataset.with_sql(query).map(:'QUERY PLAN')
37
36
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/equalizer'
2
4
 
3
5
  require 'rom/core'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/sql/associations/many_to_many'
2
4
  require 'rom/sql/associations/many_to_one'
3
5
  require 'rom/sql/associations/one_to_many'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module SQL
3
5
  module Associations
@@ -19,7 +21,7 @@ module ROM
19
21
  def wrapped
20
22
  new_target = view ? target.send(view) : target
21
23
  to_wrap = self.class.allocate
22
- to_wrap.send(:initialize, definition, options.merge(target: new_target))
24
+ to_wrap.send(:initialize, definition, **options, target: new_target)
23
25
  to_wrap.wrap
24
26
  end
25
27
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/associations/many_to_many'
2
4
  require 'rom/sql/associations/core'
3
5
  require 'rom/sql/associations/self_ref'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/associations/many_to_one'
2
4
  require 'rom/sql/associations/core'
3
5
  require 'rom/sql/associations/self_ref'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/associations/one_to_many'
2
4
  require 'rom/sql/associations/core'
3
5
  require 'rom/sql/associations/self_ref'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/sql/associations/one_to_many'
2
4
 
3
5
  module ROM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/sql/associations/many_to_many'
2
4
 
3
5
  module ROM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module SQL
3
5
  module Associations
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sequel/core'
2
4
  require 'dry/core/cache'
3
5
 
@@ -19,16 +21,18 @@ module ROM
19
21
 
20
22
  OPERATORS = %i[>= <= > <].freeze
21
23
  NONSTANDARD_EQUALITY_VALUES = [true, false, nil].freeze
22
- META_KEYS = %i(index foreign_key target sql_expr qualified).freeze
24
+ META_KEYS = %i[index foreign_key target sql_expr qualified].freeze
23
25
 
24
26
  # Error raised when an attribute cannot be qualified
25
27
  QualifyError = Class.new(StandardError)
26
28
 
27
29
  extend Dry::Core::Cache
28
30
 
29
- # @api private
30
- def self.[](*args)
31
- fetch_or_store(args) { new(*args) }
31
+ class << self
32
+ # @api private
33
+ def [](type, options = EMPTY_HASH)
34
+ fetch_or_store([type, options]) { new(type, **options) }
35
+ end
32
36
  end
33
37
 
34
38
  # Return a new attribute in its canonical form
@@ -318,7 +322,7 @@ module ROM
318
322
  cleaned_meta = meta.reject { |k, _| META_KEYS.include?(k) }
319
323
  type = optional? ? right : self.type
320
324
 
321
- self.class.new(type.with(meta: cleaned_meta), options)
325
+ self.class.new(type.with(meta: cleaned_meta), **options)
322
326
  end
323
327
 
324
328
  # Wrap a value with the type, it allows using attribute and type specific methods
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/commands'
2
4
 
3
5
  require 'rom/sql/commands/create'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/sql/commands/error_wrapper'
2
4
 
3
5
  module ROM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/sql/commands/error_wrapper'
2
4
 
3
5
  module ROM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module SQL
3
5
  module Commands
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/sql/commands/error_wrapper'
2
4
 
3
5
  module ROM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'concurrent/map'
2
4
  require 'rom/support/inflector'
3
5
  require 'rom/constants'
@@ -27,7 +29,13 @@ module ROM
27
29
 
28
30
  # @api private
29
31
  def call(&block)
30
- result = instance_exec(select_relations(block.parameters), &block)
32
+ arg, kwargs = select_relations(block.parameters)
33
+
34
+ if kwargs.nil?
35
+ result = instance_exec(arg, &block)
36
+ else
37
+ result = instance_exec(**kwargs, &block)
38
+ end
31
39
 
32
40
  if result.is_a?(::Array)
33
41
  result
@@ -82,9 +90,9 @@ module ROM
82
90
  keys = parameters.select { |type, _| type == :keyreq }
83
91
 
84
92
  if keys.empty?
85
- relations
93
+ [relations, nil]
86
94
  else
87
- keys.each_with_object({}) { |(_, k), rs| rs[k] = relations[k] }
95
+ [nil, keys.each_with_object({}) { |(_, k), rs| rs[k] = relations[k] }]
88
96
  end
89
97
  end
90
98
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module SQL
3
5
  class Error < StandardError
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sequel/deprecated'
2
4
  require 'sequel/exceptions'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/core/extensions'
2
4
 
3
5
  module ROM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sequel/database/logging'
2
4
  require 'active_support/notifications'
3
5
 
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/sql/extensions/mysql/type_builder'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/sql/schema/attributes_inferrer'
2
4
 
3
5
  module ROM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/sql/extensions/postgres/commands'
2
4
  require 'rom/sql/extensions/postgres/types'
3
5
  require 'rom/sql/extensions/postgres/type_builder'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/sql/commands/create'
2
4
  require 'rom/sql/commands/update'
3
5
 
@@ -1,14 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module SQL
3
5
  module Postgres
4
6
  class TypeBuilder < Schema::TypeBuilder
5
7
  defines :db_numeric_types, :db_type_mapping, :db_array_type_matcher
6
8
 
7
- db_numeric_types %w(
9
+ db_numeric_types %w[
8
10
  smallint integer bigint
9
11
  decimal numeric real
10
12
  double\ precision serial bigserial
11
- ).to_set.freeze
13
+ ].to_set.freeze
12
14
 
13
15
  db_type_mapping(
14
16
  'uuid' => Types::UUID,
@@ -39,11 +41,11 @@ module ROM
39
41
 
40
42
  db_array_type_matcher '[]'.freeze
41
43
 
42
- def map_pk_type(type, db_type, options = {})
44
+ def map_pk_type(type, db_type, **options)
43
45
  if numeric?(type, db_type)
44
46
  type = self.class.numeric_pk_type
45
47
  else
46
- type = map_type(type, db_type, options)
48
+ type = map_type(type, db_type, **options)
47
49
  end
48
50
 
49
51
  type.meta(primary_key: true)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module SQL
3
5
  module Postgres
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sequel/core'
2
4
 
3
5
  require 'rom/sql/type_extensions'
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sequel/core'
2
4
 
3
- Sequel.extension(*%i(pg_array pg_array_ops))
5
+ Sequel.extension(:pg_array, :pg_array_ops)
4
6
 
5
7
  require 'rom/sql/extensions/postgres/types/array_types'
6
8
 
@@ -120,7 +122,7 @@ module ROM
120
122
  Attribute[type].meta(sql_expr: expr.pg_array[idx])
121
123
  end
122
124
 
123
- def any(type, expr, value)
125
+ def any(_type, expr, value)
124
126
  Attribute[SQL::Types::Bool].meta(sql_expr: { value => expr.pg_array.any })
125
127
  end
126
128
 
@@ -128,7 +130,7 @@ module ROM
128
130
  Attribute[SQL::Types::Bool].meta(sql_expr: expr.pg_array.contained_by(type[other]))
129
131
  end
130
132
 
131
- def length(type, expr)
133
+ def length(_type, expr)
132
134
  Attribute[SQL::Types::Integer].meta(sql_expr: expr.pg_array.length)
133
135
  end
134
136
 
@@ -140,7 +142,7 @@ module ROM
140
142
  Attribute[type].meta(sql_expr: expr.pg_array.remove(cast(type, value)))
141
143
  end
142
144
 
143
- def join(type, expr, delimiter = '', null = nil)
145
+ def join(_type, expr, delimiter = '', null = nil)
144
146
  Attribute[SQL::Types::String].meta(sql_expr: expr.pg_array.join(delimiter, null))
145
147
  end
146
148
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/sql/type_extensions'
2
4
 
3
5
  module ROM
@@ -52,7 +54,7 @@ module ROM
52
54
  end
53
55
  end
54
56
 
55
- def build_read_type(db_type, member_type)
57
+ def build_read_type(_db_type, member_type)
56
58
  if member_type && member_type.meta[:read]
57
59
  base_read_type.of(member_type.meta[:read])
58
60
  else
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module SQL
3
5
  module Postgres
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sequel/core'
2
4
  require 'singleton'
3
5
 
4
- Sequel.extension(*%i(pg_json pg_json_ops))
6
+ Sequel.extension(:pg_json, :pg_json_ops)
5
7
 
6
8
  module ROM
7
9
  module SQL
@@ -228,11 +230,11 @@ module ROM
228
230
  end
229
231
  end
230
232
 
231
- def get(type, expr, *path)
233
+ def get(_type, expr, *path)
232
234
  Attribute[json_type].meta(sql_expr: wrap(expr)[path_args(path)])
233
235
  end
234
236
 
235
- def get_text(type, expr, *path)
237
+ def get_text(_type, expr, *path)
236
238
  Attribute[SQL::Types::String].meta(sql_expr: wrap(expr).get_text(path_args(path)))
237
239
  end
238
240
 
@@ -240,7 +242,7 @@ module ROM
240
242
 
241
243
  def path_args(path)
242
244
  case path.size
243
- when 0 then raise ArgumentError, "wrong number of arguments (given 0, expected 1+)"
245
+ when 0 then raise ArgumentError, 'wrong number of arguments (given 0, expected 1+)'
244
246
  when 1 then path[0]
245
247
  else path
246
248
  end
@@ -254,32 +256,32 @@ module ROM
254
256
  TypeExtensions.register(JSONB) do
255
257
  include JSONMethods[JSONB, :pg_jsonb.to_proc]
256
258
 
257
- def contain(type, expr, value)
259
+ def contain(_type, expr, value)
258
260
  Attribute[SQL::Types::Bool].meta(sql_expr: wrap(expr).contains(value))
259
261
  end
260
262
 
261
- def contained_by(type, expr, value)
263
+ def contained_by(_type, expr, value)
262
264
  Attribute[SQL::Types::Bool].meta(sql_expr: wrap(expr).contained_by(value))
263
265
  end
264
266
 
265
- def has_key(type, expr, key)
267
+ def has_key(_type, expr, key)
266
268
  Attribute[SQL::Types::Bool].meta(sql_expr: wrap(expr).has_key?(key))
267
269
  end
268
270
 
269
- def has_any_key(type, expr, *keys)
271
+ def has_any_key(_type, expr, *keys)
270
272
  Attribute[SQL::Types::Bool].meta(sql_expr: wrap(expr).contain_any(keys))
271
273
  end
272
274
 
273
- def has_all_keys(type, expr, *keys)
275
+ def has_all_keys(_type, expr, *keys)
274
276
  Attribute[SQL::Types::Bool].meta(sql_expr: wrap(expr).contain_all(keys))
275
277
  end
276
278
 
277
- def merge(type, expr, value)
279
+ def merge(_type, expr, value)
278
280
  Attribute[JSONB].meta(sql_expr: wrap(expr).concat(value))
279
281
  end
280
282
  alias_method :+, :merge
281
283
 
282
- def delete(type, expr, *path)
284
+ def delete(_type, expr, *path)
283
285
  sql_expr = path.size == 1 ? wrap(expr) - path : wrap(expr).delete_path(path)
284
286
  Attribute[JSONB].meta(sql_expr: sql_expr)
285
287
  end