sequel 5.107.0 → 5.108.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 (131) hide show
  1. checksums.yaml +4 -4
  2. data/bin/sequel +5 -5
  3. data/lib/sequel/adapters/ado.rb +1 -1
  4. data/lib/sequel/adapters/ibmdb.rb +2 -2
  5. data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -1
  6. data/lib/sequel/adapters/jdbc/mysql.rb +1 -1
  7. data/lib/sequel/adapters/jdbc.rb +2 -2
  8. data/lib/sequel/adapters/mock.rb +1 -1
  9. data/lib/sequel/adapters/mysql.rb +7 -2
  10. data/lib/sequel/adapters/mysql2.rb +5 -4
  11. data/lib/sequel/adapters/postgres.rb +37 -37
  12. data/lib/sequel/adapters/shared/db2.rb +2 -2
  13. data/lib/sequel/adapters/shared/mssql.rb +4 -4
  14. data/lib/sequel/adapters/shared/mysql.rb +2 -2
  15. data/lib/sequel/adapters/shared/postgres.rb +67 -44
  16. data/lib/sequel/adapters/shared/sqlite.rb +3 -3
  17. data/lib/sequel/adapters/utils/emulate_offset_with_reverse_and_count.rb +1 -1
  18. data/lib/sequel/adapters/utils/mysql_mysql2.rb +11 -1
  19. data/lib/sequel/connection_pool/sharded_single.rb +1 -1
  20. data/lib/sequel/connection_pool/sharded_threaded.rb +7 -5
  21. data/lib/sequel/connection_pool/sharded_timed_queue.rb +3 -3
  22. data/lib/sequel/connection_pool/threaded.rb +9 -7
  23. data/lib/sequel/connection_pool/timed_queue.rb +2 -2
  24. data/lib/sequel/connection_pool.rb +3 -3
  25. data/lib/sequel/core.rb +30 -22
  26. data/lib/sequel/database/connecting.rb +1 -1
  27. data/lib/sequel/database/features.rb +1 -1
  28. data/lib/sequel/database/misc.rb +7 -7
  29. data/lib/sequel/database/query.rb +2 -2
  30. data/lib/sequel/database/schema_generator.rb +4 -4
  31. data/lib/sequel/database/schema_methods.rb +2 -2
  32. data/lib/sequel/database/transactions.rb +4 -4
  33. data/lib/sequel/dataset/actions.rb +1 -1
  34. data/lib/sequel/dataset/features.rb +4 -4
  35. data/lib/sequel/dataset/graph.rb +1 -1
  36. data/lib/sequel/dataset/misc.rb +3 -3
  37. data/lib/sequel/dataset/prepared_statements.rb +2 -2
  38. data/lib/sequel/dataset/query.rb +8 -8
  39. data/lib/sequel/dataset/sql.rb +18 -10
  40. data/lib/sequel/dataset.rb +2 -2
  41. data/lib/sequel/deprecated.rb +2 -2
  42. data/lib/sequel/exceptions.rb +2 -2
  43. data/lib/sequel/extensions/_pretty_table.rb +1 -1
  44. data/lib/sequel/extensions/async_thread_pool.rb +3 -3
  45. data/lib/sequel/extensions/auto_cast_date_and_time.rb +2 -2
  46. data/lib/sequel/extensions/blank.rb +2 -2
  47. data/lib/sequel/extensions/constraint_validations.rb +1 -1
  48. data/lib/sequel/extensions/core_refinements.rb +8 -8
  49. data/lib/sequel/extensions/date_arithmetic.rb +1 -1
  50. data/lib/sequel/extensions/datetime_parse_to_time.rb +2 -2
  51. data/lib/sequel/extensions/duplicate_columns_handler.rb +2 -2
  52. data/lib/sequel/extensions/graph_each.rb +1 -1
  53. data/lib/sequel/extensions/index_caching.rb +1 -1
  54. data/lib/sequel/extensions/inflector.rb +5 -5
  55. data/lib/sequel/extensions/is_distinct_from.rb +2 -2
  56. data/lib/sequel/extensions/lit_require_frozen.rb +3 -3
  57. data/lib/sequel/extensions/migration.rb +21 -7
  58. data/lib/sequel/extensions/named_timezones.rb +8 -8
  59. data/lib/sequel/extensions/pg_array.rb +9 -8
  60. data/lib/sequel/extensions/pg_array_ops.rb +69 -14
  61. data/lib/sequel/extensions/pg_auto_parameterize.rb +2 -2
  62. data/lib/sequel/extensions/pg_auto_parameterize_in_array.rb +3 -3
  63. data/lib/sequel/extensions/pg_enum.rb +2 -2
  64. data/lib/sequel/extensions/pg_extended_date_support.rb +5 -5
  65. data/lib/sequel/extensions/pg_extended_integer_support.rb +1 -1
  66. data/lib/sequel/extensions/pg_hstore.rb +2 -2
  67. data/lib/sequel/extensions/pg_hstore_ops.rb +5 -5
  68. data/lib/sequel/extensions/pg_inet.rb +2 -2
  69. data/lib/sequel/extensions/pg_inet_ops.rb +2 -2
  70. data/lib/sequel/extensions/pg_interval.rb +6 -6
  71. data/lib/sequel/extensions/pg_json.rb +4 -4
  72. data/lib/sequel/extensions/pg_json_ops.rb +11 -11
  73. data/lib/sequel/extensions/pg_range.rb +6 -6
  74. data/lib/sequel/extensions/pg_range_ops.rb +7 -7
  75. data/lib/sequel/extensions/pg_row.rb +4 -4
  76. data/lib/sequel/extensions/pg_row_ops.rb +6 -6
  77. data/lib/sequel/extensions/provenance.rb +2 -2
  78. data/lib/sequel/extensions/query.rb +2 -2
  79. data/lib/sequel/extensions/s.rb +2 -2
  80. data/lib/sequel/extensions/schema_dumper.rb +4 -4
  81. data/lib/sequel/extensions/sequel_4_dataset_methods.rb +2 -0
  82. data/lib/sequel/extensions/sql_comments.rb +1 -1
  83. data/lib/sequel/extensions/sql_log_normalizer.rb +1 -1
  84. data/lib/sequel/extensions/sqlite_json_ops.rb +2 -2
  85. data/lib/sequel/extensions/string_agg.rb +5 -5
  86. data/lib/sequel/extensions/symbol_aref.rb +3 -3
  87. data/lib/sequel/extensions/symbol_aref_refinement.rb +3 -3
  88. data/lib/sequel/extensions/symbol_as_refinement.rb +2 -2
  89. data/lib/sequel/extensions/transaction_connection_validator.rb +1 -1
  90. data/lib/sequel/model/associations.rb +17 -17
  91. data/lib/sequel/model/base.rb +19 -11
  92. data/lib/sequel/model/inflections.rb +1 -1
  93. data/lib/sequel/model/plugins.rb +2 -2
  94. data/lib/sequel/model.rb +2 -2
  95. data/lib/sequel/plugins/association_pks.rb +1 -1
  96. data/lib/sequel/plugins/association_proxies.rb +4 -4
  97. data/lib/sequel/plugins/auto_restrict_eager_graph.rb +2 -0
  98. data/lib/sequel/plugins/caching.rb +1 -1
  99. data/lib/sequel/plugins/class_table_inheritance.rb +1 -1
  100. data/lib/sequel/plugins/column_encryption.rb +10 -10
  101. data/lib/sequel/plugins/concurrent_eager_loading.rb +2 -2
  102. data/lib/sequel/plugins/csv_serializer.rb +2 -2
  103. data/lib/sequel/plugins/deprecated_associations.rb +2 -2
  104. data/lib/sequel/plugins/eager_each.rb +1 -1
  105. data/lib/sequel/plugins/finder.rb +1 -1
  106. data/lib/sequel/plugins/forbid_lazy_load.rb +3 -3
  107. data/lib/sequel/plugins/insert_conflict.rb +1 -1
  108. data/lib/sequel/plugins/insert_returning_select.rb +1 -1
  109. data/lib/sequel/plugins/json_serializer.rb +4 -4
  110. data/lib/sequel/plugins/lazy_attributes.rb +1 -1
  111. data/lib/sequel/plugins/many_through_many.rb +1 -1
  112. data/lib/sequel/plugins/pg_array_associations.rb +4 -4
  113. data/lib/sequel/plugins/pg_auto_constraint_validations.rb +3 -3
  114. data/lib/sequel/plugins/pg_eager_any_typed_array.rb +2 -2
  115. data/lib/sequel/plugins/prepared_statements.rb +2 -2
  116. data/lib/sequel/plugins/serialization.rb +1 -1
  117. data/lib/sequel/plugins/sharding.rb +1 -1
  118. data/lib/sequel/plugins/single_table_inheritance.rb +1 -1
  119. data/lib/sequel/plugins/skip_saving_columns.rb +2 -2
  120. data/lib/sequel/plugins/split_values.rb +1 -1
  121. data/lib/sequel/plugins/sql_comments.rb +8 -8
  122. data/lib/sequel/plugins/subclasses.rb +6 -6
  123. data/lib/sequel/plugins/subset_conditions.rb +2 -2
  124. data/lib/sequel/plugins/tactical_eager_loading.rb +1 -1
  125. data/lib/sequel/plugins/throw_failures.rb +2 -2
  126. data/lib/sequel/plugins/unused_associations.rb +5 -5
  127. data/lib/sequel/plugins/validation_helpers.rb +1 -1
  128. data/lib/sequel/plugins/xml_serializer.rb +2 -0
  129. data/lib/sequel/sql.rb +11 -11
  130. data/lib/sequel/version.rb +1 -1
  131. metadata +1 -1
@@ -7,11 +7,11 @@
7
7
  # Sequel.extension :blank
8
8
 
9
9
  [FalseClass, Object, NilClass, Numeric, String, TrueClass].each do |klass|
10
- # :nocov:
10
+ # simplecov:disable
11
11
  if klass.method_defined?(:blank?)
12
12
  klass.send(:alias_method, :blank?, :blank?)
13
13
  end
14
- # :nocov:
14
+ # simplecov:enable
15
15
  end
16
16
 
17
17
  class FalseClass
@@ -95,7 +95,7 @@
95
95
  # integers, and a range of integers.
96
96
  # * There are like and ilike validations, which are similar to the format
97
97
  # validation but use a case sensitive or case insensitive LIKE pattern. LIKE
98
- # patters are very simple, so many regexp patterns cannot be expressed by
98
+ # patterns are very simple, so many regexp patterns cannot be expressed by
99
99
  # them, but only a couple databases (PostgreSQL and MySQL) support regexp
100
100
  # patterns.
101
101
  # * The operator validation only supports >, >=, <, and <= operators, and the
@@ -10,14 +10,14 @@
10
10
  #
11
11
  # using Sequel::CoreRefinements
12
12
 
13
- # :nocov:
13
+ # simplecov:disable
14
14
  raise(Sequel::Error, "Refinements require ruby 2.0.0 or greater") unless RUBY_VERSION >= '2.0.0'
15
- # :nocov:
15
+ # simplecov:enable
16
16
 
17
17
  module Sequel::CoreRefinements
18
- # :nocov:
18
+ # simplecov:disable
19
19
  include_meth = RUBY_VERSION >= '3.1' ? :import_methods : :include
20
- # :nocov:
20
+ # simplecov:enable
21
21
  INCLUDE_METH = include_meth
22
22
  private_constant :INCLUDE_METH
23
23
 
@@ -201,16 +201,16 @@ module Sequel::CoreRefinements
201
201
  send include_meth, Sequel::SQL::BooleanMethods
202
202
  send include_meth, Sequel::SQL::NumericMethods
203
203
 
204
- # :nocov:
204
+ # simplecov:disable
205
205
  remove_method :* if RUBY_VERSION >= '3.1'
206
- # :nocov:
206
+ # simplecov:enable
207
207
 
208
208
  send include_meth, Sequel::SQL::QualifyingMethods
209
209
  send include_meth, Sequel::SQL::StringMethods
210
210
  send include_meth, Sequel::SQL::SubscriptMethods
211
211
  send include_meth, Sequel::SQL::ComplexExpressionMethods
212
212
 
213
- # :nocov:
213
+ # simplecov:disable
214
214
  if RUBY_VERSION >= '3.1'
215
215
  remove_method :*
216
216
  def *(ce=(arg=false;nil))
@@ -222,7 +222,7 @@ module Sequel::CoreRefinements
222
222
  end
223
223
 
224
224
  end
225
- # :nocov:
225
+ # simplecov:enable
226
226
 
227
227
  # Returns receiver wrapped in an <tt>Sequel::SQL::Identifier</tt>.
228
228
  #
@@ -1,7 +1,7 @@
1
1
  # frozen-string-literal: true
2
2
  #
3
3
  # The date_arithmetic extension adds the ability to perform database-independent
4
- # addition/substraction of intervals to/from dates and timestamps.
4
+ # addition/subtraction of intervals to/from dates and timestamps.
5
5
  #
6
6
  # First, you need to load the extension into the database:
7
7
  #
@@ -20,10 +20,10 @@ module Sequel::DateTimeParseToTime
20
20
  # be in UTC and there is no offset information in the string.
21
21
  def convert_input_timestamp(v, input_timezone)
22
22
  if v.is_a?(String) && datetime_class == Time && input_timezone == :utc && !_date_parse(v).has_key?(:offset)
23
- # :nocov:
23
+ # simplecov:disable
24
24
  # Whether this is fully branch covered depends on the order in which the specs are run.
25
25
  v = handle_date_parse_input(v) if respond_to?(:handle_date_parse_input, true)
26
- # :nocov:
26
+ # simplecov:enable
27
27
  t = DateTime.parse(v).to_time
28
28
  case application_timezone
29
29
  when nil, :local
@@ -40,9 +40,9 @@
40
40
 
41
41
  module Sequel
42
42
  module DuplicateColumnsHandler
43
- # :nocov:
43
+ # simplecov:disable
44
44
  CALLER_ARGS = (RUBY_VERSION >= '2.0' ? [0,1] : [0]).freeze
45
- # :nocov:
45
+ # simplecov:enable
46
46
 
47
47
  # Customize handling of duplicate columns for this dataset.
48
48
  def on_duplicate_columns(handler = (raise Error, "Must provide either an argument or a block to on_duplicate_columns" unless defined?(yield); nil), &block)
@@ -43,7 +43,7 @@ module Sequel
43
43
  private
44
44
 
45
45
  # Fetch the rows, split them into component table parts,
46
- # tranform and run the row_proc on each part (if applicable),
46
+ # transform and run the row_proc on each part (if applicable),
47
47
  # and yield a hash of the parts.
48
48
  def graph_each(sql=select_sql)
49
49
  # Reject tables with nil datasets, as they are excluded from
@@ -14,7 +14,7 @@
14
14
  #
15
15
  # # load model files
16
16
  #
17
- # Then, whenever database indicies are modified, write a new cached
17
+ # Then, whenever database indices are modified, write a new cached
18
18
  # file. You can do that with <tt>bin/sequel</tt>'s -X option:
19
19
  #
20
20
  # bin/sequel -X /path/to/index_cache.dump postgres://...
@@ -31,7 +31,7 @@ class String
31
31
  @plurals, @singulars, @uncountables = [], [], []
32
32
 
33
33
  class << self
34
- # Array of 2 element arrays, first containing a regex, and the second containing a substitution pattern, used for plurization.
34
+ # Array of 2 element arrays, first containing a regex, and the second containing a substitution pattern, used for pluralization.
35
35
  attr_reader :plurals
36
36
 
37
37
  # Array of 2 element arrays, first containing a regex, and the second containing a substitution pattern, used for singularization.
@@ -107,11 +107,11 @@ class String
107
107
  end
108
108
 
109
109
  %w'classify constantize dasherize demodulize foreign_key humanize pluralize singularize tableize underscore'.each do |m|
110
- # :nocov:
110
+ # simplecov:disable
111
111
  if method_defined?(m)
112
112
  alias_method(m, m)
113
113
  end
114
- # :nocov:
114
+ # simplecov:enable
115
115
  end
116
116
 
117
117
  # By default, camelize converts the string to UpperCamelCase. If the argument to camelize
@@ -212,8 +212,8 @@ class String
212
212
  # Examples
213
213
  # "posts".singularize #=> "post"
214
214
  # "octopi".singularize #=> "octopus"
215
- # "sheep".singluarize #=> "sheep"
216
- # "word".singluarize #=> "word"
215
+ # "sheep".singularize #=> "sheep"
216
+ # "word".singularize #=> "word"
217
217
  # "the blue mailmen".singularize #=> "the blue mailman"
218
218
  # "CamelOctopi".singularize #=> "CamelOctopus"
219
219
  def singularize
@@ -124,7 +124,7 @@ module Sequel
124
124
  Dataset.register_extension(:is_distinct_from, SQL::IsDistinctFrom::DatasetMethods)
125
125
  end
126
126
 
127
- # :nocov:
127
+ # simplecov:disable
128
128
  if Sequel.core_extensions?
129
129
  class Symbol
130
130
  include Sequel::SQL::IsDistinctFrom::Methods
@@ -138,4 +138,4 @@ if defined?(Sequel::CoreRefinements)
138
138
  end
139
139
  end
140
140
  end
141
- # :nocov:
141
+ # simplecov:enable
@@ -46,16 +46,16 @@ module Sequel
46
46
  class LiteralString
47
47
  # The string used when creating the literal string (first argument to
48
48
  # Sequel::LiteralString.new). This may be nil if no string was provided,
49
- # or if the litral string was created before this extension was required.
49
+ # or if the literal string was created before this extension was required.
50
50
  attr_reader :source
51
51
 
52
52
  def initialize(*a)
53
53
  @source = a.first
54
54
  super
55
55
  end
56
- # :nocov:
56
+ # simplecov:disable
57
57
  ruby2_keywords :initialize if respond_to?(:ruby2_keywords, true)
58
- # :nocov:
58
+ # simplecov:enable
59
59
  end
60
60
 
61
61
  module LitRequireFrozen
@@ -68,9 +68,9 @@ module Sequel
68
68
  # Allow calling private methods for backwards compatibility
69
69
  @db.send(method_sym, *args, &block)
70
70
  end
71
- # :nocov:
71
+ # simplecov:disable
72
72
  ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
73
- # :nocov:
73
+ # simplecov:enable
74
74
 
75
75
  # This object responds to all methods the database responds to.
76
76
  def respond_to_missing?(meth, include_private)
@@ -410,6 +410,11 @@ module Sequel
410
410
  private_constant :MIGRATION_ADVISORY_LOCK_ID
411
411
 
412
412
  # Migrates the supplied database using the migration files in the specified directory. Options:
413
+ # :allow_migration_number :: Set to check each migration number. If set, calls the
414
+ # <tt>===</tt> method on the object with the migration number,
415
+ # allowing it to work with both ranges and procs. If the
416
+ # <tt>===</tt> method returns false, an exception is raised
417
+ # (TimestampMigrator only).
413
418
  # :allow_missing_migration_files :: Don't raise an error if there are missing migration files.
414
419
  # It is very risky to use this option, since it can result in
415
420
  # the database schema version number not matching the expected
@@ -699,6 +704,7 @@ module Sequel
699
704
 
700
705
  # Set up all state for the migrator instance
701
706
  def initialize(db, directory, opts=OPTS)
707
+ @allow_migration_number = opts[:allow_migration_number]
702
708
  super
703
709
  @target = opts[:target]
704
710
  @applied_migrations = get_applied_migrations
@@ -788,20 +794,28 @@ module Sequel
788
794
  # Returns any migration files found in the migrator's directory.
789
795
  def get_migration_files
790
796
  files = []
797
+ allow_migration_number = @allow_migration_number
798
+
791
799
  Dir.new(directory).each do |file|
792
800
  next unless MIGRATION_FILE_PATTERN.match(file)
793
801
  files << File.join(directory, file)
794
802
  end
795
- files.sort! do |a, b|
796
- a_ver, a_name = split_migration_filename(a)
797
- b_ver, b_name = split_migration_filename(b)
803
+
804
+ files.map! do |f|
805
+ ver, = split = split_migration_filename(f)
806
+ if allow_migration_number && !(allow_migration_number === ver)
807
+ raise Error, "Migration filename uses version number that is not allowed: #{f}"
808
+ end
809
+ [f, *split]
810
+ end.sort! do |a, b|
811
+ _, a_ver, a_name = a
812
+ _, b_ver, b_name = b
798
813
  x = a_ver <=> b_ver
799
814
  if x.zero?
800
815
  x = a_name <=> b_name
801
816
  end
802
817
  x
803
- end
804
- files
818
+ end.map!(&:first)
805
819
  end
806
820
 
807
821
  # Return an integer and name (without extension) for the given path.
@@ -80,10 +80,10 @@ module Sequel
80
80
  raise unless disamb = tzinfo_disambiguator_for(v)
81
81
  period = input_timezone.period_for_local(v, &disamb)
82
82
  offset = period.utc_total_offset
83
- # :nocov:
83
+ # simplecov:disable
84
84
  if BROKEN_TIME_AT_WITH_NSEC
85
85
  Time.at(v.to_i - offset, :in => input_timezone) + v.nsec/1000000000.0
86
- # :nocov:
86
+ # simplecov:enable
87
87
  else
88
88
  Time.at(v.to_i - offset, v.nsec, :nsec, :in => input_timezone)
89
89
  end
@@ -92,16 +92,16 @@ module Sequel
92
92
  # Convert the given input Time to the given output timezone,
93
93
  # which should be a TZInfo::Timezone instance.
94
94
  def convert_output_time_other(v, output_timezone)
95
- # :nocov:
95
+ # simplecov:disable
96
96
  if BROKEN_TIME_AT_WITH_NSEC
97
97
  Time.at(v.to_i, :in => output_timezone) + v.nsec/1000000000.0
98
- # :nocov:
98
+ # simplecov:enable
99
99
  else
100
100
  Time.at(v.to_i, v.nsec, :nsec, :in => output_timezone)
101
101
  end
102
102
  end
103
103
  # :nodoc:
104
- # :nocov:
104
+ # simplecov:disable
105
105
  else
106
106
  def convert_input_time_other(v, input_timezone)
107
107
  local_offset = input_timezone.period_for_local(v, &tzinfo_disambiguator_for(v)).utc_total_offset
@@ -122,7 +122,7 @@ module Sequel
122
122
  end
123
123
  end
124
124
  # :nodoc:
125
- # :nocov:
125
+ # simplecov:enable
126
126
  end
127
127
 
128
128
  # Handle both TZInfo 1 and TZInfo 2
@@ -139,7 +139,7 @@ module Sequel
139
139
  DateTime.civil(v.year, v.month, v.day, v.hour, v.minute, v.second + v.sec_fraction, v.offset, v.start)
140
140
  end
141
141
  # :nodoc:
142
- # :nocov:
142
+ # simplecov:disable
143
143
  else
144
144
  # Assume the given DateTime has a correct time but a wrong timezone. It is
145
145
  # currently in UTC timezone, but it should be converted to the input_timezone.
@@ -161,7 +161,7 @@ module Sequel
161
161
  (v - local_offset).new_offset(local_offset)
162
162
  end
163
163
  # :nodoc:
164
- # :nocov:
164
+ # simplecov:enable
165
165
  end
166
166
 
167
167
  # Returns TZInfo::Timezone instance if given a String.
@@ -77,6 +77,7 @@ module Sequel
77
77
  # Represents a PostgreSQL array column value.
78
78
  class PGArray < DelegateClass(Array)
79
79
  include Sequel::SQL::AliasMethods
80
+ include Sequel::SQL::CastMethods
80
81
 
81
82
  module DatabaseMethods
82
83
  BLOB_RANGE = 1...-1
@@ -362,18 +363,18 @@ module Sequel
362
363
  raise Sequel::Error, "invalid array, empty string" if eos?
363
364
  raise Sequel::Error, "invalid array, doesn't start with {" unless scan(/((\[\d+:\d+\])+=)?\{/)
364
365
 
365
- # :nocov:
366
+ # simplecov:disable
366
367
  while !eos?
367
- # :nocov:
368
+ # simplecov:enable
368
369
  char = scan(/[{}",]|[^{}",]+/)
369
370
  if char == ','
370
371
  # Comma outside quoted string indicates end of current entry
371
372
  new_entry
372
373
  elsif char == '"'
373
374
  raise Sequel::Error, "invalid array, opening quote with existing recorded data" unless @recorded.empty?
374
- # :nocov:
375
+ # simplecov:disable
375
376
  while true
376
- # :nocov:
377
+ # simplecov:enable
377
378
  char = scan(/["\\]|[^"\\]+/)
378
379
  if char == '\\'
379
380
  @recorded << getch
@@ -434,12 +435,12 @@ module Sequel
434
435
  end
435
436
 
436
437
  if Sequel::Postgres.respond_to?(:parse_pg_array)
437
- # :nocov:
438
+ # simplecov:disable
438
439
  # Use sequel_pg's C-based parser if it has already been defined.
439
440
  def call(string)
440
441
  PGArray.new(Sequel::Postgres.parse_pg_array(string, @converter), @type)
441
442
  end
442
- # :nocov:
443
+ # simplecov:enable
443
444
  else
444
445
  # Parse the string using Parser with the appropriate
445
446
  # converter, and return a PGArray with the appropriate database
@@ -531,7 +532,7 @@ module Sequel
531
532
  Database.register_extension(:pg_array, Postgres::PGArray::DatabaseMethods)
532
533
  end
533
534
 
534
- # :nocov:
535
+ # simplecov:disable
535
536
  if Sequel.core_extensions?
536
537
  class Array
537
538
  # Return a PGArray proxy to the receiver, using a
@@ -553,4 +554,4 @@ if defined?(Sequel::CoreRefinements)
553
554
  end
554
555
  end
555
556
  end
556
- # :nocov:
557
+ # simplecov:enable
@@ -54,15 +54,20 @@
54
54
  # ia.join # array_to_string(int_array_column, '')
55
55
  # ia.join(':') # array_to_string(int_array_column, ':')
56
56
  # ia.join(':', ' ') # array_to_string(int_array_column, ':', ' ')
57
- # ia.unnest # unnest(int_array_column)
58
- # ia.unnest(:b) # unnest(int_array_column, b)
59
- #
60
- # On PostgreSQL 18+, the following are supported:
61
- #
57
+ # ia.ndims # array_ndims(int_array_column)
58
+ # ia.position(3) # array_position(int_array_column, 3, 1)
59
+ # ia.position(3, 2) # array_position(int_array_column, 3, 2)
60
+ # ia.positions(3) # array_positions(int_array_column, 3)
61
+ # ia.prepend(3) # array_prepend(3, int_array_column)
62
+ # ia.reverse # array_reverse(int_array_column)
63
+ # ia.sample(3) # array_sample(int_array_column, 3)
64
+ # ia.shuffle # array_shuffle(int_array_column)
62
65
  # ia.sort # array_sort(int_array_column)
63
66
  # ia.sort(desc: true) # array_sort(int_array_column, true)
64
67
  # ia.sort(nulls: :first) # array_sort(int_array_column, false, true)
65
- # ia.reverse # array_reverse(int_array_column)
68
+ # ia.trim(1) # trim_array(int_array_column, 1)
69
+ # ia.unnest # unnest(int_array_column)
70
+ # ia.unnest(:b) # unnest(int_array_column, b)
66
71
  #
67
72
  # See the PostgreSQL array function and operator documentation for more
68
73
  # details on what these functions and operators do.
@@ -153,6 +158,13 @@ module Sequel
153
158
  function(:array_dims)
154
159
  end
155
160
 
161
+ # Call the array_ndims method:
162
+ #
163
+ # array_op.ndims # array_ndims(array)
164
+ def ndims
165
+ function(:array_ndims)
166
+ end
167
+
156
168
  # Convert the array into an hstore using the hstore function.
157
169
  # If given an argument, use the two array form:
158
170
  #
@@ -164,9 +176,9 @@ module Sequel
164
176
  else
165
177
  Sequel.function(:hstore, self, wrap_array(arg))
166
178
  end
167
- # :nocov:
179
+ # simplecov:disable
168
180
  if Sequel.respond_to?(:hstore_op)
169
- # :nocov:
181
+ # simplecov:enable
170
182
  v = Sequel.hstore_op(v)
171
183
  end
172
184
  v
@@ -188,6 +200,28 @@ module Sequel
188
200
  function(:array_lower, dimension)
189
201
  end
190
202
 
203
+ # Call the array_position method:
204
+ #
205
+ # array_op.position(1) # array_position(array, 1, 1)
206
+ # array_op.position(1, 2) # array_position(array, 1, 2)
207
+ def position(element, offset = 1)
208
+ function(:array_position, element, offset)
209
+ end
210
+
211
+ # Call the array_positions method:
212
+ #
213
+ # array_op.positions(1) # array_positions(array, 1)
214
+ def positions(element)
215
+ function(:array_positions, element)
216
+ end
217
+
218
+ # Call the array_prepend method:
219
+ #
220
+ # array_op.prepend(1) # array_prepend(1, array)
221
+ def prepend(element)
222
+ SQL::Function.new(:array_prepend, element, self)
223
+ end
224
+
191
225
  # Use the overlaps (&&) operator:
192
226
  #
193
227
  # array_op.overlaps(:a) # (array && a)
@@ -195,7 +229,7 @@ module Sequel
195
229
  bool_op(OVERLAPS, wrap_array(other))
196
230
  end
197
231
 
198
- # Use the concatentation (||) operator:
232
+ # Use the concatenation (||) operator:
199
233
  #
200
234
  # array_op.push(:a) # (array || a)
201
235
  # array_op.concat(:a) # (array || a)
@@ -231,6 +265,20 @@ module Sequel
231
265
  function(:array_reverse)
232
266
  end
233
267
 
268
+ # Call the array_sample method:
269
+ #
270
+ # array_op.sample(1) # array_sample(array, 1)
271
+ def sample(element)
272
+ function(:array_sample, element)
273
+ end
274
+
275
+ # Call the array_shuffle method:
276
+ #
277
+ # array_op.shuffle # array_shuffle
278
+ def shuffle
279
+ function(:array_shuffle)
280
+ end
281
+
234
282
  # Call the array_sort method. Options:
235
283
  #
236
284
  # :desc :: Sort in descending order instead of ascending order.
@@ -273,6 +321,13 @@ module Sequel
273
321
  end
274
322
  alias join to_string
275
323
 
324
+ # Call the trim_array method:
325
+ #
326
+ # array_op.trim(1) # array_trim(array, 1)
327
+ def trim(number)
328
+ function(:trim_array, number)
329
+ end
330
+
276
331
  # Call the unnest method:
277
332
  #
278
333
  # array_op.unnest # unnest(array)
@@ -280,7 +335,7 @@ module Sequel
280
335
  function(:unnest, *args.map{|a| wrap_array(a)})
281
336
  end
282
337
 
283
- # Use the concatentation (||) operator, reversing the order:
338
+ # Use the concatenation (||) operator, reversing the order:
284
339
  #
285
340
  # array_op.unshift(:a) # (a || array)
286
341
  def unshift(other)
@@ -326,9 +381,9 @@ module Sequel
326
381
  end
327
382
  end
328
383
 
329
- # :nocov:
384
+ # simplecov:disable
330
385
  if defined?(PGArray)
331
- # :nocov:
386
+ # simplecov:enable
332
387
  class PGArray
333
388
  # Wrap the PGArray instance in an ArrayOp, allowing you to easily use
334
389
  # the PostgreSQL array functions and operators with literal arrays.
@@ -360,7 +415,7 @@ module Sequel
360
415
  end
361
416
  end
362
417
 
363
- # :nocov:
418
+ # simplecov:disable
364
419
  if Sequel.core_extensions?
365
420
  class Symbol
366
421
  include Sequel::Postgres::ArrayOpMethods
@@ -374,4 +429,4 @@ if defined?(Sequel::CoreRefinements)
374
429
  end
375
430
  end
376
431
  end
377
- # :nocov:
432
+ # simplecov:enable
@@ -56,7 +56,7 @@
56
56
  # DB[:t].select{foo('a').as(:f)}.group{foo('a')}
57
57
  # # SELECT foo('a') AS "f" FROM "t" GROUP BY foo('a')
58
58
  #
59
- # Will get auto paramterized as:
59
+ # Will get auto parameterized as:
60
60
  #
61
61
  # # SELECT foo($1) AS "f" FROM "t" GROUP BY foo($2)
62
62
  #
@@ -180,7 +180,7 @@ module Sequel
180
180
  end
181
181
  end
182
182
 
183
- # PlacholderLiteralizer subclass with support for stored auto parameters.
183
+ # PlaceholderLiteralizer subclass with support for stored auto parameters.
184
184
  class PlaceholderLiteralizer < ::Sequel::Dataset::PlaceholderLiteralizer
185
185
  def initialize(dataset, fragments, final_sql, arity)
186
186
  s = dataset.sql.dup
@@ -49,7 +49,7 @@ module Sequel
49
49
  # Enable automatically parameterizing queries.
50
50
  module AutoParameterizeInArray
51
51
  module TreatStringListAsUntypedArray
52
- # Sentinal value to use as an auto param type to use auto parameterization
52
+ # Sentinel value to use as an auto param type to use auto parameterization
53
53
  # of a string array without an explicit type cast.
54
54
  NO_EXPLICIT_CAST = Object.new.freeze
55
55
 
@@ -64,7 +64,7 @@ module Sequel
64
64
 
65
65
  private
66
66
 
67
- # Recognize NO_EXPLICIT_CAST sentinal value and use wrapped
67
+ # Recognize NO_EXPLICIT_CAST sentinel value and use wrapped
68
68
  # PGArray that will be parameterized into the query.
69
69
  def _convert_array_to_pg_array_with_type(r, type)
70
70
  if NO_EXPLICIT_CAST.equal?(type)
@@ -158,7 +158,7 @@ module Sequel
158
158
  nil
159
159
  end
160
160
 
161
- # The minimium size of array to auto parameterize.
161
+ # The minimum size of array to auto parameterize.
162
162
  def pg_auto_parameterize_min_array_size
163
163
  2
164
164
  end
@@ -180,9 +180,9 @@ module Sequel
180
180
  end
181
181
 
182
182
  # support reversible create_enum statements if the migration extension is loaded
183
- # :nocov:
183
+ # simplecov:disable
184
184
  if defined?(MigrationReverser)
185
- # :nocov:
185
+ # simplecov:enable
186
186
  class MigrationReverser
187
187
  private
188
188
  def create_enum(name, _)
@@ -31,7 +31,7 @@ module Sequel
31
31
  RATIONAL_60 = Rational(60)
32
32
  TIME_CAN_PARSE_BC = RUBY_VERSION >= '2.5'
33
33
 
34
- # Add dataset methods and update the conversion proces for dates and timestamps.
34
+ # Add dataset methods and update the conversion process for dates and timestamps.
35
35
  def self.extended(db)
36
36
  db.extend_datasets(DatasetMethods)
37
37
  procs = db.conversion_procs
@@ -114,10 +114,10 @@ module Sequel
114
114
  DateTime.parse(value)
115
115
  elsif TIME_CAN_PARSE_BC
116
116
  Time.parse(value)
117
- # :nocov:
117
+ # simplecov:disable
118
118
  else
119
119
  DateTime.parse(value).to_time
120
- # :nocov:
120
+ # simplecov:enable
121
121
  end
122
122
 
123
123
  Sequel.convert_output_timestamp(dt, Sequel.application_timezone)
@@ -219,7 +219,7 @@ module Sequel
219
219
  end
220
220
 
221
221
  if RUBY_ENGINE == 'jruby'
222
- # :nocov:
222
+ # simplecov:disable
223
223
 
224
224
  ExtendedDateSupport::CONVERT_TYPES = [Java::JavaSQL::Types::DATE, Java::JavaSQL::Types::TIMESTAMP]
225
225
 
@@ -241,7 +241,7 @@ module Sequel
241
241
  super
242
242
  end
243
243
  end
244
- # :nocov:
244
+ # simplecov:enable
245
245
  else
246
246
  # Handle BC Time objects.
247
247
  def literal_time(time)
@@ -53,7 +53,7 @@
53
53
  # # => "numeric"
54
54
  #
55
55
  # The +:raw+ behavior was Sequel's historical behavior, but unless
56
- # you fully understand the reprecussions of PostgreSQL using a
56
+ # you fully understand the repercussions of PostgreSQL using a
57
57
  # numeric type for integer values, you should not use it.
58
58
  #
59
59
  # To get the current default behavior of raising an exception for
@@ -326,7 +326,7 @@ module Sequel
326
326
  Database.register_extension(:pg_hstore, Postgres::HStore::DatabaseMethods)
327
327
  end
328
328
 
329
- # :nocov:
329
+ # simplecov:disable
330
330
  if Sequel.core_extensions?
331
331
  class Hash
332
332
  # Create a new HStore using the receiver as the input
@@ -350,4 +350,4 @@ if defined?(Sequel::CoreRefinements)
350
350
  end
351
351
  end
352
352
  end
353
- # :nocov:
353
+ # simplecov:enable