rom-sql 3.5.0 → 4.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -3
  3. data/LICENSE +1 -1
  4. data/README.md +1 -1
  5. data/lib/rom/plugins/relation/sql/auto_restrictions.rb +11 -10
  6. data/lib/rom/plugins/relation/sql/default_views.rb +75 -0
  7. data/lib/rom/plugins/relation/sql/instrumentation.rb +11 -10
  8. data/lib/rom/plugins/relation/sql/postgres/explain.rb +4 -4
  9. data/lib/rom/plugins/relation/sql/postgres/full_text_search.rb +18 -16
  10. data/lib/rom/plugins/relation/sql/postgres/streaming.rb +12 -9
  11. data/lib/rom/sql/associations/many_to_many.rb +7 -7
  12. data/lib/rom/sql/associations/many_to_one.rb +3 -3
  13. data/lib/rom/sql/associations/one_to_many.rb +3 -3
  14. data/lib/rom/sql/associations/one_to_one.rb +1 -1
  15. data/lib/rom/sql/associations/one_to_one_through.rb +1 -1
  16. data/lib/rom/sql/associations/self_ref.rb +1 -1
  17. data/lib/rom/sql/associations.rb +5 -5
  18. data/lib/rom/sql/attribute.rb +9 -9
  19. data/lib/rom/sql/attribute_aliasing.rb +2 -3
  20. data/lib/rom/sql/commands/create.rb +5 -4
  21. data/lib/rom/sql/commands/delete.rb +2 -2
  22. data/lib/rom/sql/commands/update.rb +5 -4
  23. data/lib/rom/sql/commands.rb +4 -4
  24. data/lib/rom/sql/dsl.rb +3 -3
  25. data/lib/rom/sql/errors.rb +3 -3
  26. data/lib/rom/sql/extensions/active_support_notifications.rb +4 -4
  27. data/lib/rom/sql/extensions/mysql/type_builder.rb +5 -5
  28. data/lib/rom/sql/extensions/mysql.rb +1 -1
  29. data/lib/rom/sql/extensions/postgres/commands.rb +13 -31
  30. data/lib/rom/sql/extensions/postgres/type_builder.rb +28 -31
  31. data/lib/rom/sql/extensions/postgres/type_serializer.rb +24 -24
  32. data/lib/rom/sql/extensions/postgres/types/array.rb +4 -4
  33. data/lib/rom/sql/extensions/postgres/types/array_types.rb +1 -1
  34. data/lib/rom/sql/extensions/postgres/types/geometric.rb +27 -27
  35. data/lib/rom/sql/extensions/postgres/types/json.rb +9 -9
  36. data/lib/rom/sql/extensions/postgres/types/ltree.rb +61 -34
  37. data/lib/rom/sql/extensions/postgres/types/network.rb +2 -2
  38. data/lib/rom/sql/extensions/postgres/types/range.rb +25 -25
  39. data/lib/rom/sql/extensions/postgres/types.rb +14 -14
  40. data/lib/rom/sql/extensions/postgres.rb +6 -6
  41. data/lib/rom/sql/extensions/rails_log_subscriber.rb +3 -3
  42. data/lib/rom/sql/extensions/sqlite/types.rb +1 -1
  43. data/lib/rom/sql/extensions/sqlite.rb +2 -2
  44. data/lib/rom/sql/extensions.rb +6 -6
  45. data/lib/rom/sql/foreign_key.rb +3 -1
  46. data/lib/rom/sql/function.rb +17 -16
  47. data/lib/rom/sql/gateway.rb +44 -17
  48. data/lib/rom/sql/group_dsl.rb +1 -1
  49. data/lib/rom/sql/index.rb +2 -0
  50. data/lib/rom/sql/join_dsl.rb +1 -1
  51. data/lib/rom/sql/mapper_compiler.rb +2 -2
  52. data/lib/rom/sql/migration/migrator.rb +11 -11
  53. data/lib/rom/sql/migration/runner.rb +3 -3
  54. data/lib/rom/sql/migration/schema_diff.rb +7 -8
  55. data/lib/rom/sql/migration/writer.rb +12 -12
  56. data/lib/rom/sql/migration.rb +4 -8
  57. data/lib/rom/sql/order_dsl.rb +1 -1
  58. data/lib/rom/sql/plugin/associates.rb +49 -11
  59. data/lib/rom/sql/plugin/pagination.rb +5 -3
  60. data/lib/rom/sql/plugin/schema_indexes.rb +35 -0
  61. data/lib/rom/sql/plugins.rb +9 -6
  62. data/lib/rom/sql/projection_dsl.rb +2 -2
  63. data/lib/rom/sql/rake_task.rb +2 -2
  64. data/lib/rom/sql/relation/reading.rb +34 -27
  65. data/lib/rom/sql/relation/writing.rb +11 -10
  66. data/lib/rom/sql/relation.rb +57 -89
  67. data/lib/rom/sql/restriction_dsl.rb +1 -1
  68. data/lib/rom/sql/schema/attributes_inferrer.rb +3 -3
  69. data/lib/rom/sql/schema/dsl.rb +4 -2
  70. data/lib/rom/sql/schema/index_dsl.rb +3 -5
  71. data/lib/rom/sql/schema/inferrer.rb +25 -23
  72. data/lib/rom/sql/schema/type_builder.rb +2 -2
  73. data/lib/rom/sql/schema.rb +9 -21
  74. data/lib/rom/sql/spec/support.rb +5 -5
  75. data/lib/rom/sql/tasks/migration_tasks.rake +12 -12
  76. data/lib/rom/sql/transaction.rb +4 -2
  77. data/lib/rom/sql/type_extensions.rb +3 -1
  78. data/lib/rom/sql/type_serializer.rb +10 -10
  79. data/lib/rom/sql/types.rb +4 -4
  80. data/lib/rom/sql/version.rb +1 -1
  81. data/lib/rom/sql/wrap.rb +1 -1
  82. data/lib/rom/sql.rb +13 -14
  83. data/lib/rom/types/values.rb +2 -2
  84. data/lib/rom-sql.rb +1 -1
  85. metadata +14 -24
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom/types/values'
3
+ require "rom/types/values"
4
4
 
5
5
  module ROM
6
6
  module SQL
@@ -9,11 +9,9 @@ module ROM
9
9
  module Types
10
10
  # @see https://www.postgresql.org/docs/current/static/ltree.html
11
11
 
12
- LTree = Type('ltree') do
12
+ LTree = Type("ltree") do
13
13
  SQL::Types.define(ROM::Types::Values::TreePath) do
14
- input do |label_path|
15
- label_path.to_s
16
- end
14
+ input(&:to_s)
17
15
 
18
16
  output do |label_path|
19
17
  ROM::Types::Values::TreePath.new(label_path.to_s) if label_path
@@ -122,8 +120,14 @@ module ROM
122
120
  # # Translates to ||
123
121
  # #
124
122
  # # @example
125
- # # people.select { (ltree_tags + ROM::Types::Values::TreePath.new('Moscu')).as(:ltree_tags) }.where { name.is('Jade Doe') }
126
- # # people.select { (ltree_tags + 'Moscu').as(:ltree_tags) }.where { name.is('Jade Doe') }
123
+ # # people.select {
124
+ # # (ltree_tags + ROM::Types::Values::TreePath.new('Moscu')).as(:ltree_tags)
125
+ # # }.where { name.is('Jade Doe') }
126
+ # #
127
+ # # people.select {
128
+ # # (ltree_tags + 'Moscu').as(:ltree_tags)
129
+ # # }
130
+ # # .where { name.is('Jade Doe') }
127
131
  # #
128
132
  # # @param [LTree, String] keys
129
133
  # #
@@ -224,17 +228,18 @@ module ROM
224
228
  #
225
229
  # end
226
230
  module LTreeMethods
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
231
+ ASCENDANT = ["(", " @> ", ")"].freeze
232
+ FIND_ASCENDANT = ["(", " ?@> ", ")"].freeze
233
+ DESCENDANT = ["(", " <@ ", ")"].freeze
234
+ FIND_DESCENDANT = ["(", " ?<@ ", ")"].freeze
235
+ MATCH_ANY = ["(", " ? ", ")"].freeze
236
+ MATCH_ANY_LQUERY = ["(", " ?~ ", ")"].freeze
237
+ MATCH_LTEXTQUERY = ["(", " @ ", ")"].freeze
238
+ MATCH_ANY_LTEXTQUERY = ["(", " ?@ ", ")"].freeze
235
239
 
236
240
  def match(_type, expr, query)
237
- Attribute[SQL::Types::Bool].meta(sql_expr: Sequel::SQL::BooleanExpression.new(:'~', expr, query))
241
+ Attribute[SQL::Types::Bool].meta(sql_expr: Sequel::SQL::BooleanExpression.new(:~,
242
+ expr, query))
238
243
  end
239
244
 
240
245
  def match_any(_type, expr, query)
@@ -248,45 +253,56 @@ module ROM
248
253
  Sequel::SQL::PlaceholderLiteralString.new(string, [expr, query])
249
254
  end
250
255
 
251
- def build_array_query(query, array_type = 'lquery')
256
+ def build_array_query(query, array_type = "lquery")
252
257
  case query
253
258
  when ::Array
254
259
  ROM::SQL::Types::PG::Array(array_type)[query]
255
260
  when ::String
256
- ROM::SQL::Types::PG::Array(array_type)[query.split(',')]
261
+ ROM::SQL::Types::PG::Array(array_type)[query.split(",")]
257
262
  end
258
263
  end
259
264
  end
260
265
 
261
- TypeExtensions.register(ROM::SQL::Types::PG::Array('ltree', LTree)) do
266
+ TypeExtensions.register(ROM::SQL::Types::PG::Array("ltree", LTree)) do
262
267
  include LTreeMethods
263
268
 
264
269
  def contain_any_ltextquery(_type, expr, query)
265
- Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::MATCH_LTEXTQUERY, expr, query))
270
+ Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(
271
+ LTreeMethods::MATCH_LTEXTQUERY, expr, query
272
+ ))
266
273
  end
267
274
 
268
275
  def contain_ancestor(_type, expr, query)
269
- Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::ASCENDANT, expr, query))
276
+ Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(
277
+ LTreeMethods::ASCENDANT, expr, query
278
+ ))
270
279
  end
271
280
 
272
281
  def contain_descendant(_type, expr, query)
273
- Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::DESCENDANT, expr, query))
282
+ Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(
283
+ LTreeMethods::DESCENDANT, expr, query
284
+ ))
274
285
  end
275
286
 
276
287
  def find_ancestor(_type, expr, query)
277
- Attribute[LTree].meta(sql_expr: custom_operator_expr(LTreeMethods::FIND_ASCENDANT, expr, query))
288
+ Attribute[LTree].meta(sql_expr: custom_operator_expr(LTreeMethods::FIND_ASCENDANT,
289
+ expr, query))
278
290
  end
279
291
 
280
292
  def find_descendant(_type, expr, query)
281
- Attribute[LTree].meta(sql_expr: custom_operator_expr(LTreeMethods::FIND_DESCENDANT, expr, query))
293
+ Attribute[LTree].meta(sql_expr: custom_operator_expr(LTreeMethods::FIND_DESCENDANT,
294
+ expr, query))
282
295
  end
283
296
 
284
297
  def match_any_lquery(_type, expr, query)
285
- Attribute[LTree].meta(sql_expr: custom_operator_expr(LTreeMethods::MATCH_ANY_LQUERY, expr, query))
298
+ Attribute[LTree].meta(sql_expr: custom_operator_expr(LTreeMethods::MATCH_ANY_LQUERY,
299
+ expr, query))
286
300
  end
287
301
 
288
302
  def match_any_ltextquery(_type, expr, query)
289
- Attribute[LTree].meta(sql_expr: custom_operator_expr(LTreeMethods::MATCH_ANY_LTEXTQUERY, expr, query))
303
+ Attribute[LTree].meta(sql_expr: custom_operator_expr(
304
+ LTreeMethods::MATCH_ANY_LTEXTQUERY, expr, query
305
+ ))
290
306
  end
291
307
  end
292
308
 
@@ -294,25 +310,35 @@ module ROM
294
310
  include LTreeMethods
295
311
 
296
312
  def match_ltextquery(_type, expr, query)
297
- Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::MATCH_LTEXTQUERY, expr, query))
313
+ Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(
314
+ LTreeMethods::MATCH_LTEXTQUERY, expr, query
315
+ ))
298
316
  end
299
317
 
300
318
  def contain_descendant(_type, expr, query)
301
- array = build_array_query(query, 'ltree')
302
- Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::DESCENDANT, expr, array))
319
+ array = build_array_query(query, "ltree")
320
+ Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(
321
+ LTreeMethods::DESCENDANT, expr, array
322
+ ))
303
323
  end
304
324
 
305
325
  def descendant(_type, expr, query)
306
- Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::DESCENDANT, expr, query))
326
+ Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(
327
+ LTreeMethods::DESCENDANT, expr, query
328
+ ))
307
329
  end
308
330
 
309
331
  def contain_ascendant(_type, expr, query)
310
- array = build_array_query(query, 'ltree')
311
- Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::ASCENDANT, expr, array))
332
+ array = build_array_query(query, "ltree")
333
+ Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(
334
+ LTreeMethods::ASCENDANT, expr, array
335
+ ))
312
336
  end
313
337
 
314
338
  def ascendant(_type, expr, query)
315
- Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::ASCENDANT, expr, query))
339
+ Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(
340
+ LTreeMethods::ASCENDANT, expr, query
341
+ ))
316
342
  end
317
343
 
318
344
  def +(_type, expr, other)
@@ -322,7 +348,8 @@ module ROM
322
348
  else
323
349
  ROM::Types::Values::TreePath.new(other)
324
350
  end
325
- Attribute[LTree].meta(sql_expr: Sequel::SQL::StringExpression.new(:'||', expr, other_value.to_s))
351
+ Attribute[LTree].meta(sql_expr: Sequel::SQL::StringExpression.new(:"||", expr,
352
+ other_value.to_s))
326
353
  end
327
354
  end
328
355
  end
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ipaddr'
3
+ require "ipaddr"
4
4
 
5
5
  module ROM
6
6
  module SQL
7
7
  module Postgres
8
8
  module Types
9
- IPAddress = Type('inet') do
9
+ IPAddress = Type("inet") do
10
10
  read = SQL::Types.Constructor(IPAddr) { |ip| IPAddr.new(ip.to_s) }
11
11
 
12
12
  SQL::Types.Constructor(IPAddr, &:to_s).meta(read: read)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'sequel/core'
3
+ require "sequel/core"
4
4
 
5
5
  Sequel.extension(:pg_range, :pg_range_ops)
6
6
 
@@ -9,10 +9,10 @@ module ROM
9
9
  module Postgres
10
10
  module Values
11
11
  Range = ::Struct.new(:lower, :upper, :bounds) do
12
- PAREN_LEFT = '('.freeze
13
- PAREN_RIGHT = ')'.freeze
12
+ PAREN_LEFT = "("
13
+ PAREN_RIGHT = ")"
14
14
 
15
- def initialize(lower, upper, bounds = :'[)')
15
+ def initialize(lower, upper, bounds = :"[)")
16
16
  super
17
17
  end
18
18
 
@@ -33,22 +33,22 @@ module ROM
33
33
 
34
34
  @range_parsers = {
35
35
  int4range: Sequel::Postgres::PGRange::Parser.new(
36
- 'int4range', SQL::Types::Coercible::Integer
36
+ "int4range", SQL::Types::Coercible::Integer
37
37
  ),
38
38
  int8range: Sequel::Postgres::PGRange::Parser.new(
39
- 'int8range', SQL::Types::Coercible::Integer
39
+ "int8range", SQL::Types::Coercible::Integer
40
40
  ),
41
- numrange: Sequel::Postgres::PGRange::Parser.new(
42
- 'numrange', SQL::Types::Coercible::Integer
41
+ numrange: Sequel::Postgres::PGRange::Parser.new(
42
+ "numrange", SQL::Types::Coercible::Integer
43
43
  ),
44
- tsrange: Sequel::Postgres::PGRange::Parser.new(
45
- 'tsrange', ::Time.method(:parse)
44
+ tsrange: Sequel::Postgres::PGRange::Parser.new(
45
+ "tsrange", ::Time.method(:parse)
46
46
  ),
47
47
  tstzrange: Sequel::Postgres::PGRange::Parser.new(
48
- 'tstzrange', ::Time.method(:parse)
48
+ "tstzrange", ::Time.method(:parse)
49
49
  ),
50
50
  daterange: Sequel::Postgres::PGRange::Parser.new(
51
- 'daterange', ::Date.method(:parse)
51
+ "daterange", ::Date.method(:parse)
52
52
  )
53
53
  }.freeze
54
54
 
@@ -58,7 +58,7 @@ module ROM
58
58
  pg_range =
59
59
  if value.is_a?(Sequel::Postgres::PGRange)
60
60
  value
61
- elsif value && value.respond_to?(:to_s)
61
+ elsif value.respond_to?(:to_s)
62
62
  @range_parsers[name].(value.to_s)
63
63
  else
64
64
  value
@@ -67,9 +67,9 @@ module ROM
67
67
  Values::Range.new(
68
68
  pg_range.begin,
69
69
  pg_range.end,
70
- [pg_range.exclude_begin? ? :'(' : :'[',
71
- pg_range.exclude_end? ? :')' : :']']
72
- .join('').to_sym
70
+ [pg_range.exclude_begin? ? :"(" : :"[",
71
+ pg_range.exclude_end? ? :")" : :"]"]
72
+ .join("").to_sym
73
73
  )
74
74
  end
75
75
  end
@@ -78,23 +78,23 @@ module ROM
78
78
  def self.range(name, read_type)
79
79
  Type(name) do
80
80
  type = SQL::Types.Nominal(Values::Range).constructor do |range|
81
- format('%s%s,%s%s',
82
- range.exclude_begin? ? :'(' : :'[',
81
+ format("%s%s,%s%s",
82
+ range.exclude_begin? ? :"(" : :"[",
83
83
  range.lower,
84
84
  range.upper,
85
- range.exclude_end? ? :')' : :']')
85
+ range.exclude_end? ? :")" : :"]")
86
86
  end
87
87
 
88
88
  type.meta(read: read_type)
89
89
  end
90
90
  end
91
91
 
92
- Int4Range = range('int4range', range_read_type(:int4range))
93
- Int8Range = range('int8range', range_read_type(:int8range))
94
- NumRange = range('numrange', range_read_type(:numrange))
95
- TsRange = range('tsrange', range_read_type(:tsrange))
96
- TsTzRange = range('tstzrange', range_read_type(:tstzrange))
97
- DateRange = range('daterange', range_read_type(:daterange))
92
+ Int4Range = range("int4range", range_read_type(:int4range))
93
+ Int8Range = range("int8range", range_read_type(:int8range))
94
+ NumRange = range("numrange", range_read_type(:numrange))
95
+ TsRange = range("tsrange", range_read_type(:tsrange))
96
+ TsTzRange = range("tstzrange", range_read_type(:tstzrange))
97
+ DateRange = range("daterange", range_read_type(:daterange))
98
98
 
99
99
  module RangeOperators
100
100
  def contain(_type, expr, value)
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'sequel/core'
3
+ require "sequel/core"
4
4
 
5
- require 'rom/sql/type_extensions'
5
+ require "rom/sql/type_extensions"
6
6
 
7
7
  Sequel.extension(:pg_hstore)
8
8
 
@@ -11,25 +11,25 @@ module ROM
11
11
  module Postgres
12
12
  module Types
13
13
  def self.Type(name, type = yield)
14
- type.meta(db_type: name, database: 'postgres')
14
+ type.meta(db_type: name, database: "postgres")
15
15
  end
16
16
 
17
- UUID = Type('uuid', SQL::Types::String)
17
+ UUID = Type("uuid", SQL::Types::String)
18
18
 
19
- HStore = Type('hstore') do
19
+ HStore = Type("hstore") do
20
20
  read = SQL::Types.Constructor(Hash, &:to_hash)
21
21
 
22
22
  SQL::Types.Constructor(Hash, &Sequel.method(:hstore))
23
23
  .meta(read: read)
24
24
  end
25
25
 
26
- Bytea = Type('bytea') do
26
+ Bytea = Type("bytea") do
27
27
  SQL::Types.Constructor(Sequel::SQL::Blob, &Sequel::SQL::Blob.method(:new))
28
28
  end
29
29
 
30
- Money = Type('money', SQL::Types::Decimal)
30
+ Money = Type("money", SQL::Types::Decimal)
31
31
 
32
- XML = Type('xml', SQL::Types::String)
32
+ XML = Type("xml", SQL::Types::String)
33
33
  end
34
34
  end
35
35
 
@@ -39,9 +39,9 @@ module ROM
39
39
  end
40
40
  end
41
41
 
42
- require 'rom/sql/extensions/postgres/types/array'
43
- require 'rom/sql/extensions/postgres/types/json'
44
- require 'rom/sql/extensions/postgres/types/geometric'
45
- require 'rom/sql/extensions/postgres/types/network'
46
- require 'rom/sql/extensions/postgres/types/range'
47
- require 'rom/sql/extensions/postgres/types/ltree'
42
+ require "rom/sql/extensions/postgres/types/array"
43
+ require "rom/sql/extensions/postgres/types/json"
44
+ require "rom/sql/extensions/postgres/types/geometric"
45
+ require "rom/sql/extensions/postgres/types/network"
46
+ require "rom/sql/extensions/postgres/types/range"
47
+ require "rom/sql/extensions/postgres/types/ltree"
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom/sql/extensions/postgres/commands'
4
- require 'rom/sql/extensions/postgres/types'
5
- require 'rom/sql/extensions/postgres/type_builder'
6
- require 'rom/sql/extensions/postgres/type_serializer'
7
- require 'rom/plugins/relation/sql/postgres/explain'
8
- require 'rom/plugins/relation/sql/postgres/full_text_search'
3
+ require "rom/sql/extensions/postgres/commands"
4
+ require "rom/sql/extensions/postgres/types"
5
+ require "rom/sql/extensions/postgres/type_builder"
6
+ require "rom/sql/extensions/postgres/type_serializer"
7
+ require "rom/plugins/relation/sql/postgres/explain"
8
+ require "rom/plugins/relation/sql/postgres/full_text_search"
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/log_subscriber'
3
+ require "active_support/log_subscriber"
4
4
 
5
5
  module ROM
6
6
  module SQL
@@ -10,8 +10,8 @@ module ROM
10
10
 
11
11
  payload = event.payload
12
12
 
13
- name = format('%s (%.1fms)', payload[:name], event.duration)
14
- sql = payload[:sql].squeeze(' ')
13
+ name = format("%s (%.1fms)", payload[:name], event.duration)
14
+ sql = payload[:sql].squeeze(" ")
15
15
  binds = payload[:binds].to_a.inspect if payload[:binds]
16
16
 
17
17
  if odd?
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry-types'
3
+ require "dry-types"
4
4
 
5
5
  module ROM
6
6
  module SQL
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom/sql/extensions/sqlite/types'
4
- require 'rom/sql/extensions/sqlite/type_builder'
3
+ require "rom/sql/extensions/sqlite/types"
4
+ require "rom/sql/extensions/sqlite/type_builder"
@@ -1,29 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/core/extensions'
3
+ require "dry/core/extensions"
4
4
 
5
5
  module ROM
6
6
  module SQL
7
7
  extend Dry::Core::Extensions
8
8
 
9
9
  register_extension(:postgres) do
10
- require 'rom/sql/extensions/postgres'
10
+ require "rom/sql/extensions/postgres"
11
11
  end
12
12
 
13
13
  register_extension(:mysql) do
14
- require 'rom/sql/extensions/mysql'
14
+ require "rom/sql/extensions/mysql"
15
15
  end
16
16
 
17
17
  register_extension(:sqlite) do
18
- require 'rom/sql/extensions/sqlite'
18
+ require "rom/sql/extensions/sqlite"
19
19
  end
20
20
 
21
21
  register_extension(:active_support_notifications) do
22
- require 'rom/sql/extensions/active_support_notifications'
22
+ require "rom/sql/extensions/active_support_notifications"
23
23
  end
24
24
 
25
25
  register_extension(:rails_log_subscriber) do
26
- require 'rom/sql/extensions/rails_log_subscriber'
26
+ require "rom/sql/extensions/rails_log_subscriber"
27
27
  end
28
28
  end
29
29
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "dry/core/equalizer"
4
+
3
5
  module ROM
4
6
  module SQL
5
7
  # @api private
@@ -11,7 +13,7 @@ module ROM
11
13
 
12
14
  param :attributes
13
15
 
14
- param :parent_table, type: Dry::Types['strict.symbol']
16
+ param :parent_table, type: Dry::Types["strict.symbol"]
15
17
 
16
18
  option :parent_keys, default: -> { DEFAULT_PARENT_KEYS }
17
19
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom/attribute'
4
- require 'rom/sql/attribute_wrapping'
3
+ require "rom/attribute"
4
+ require "rom/sql/attribute_wrapping"
5
5
 
6
6
  module ROM
7
7
  module SQL
@@ -15,14 +15,14 @@ module ROM
15
15
  # @api private
16
16
  def frame_limit(value)
17
17
  case value
18
- when :current then 'CURRENT ROW'
19
- when :start then 'UNBOUNDED PRECEDING'
20
- when :end then 'UNBOUNDED FOLLOWING'
18
+ when :current then "CURRENT ROW"
19
+ when :start then "UNBOUNDED PRECEDING"
20
+ when :end then "UNBOUNDED FOLLOWING"
21
21
  else
22
- if value > 0
23
- "#{ value } FOLLOWING"
22
+ if value.positive?
23
+ "#{value} FOLLOWING"
24
24
  else
25
- "#{ value.abs } PRECEDING"
25
+ "#{value.abs} PRECEDING"
26
26
  end
27
27
  end
28
28
  end
@@ -32,15 +32,16 @@ module ROM
32
32
 
33
33
  # @api private
34
34
  WINDOW_FRAMES = Hash.new do |cache, frame|
35
- type = frame.key?(:rows) ? 'ROWS' : 'RANGE'
35
+ type = frame.key?(:rows) ? "ROWS" : "RANGE"
36
36
  bounds = frame[:rows] || frame[:range]
37
- cache[frame] = "#{ type } BETWEEN #{ frame_limit(bounds[0]) } AND #{ frame_limit(bounds[1]) }"
37
+ cache[frame] =
38
+ "#{type} BETWEEN #{frame_limit(bounds[0])} AND #{frame_limit(bounds[1])}"
38
39
  end
39
40
 
40
41
  WINDOW_FRAMES[nil] = nil
41
- WINDOW_FRAMES[:all] = WINDOW_FRAMES[rows: [:start, :end]]
42
- WINDOW_FRAMES[:rows] = WINDOW_FRAMES[rows: [:start, :current]]
43
- WINDOW_FRAMES[range: :current] = WINDOW_FRAMES[range: [:current, :current]]
42
+ WINDOW_FRAMES[:all] = WINDOW_FRAMES[rows: %i[start end]]
43
+ WINDOW_FRAMES[:rows] = WINDOW_FRAMES[rows: %i[start current]]
44
+ WINDOW_FRAMES[range: :current] = WINDOW_FRAMES[range: %i[current current]]
44
45
 
45
46
  # Return a new attribute with an alias
46
47
  #
@@ -104,7 +105,7 @@ module ROM
104
105
  # @api public
105
106
  def is(other)
106
107
  ::ROM::SQL::Attribute[::ROM::SQL::Types::Bool].meta(
107
- sql_expr: ::Sequel::SQL::BooleanExpression.new(:'=', func, other)
108
+ sql_expr: ::Sequel::SQL::BooleanExpression.new(:"=", func, other)
108
109
  )
109
110
  end
110
111
 
@@ -185,7 +186,7 @@ module ROM
185
186
  def case(mapping)
186
187
  mapping = mapping.dup
187
188
  otherwise = mapping.delete(:else) do
188
- raise ArgumentError, 'provide the default case using the :else keyword'
189
+ raise ArgumentError, "provide the default case using the :else keyword"
189
190
  end
190
191
 
191
192
  Attribute[type].meta(sql_expr: ::Sequel.case(mapping, otherwise))
@@ -209,7 +210,7 @@ module ROM
209
210
  def filter(condition = Undefined, &block)
210
211
  if block
211
212
  conditions = schema.restriction(&block)
212
- conditions = conditions & condition unless condition.equal?(Undefined)
213
+ conditions &= condition unless condition.equal?(Undefined)
213
214
  else
214
215
  conditions = condition
215
216
  end