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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/types/values'
2
4
 
3
5
  module ROM
@@ -222,20 +224,20 @@ module ROM
222
224
  #
223
225
  # end
224
226
  module LTreeMethods
225
- ASCENDANT = ["(".freeze, " @> ".freeze, ")".freeze].freeze
226
- FIND_ASCENDANT = ["(".freeze, " ?@> ".freeze, ")".freeze].freeze
227
- DESCENDANT = ["(".freeze, " <@ ".freeze, ")".freeze].freeze
228
- FIND_DESCENDANT = ["(".freeze, " ?<@ ".freeze, ")".freeze].freeze
229
- MATCH_ANY = ["(".freeze, " ? ".freeze, ")".freeze].freeze
230
- MATCH_ANY_LQUERY = ["(".freeze, " ?~ ".freeze, ")".freeze].freeze
231
- MATCH_LTEXTQUERY = ["(".freeze, " @ ".freeze, ")".freeze].freeze
232
- MATCH_ANY_LTEXTQUERY = ["(".freeze, " ?@ ".freeze, ")".freeze].freeze
227
+ ASCENDANT = ['(', ' @> ', ')'].freeze
228
+ FIND_ASCENDANT = ['(', ' ?@> ', ')'].freeze
229
+ DESCENDANT = ['(', ' <@ ', ')'].freeze
230
+ FIND_DESCENDANT = ['(', ' ?<@ ', ')'].freeze
231
+ MATCH_ANY = ['(', ' ? ', ')'].freeze
232
+ MATCH_ANY_LQUERY = ['(', ' ?~ ', ')'].freeze
233
+ MATCH_LTEXTQUERY = ['(', ' @ ', ')'].freeze
234
+ MATCH_ANY_LTEXTQUERY = ['(', ' ?@ ', ')'].freeze
233
235
 
234
- def match(type, expr, query)
236
+ def match(_type, expr, query)
235
237
  Attribute[SQL::Types::Bool].meta(sql_expr: Sequel::SQL::BooleanExpression.new(:'~', expr, query))
236
238
  end
237
239
 
238
- def match_any(type, expr, query)
240
+ def match_any(_type, expr, query)
239
241
  array = build_array_query(query)
240
242
  Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(MATCH_ANY, expr, array))
241
243
  end
@@ -259,31 +261,31 @@ module ROM
259
261
  TypeExtensions.register(ROM::SQL::Types::PG::Array('ltree', LTree)) do
260
262
  include LTreeMethods
261
263
 
262
- def contain_any_ltextquery(type, expr, query)
264
+ def contain_any_ltextquery(_type, expr, query)
263
265
  Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::MATCH_LTEXTQUERY, expr, query))
264
266
  end
265
267
 
266
- def contain_ancestor(type, expr, query)
268
+ def contain_ancestor(_type, expr, query)
267
269
  Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::ASCENDANT, expr, query))
268
270
  end
269
271
 
270
- def contain_descendant(type, expr, query)
272
+ def contain_descendant(_type, expr, query)
271
273
  Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::DESCENDANT, expr, query))
272
274
  end
273
275
 
274
- def find_ancestor(type, expr, query)
276
+ def find_ancestor(_type, expr, query)
275
277
  Attribute[LTree].meta(sql_expr: custom_operator_expr(LTreeMethods::FIND_ASCENDANT, expr, query))
276
278
  end
277
279
 
278
- def find_descendant(type, expr, query)
280
+ def find_descendant(_type, expr, query)
279
281
  Attribute[LTree].meta(sql_expr: custom_operator_expr(LTreeMethods::FIND_DESCENDANT, expr, query))
280
282
  end
281
283
 
282
- def match_any_lquery(type, expr, query)
284
+ def match_any_lquery(_type, expr, query)
283
285
  Attribute[LTree].meta(sql_expr: custom_operator_expr(LTreeMethods::MATCH_ANY_LQUERY, expr, query))
284
286
  end
285
287
 
286
- def match_any_ltextquery(type, expr, query)
288
+ def match_any_ltextquery(_type, expr, query)
287
289
  Attribute[LTree].meta(sql_expr: custom_operator_expr(LTreeMethods::MATCH_ANY_LTEXTQUERY, expr, query))
288
290
  end
289
291
  end
@@ -291,29 +293,29 @@ module ROM
291
293
  TypeExtensions.register(LTree) do
292
294
  include LTreeMethods
293
295
 
294
- def match_ltextquery(type, expr, query)
296
+ def match_ltextquery(_type, expr, query)
295
297
  Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::MATCH_LTEXTQUERY, expr, query))
296
298
  end
297
299
 
298
- def contain_descendant(type, expr, query)
300
+ def contain_descendant(_type, expr, query)
299
301
  array = build_array_query(query, 'ltree')
300
302
  Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::DESCENDANT, expr, array))
301
303
  end
302
304
 
303
- def descendant(type, expr, query)
305
+ def descendant(_type, expr, query)
304
306
  Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::DESCENDANT, expr, query))
305
307
  end
306
308
 
307
- def contain_ascendant(type, expr, query)
309
+ def contain_ascendant(_type, expr, query)
308
310
  array = build_array_query(query, 'ltree')
309
311
  Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::ASCENDANT, expr, array))
310
312
  end
311
313
 
312
- def ascendant(type, expr, query)
314
+ def ascendant(_type, expr, query)
313
315
  Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::ASCENDANT, expr, query))
314
316
  end
315
317
 
316
- def +(type, expr, other)
318
+ def +(_type, expr, other)
317
319
  other_value = case other
318
320
  when ROM::Types::Values::TreePath
319
321
  other
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ipaddr'
2
4
 
3
5
  module ROM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sequel/core'
2
4
 
3
5
  Sequel.extension(:pg_range, :pg_range_ops)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/log_subscriber'
2
4
 
3
5
  module ROM
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/sql/extensions/sqlite/types'
2
4
  require 'rom/sql/extensions/sqlite/type_builder'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module SQL
3
5
  module SQLite
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry-types'
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
  # @api private
@@ -5,7 +7,7 @@ module ROM
5
7
  extend Initializer
6
8
  include Dry::Equalizer(:attributes, :parent_table, :options)
7
9
 
8
- DEFAULT_PARENT_KEYS = %i(id).freeze
10
+ DEFAULT_PARENT_KEYS = %i[id].freeze
9
11
 
10
12
  param :attributes
11
13
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/attribute'
2
4
  require 'rom/sql/attribute_wrapping'
3
5
 
@@ -79,7 +81,7 @@ module ROM
79
81
  # @see Attribute#qualified?
80
82
  #
81
83
  # @api private
82
- def qualified?(table_alias = nil)
84
+ def qualified?(_table_alias = nil)
83
85
  meta[:func].args.all?(&:qualified?)
84
86
  end
85
87
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'logger'
2
4
  require 'sequel/core'
3
5
 
@@ -21,7 +23,7 @@ module ROM
21
23
  adapter :sql
22
24
 
23
25
  CONNECTION_EXTENSIONS = {
24
- postgres: %i(pg_array pg_json pg_enum)
26
+ postgres: %i[pg_array pg_json pg_enum]
25
27
  }.freeze
26
28
 
27
29
  # @!attribute [r] logger
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/sql/dsl'
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
  # @api private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/sql/restriction_dsl'
2
4
 
3
5
  module ROM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/mapper_compiler'
2
4
 
3
5
  module ROM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/sql/migration/migrator'
2
4
  require 'rom/sql/migration/schema_diff'
3
5
 
@@ -97,7 +99,7 @@ module ROM
97
99
  attr_reader :migrator
98
100
 
99
101
  # @api private
100
- def initialize(uri, options = EMPTY_HASH)
102
+ def initialize(_uri, options = EMPTY_HASH)
101
103
  @migrator = create_migrator(options[:migrator])
102
104
 
103
105
  self.class.instance ||= self
@@ -139,7 +141,7 @@ module ROM
139
141
  end
140
142
 
141
143
  # @api public
142
- def auto_migrate!(conf, options = EMPTY_HASH, &block)
144
+ def auto_migrate!(conf, options = EMPTY_HASH)
143
145
  schemas = conf.relation_classes(self).map do |klass|
144
146
  klass.schema_proc.call.finalize_attributes!(gateway: self)
145
147
  end
@@ -156,7 +158,7 @@ module ROM
156
158
  return Migrator.new(connection) unless migrator_option
157
159
 
158
160
  if migrator_option.is_a?(Hash)
159
- Migrator.new(connection, migrator_option)
161
+ Migrator.new(connection, **migrator_option)
160
162
  else
161
163
  migrator_option
162
164
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module SQL
3
5
  module Migration
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathname'
2
4
 
3
5
  require 'rom/types'
@@ -65,12 +67,12 @@ module ROM
65
67
  end
66
68
 
67
69
  # @api private
68
- def auto_migrate!(gateway, schemas, options = EMPTY_HASH, &block)
70
+ def auto_migrate!(gateway, schemas, options = EMPTY_HASH)
69
71
  diff_finder = SchemaDiff.new(gateway.database_type)
70
72
 
71
73
  changes = schemas.map { |target|
72
74
  empty = SQL::Schema.define(target.name)
73
- current = target.with(inferrer.(empty, gateway))
75
+ current = target.with(**inferrer.(empty, gateway))
74
76
 
75
77
  diff_finder.(current, target)
76
78
  }.reject(&:empty?)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module SQL
3
5
  module Migration
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module SQL
3
5
  module Migration
@@ -67,8 +69,8 @@ module ROM
67
69
  if attribute.type_changed?
68
70
  from, to = attribute.current.unwrap, attribute.target.unwrap
69
71
  raise UnsupportedConversion.new(
70
- "Don't know how to convert #{ from.inspect } to #{ to.inspect }"
71
- )
72
+ "Don't know how to convert #{from.inspect} to #{to.inspect}"
73
+ )
72
74
  end
73
75
 
74
76
  if attribute.nullability_changed?
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/sql/type_serializer'
2
4
 
3
5
  module ROM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ROM::SQL.migration do
2
4
  change do
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/sql/migration/recorder'
2
4
 
3
5
  module ROM
@@ -32,7 +34,7 @@ module ROM
32
34
  operations.each do |operation|
33
35
  op, args, nested = operation
34
36
  buffer << indent << op.to_s << ' '
35
- write_arguments(buffer, *args)
37
+ write_arguments(buffer, args)
36
38
 
37
39
  if !nested.empty?
38
40
  buffer << ' do'
@@ -42,9 +44,15 @@ module ROM
42
44
  end
43
45
  end
44
46
 
45
- def write_arguments(buffer, *args, **kwargs)
47
+ def write_arguments(buffer, args)
48
+ if args.last.is_a?(::Hash)
49
+ args, options = args[0...-1], args.last
50
+ else
51
+ options = EMPTY_HASH
52
+ end
53
+
46
54
  buffer << args.map(&:inspect).join(', ')
47
- kwargs.each do |key, value|
55
+ options.each do |key, value|
48
56
  buffer << ', ' << key.to_s << ': ' << value.inspect
49
57
  end
50
58
  end
@@ -53,7 +61,7 @@ module ROM
53
61
  create_or_alter, args = op
54
62
  table_name = args[0]
55
63
 
56
- "#{ create_or_alter.to_s.sub('_table', '') }_#{ table_name }"
64
+ "#{create_or_alter.to_s.sub('_table', '')}_#{table_name}"
57
65
  end
58
66
  end
59
67
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/sql/dsl'
2
4
 
3
5
  module ROM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/sql/associations'
2
4
 
3
5
  module ROM
@@ -48,7 +50,7 @@ module ROM
48
50
  # @see ROM::Command::ClassInterface.build
49
51
  #
50
52
  # @api public
51
- def build(relation, options = EMPTY_HASH)
53
+ def build(relation, **options)
52
54
  command = super
53
55
 
54
56
  configured_assocs = command.configured_associations
@@ -146,7 +148,7 @@ module ROM
146
148
  def with_association(name, opts = EMPTY_HASH)
147
149
  self.class.build(
148
150
  relation,
149
- { **options, associations: associations.merge(name => opts) }
151
+ **options, associations: associations.merge(name => opts)
150
152
  )
151
153
  end
152
154
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module SQL
3
5
  module Plugin
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/initializer'
2
4
 
3
5
  module ROM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/plugins/relation/sql/instrumentation'
2
4
  require 'rom/plugins/relation/sql/auto_restrictions'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/sql/dsl'
2
4
  require 'rom/sql/function'
3
5
 
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake'
2
4
  load 'rom/sql/tasks/migration_tasks.rake'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/sql/types'
2
4
  require 'rom/sql/schema'
3
5
  require 'rom/sql/attribute'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/support/inflector'
2
4
  require 'rom/sql/join_dsl'
3
5
 
@@ -891,8 +893,8 @@ module ROM
891
893
  # @yieldparam relation [Array]
892
894
  #
893
895
  # @api public
894
- def lock(options = EMPTY_HASH, &block)
895
- clause = lock_clause(options)
896
+ def lock(**options, &block)
897
+ clause = lock_clause(**options)
896
898
 
897
899
  if block
898
900
  transaction do
@@ -1036,7 +1038,7 @@ module ROM
1036
1038
  stmt << ' OF ' << Array(of).join(', ') if of
1037
1039
 
1038
1040
  if skip_locked
1039
- raise ArgumentError, "SKIP LOCKED cannot be used with (NO)WAIT clause" if !wait.nil?
1041
+ raise ArgumentError, 'SKIP LOCKED cannot be used with (NO)WAIT clause' if !wait.nil?
1040
1042
 
1041
1043
  stmt << ' SKIP LOCKED'
1042
1044
  else