sequel 5.95.0 → 5.96.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a008ffa4ce90081d7259c785ca68f6f3e3209d789ce6016da8040ea89acca49
4
- data.tar.gz: a9f7af4d4214ca4dd82d4909e8aa2c79c96821245f39cc34278df788ae319cb6
3
+ metadata.gz: 52123540e6fde4ed7ade970b36fc60898bae7463c0e22f63c4205748365cd82b
4
+ data.tar.gz: e3374571d1e4fc490d3e2dc847679a2d8893b196c152d26f760b723605951ddd
5
5
  SHA512:
6
- metadata.gz: 9aa9d1fb1cb8a0a323331b2cdccc48b51b5b9f38289be280f693e0b998747d6c7a5e204c29c13cb89bd50caeb5bde604527eb8966249edfe3ab0866bb039bdf2
7
- data.tar.gz: 894997717d624f602d9dbfaa554ac03270a50a69f5da6982fd687101af95e94c02a3c82b0fbe9e5ec8a5c4d39265fb4e18d9b9f706be216fccc7c45cd72a00ce
6
+ metadata.gz: a4a48515dcb90df9ca6dde4b657f6d1ccce0724b0bd6d09c2a36aed3f37d338fe468135f177fb7cd5f985c79a5e06a91d1459731dc2fdc21601083863d9efd1a
7
+ data.tar.gz: 3c18417f6991a190781cf0098aa81dae3077f52e5fed75162352ffe10fc2f065b5b9ffad1db3bdded7ecc8afed7ea698fc1047570a98dc8a7a87470e7cc2290e
@@ -154,6 +154,11 @@ module Sequel
154
154
  @operations << {:op => :alter_constraint, :name => name}.merge!(opts)
155
155
  end
156
156
 
157
+ # :inherit :: Set true to use INHERIT, or false to use NO INHERIT (PostgreSQL 18+)
158
+ def rename_constraint(name, new_name)
159
+ @operations << {:op => :rename_constraint, :name => name, :new_name => new_name}
160
+ end
161
+
157
162
  # Validate the constraint with the given name, which should have
158
163
  # been added previously with NOT VALID.
159
164
  def validate_constraint(name)
@@ -1210,6 +1215,10 @@ module Sequel
1210
1215
  Postgres::AlterTableGenerator
1211
1216
  end
1212
1217
 
1218
+ def alter_table_rename_constraint_sql(table, op)
1219
+ "RENAME CONSTRAINT #{quote_identifier(op[:name])} TO #{quote_identifier(op[:new_name])}"
1220
+ end
1221
+
1213
1222
  def alter_table_set_column_type_sql(table, op)
1214
1223
  s = super
1215
1224
  if using = op[:using]
@@ -1291,7 +1300,7 @@ module Sequel
1291
1300
  sql << (identity == :always ? "ALWAYS" : "BY DEFAULT")
1292
1301
  sql << " AS IDENTITY"
1293
1302
  elsif (generated = column[:generated_always_as])
1294
- sql << " GENERATED ALWAYS AS (#{literal(generated)}) STORED"
1303
+ sql << " GENERATED ALWAYS AS (#{literal(generated)}) #{column[:virtual] ? 'VIRTUAL' : 'STORED'}"
1295
1304
  end
1296
1305
  end
1297
1306
  end
@@ -1385,6 +1394,7 @@ module Sequel
1385
1394
  end
1386
1395
  end
1387
1396
 
1397
+ constraint_deferrable_sql_append(sql, constraint[:deferrable])
1388
1398
  sql
1389
1399
  else # when :foreign_key, :check
1390
1400
  sql = super
@@ -156,6 +156,9 @@ module Sequel
156
156
  # PostgreSQL specific options:
157
157
  #
158
158
  # :identity :: Create an identity column.
159
+ # :virtual :: When using :generated_always_as, create a VIRTUAL column instead of a STORED
160
+ # column (PostgreSQL 18+). VIRTUAL is the default if not specified on
161
+ # PostgreSQL 18+, but for backwards compatibility, Sequel's default is STORED.
159
162
  #
160
163
  # MySQL specific options:
161
164
  #
@@ -56,6 +56,13 @@
56
56
  # ia.join(':', ' ') # array_to_string(int_array_column, ':', ' ')
57
57
  # ia.unnest # unnest(int_array_column)
58
58
  # ia.unnest(:b) # unnest(int_array_column, b)
59
+ #
60
+ # On PostgreSQL 18+, the following are supported:
61
+ #
62
+ # ia.sort # array_sort(int_array_column)
63
+ # ia.sort(desc: true) # array_sort(int_array_column, true)
64
+ # ia.sort(nulls: :first) # array_sort(int_array_column, false, true)
65
+ # ia.reverse # array_reverse(int_array_column)
59
66
  #
60
67
  # See the PostgreSQL array function and operator documentation for more
61
68
  # details on what these functions and operators do.
@@ -217,6 +224,40 @@ module Sequel
217
224
  ArrayOp.new(function(:array_replace, element, replacement))
218
225
  end
219
226
 
227
+ # Call the array_reverse method:
228
+ #
229
+ # array_op.reverse # array_reverse(array)
230
+ def reverse
231
+ function(:array_reverse)
232
+ end
233
+
234
+ # Call the array_sort method. Options:
235
+ #
236
+ # :desc :: Sort in descending order instead of ascending order.
237
+ # :nulls :: If sorting in ascending order and value is :first, include NULL
238
+ # values before non-NULL values. If sorting in descending order and
239
+ # value is :last, include non-NULL values before NULL values.
240
+ #
241
+ # array_op.sort # array_sort(array)
242
+ # array_op.sort(desc: true) # array_sort(array, true)
243
+ # array_op.sort(nulls: :first) # array_sort(array, false, true)
244
+ # array_op.sort(desc: true, nulls: :last) # array_sort(array, true, false)
245
+ def sort(opts=OPTS)
246
+ desc = opts[:desc]
247
+ nulls = opts[:nulls]
248
+ if desc
249
+ if nulls == :last
250
+ function(:array_sort, true, false)
251
+ else
252
+ function(:array_sort, true)
253
+ end
254
+ elsif nulls == :first
255
+ function(:array_sort, false, true)
256
+ else
257
+ function(:array_sort)
258
+ end
259
+ end
260
+
220
261
  # Call the array_to_string method:
221
262
  #
222
263
  # array_op.join # array_to_string(array, '')
@@ -348,6 +348,8 @@ module Sequel
348
348
  # automatically parameterized.
349
349
  def auto_param_type(v)
350
350
  case v
351
+ when Symbol
352
+ false
351
353
  when String
352
354
  case v
353
355
  when LiteralString
@@ -166,6 +166,11 @@
166
166
  # # "d" date EXISTS FALSE ON ERROR
167
167
  # # ))
168
168
  #
169
+ # On PostgreSQL 18+, strip_nulls can take an argument for whether to strip in arrays
170
+ #
171
+ # j.strip_nulls(in_arrays: true) # json_strip_nulls(json_column, true)
172
+ # j.strip_nulls(in_arrays: false) # json_strip_nulls(json_column, false)
173
+ #
169
174
  # If you are also using the pg_json extension, you should load it before
170
175
  # loading this extension. Doing so will allow you to use the #op method on
171
176
  # JSONHash, JSONHarray, JSONBHash, and JSONBArray, allowing you to perform json/jsonb operations
@@ -380,11 +385,22 @@ module Sequel
380
385
  self.class.new(JSONQueryOp.new(self, path, opts))
381
386
  end
382
387
 
383
- # Returns a json value stripped of all internal null values.
388
+ # Returns a json value stripped of all internal null values. Options:
389
+ #
390
+ # :in_arrays :: Whether to strip null values in JSON arrays
384
391
  #
385
- # json_op.strip_nulls # json_strip_nulls(json)
386
- def strip_nulls
387
- self.class.new(function(:strip_nulls))
392
+ # json_op.strip_nulls # json_strip_nulls(json)
393
+ # json_op.strip_nulls(in_arrays: true) # json_strip_nulls(json, true)
394
+ # json_op.strip_nulls(in_arrays: false) # json_strip_nulls(json, false)
395
+ def strip_nulls(opts=OPTS)
396
+ in_arrays = opts[:in_arrays]
397
+ f = if in_arrays.nil?
398
+ function(:strip_nulls)
399
+ else
400
+ function(:strip_nulls, in_arrays)
401
+ end
402
+
403
+ self.class.new(f)
388
404
  end
389
405
 
390
406
  # Returns json_table SQL function expression, querying JSON data and returning
@@ -339,7 +339,7 @@ module Sequel
339
339
 
340
340
  # Allow automatic parameterization.
341
341
  def sequel_auto_param_type(ds)
342
- "::#{db_type}"
342
+ "::#{db_type}" if all?{|range| range.is_a?(Range) || ds.send(:auto_param_type, range)}
343
343
  end
344
344
  end
345
345
  end
@@ -481,9 +481,9 @@ module Sequel
481
481
  end
482
482
  end
483
483
 
484
- # Allow automatic parameterization for ranges with types.
484
+ # Allow automatic parameterization for ranges with types, if both start .
485
485
  def sequel_auto_param_type(ds)
486
- "::#{db_type}" if db_type
486
+ "::#{db_type}" if db_type && (!@begin || ds.send(:auto_param_type, @begin)) && (!@end || ds.send(:auto_param_type, @end))
487
487
  end
488
488
 
489
489
  private
@@ -1358,17 +1358,16 @@ END
1358
1358
  @values.keys
1359
1359
  end
1360
1360
 
1361
- # Refresh this record using +for_update+ (by default, or the specified style when given)
1361
+ # Refresh this record using +:update+ lock style (by default, or the specified style when given),
1362
1362
  # unless this is a new record. Returns self. This can be used to make sure no other
1363
- # process is updating the record at the same time.
1363
+ # process can modify the record during the transaction containing this call. Using
1364
+ # this method only makes sense inside transactions.
1364
1365
  #
1365
1366
  # If style is a string, it will be used directly. You should never pass a string
1366
1367
  # to this method that is derived from user input, as that can lead to
1367
1368
  # SQL injection.
1368
1369
  #
1369
- # A symbol may be used for database independent locking behavior, but
1370
- # all supported symbols have separate methods (e.g. for_update).
1371
- #
1370
+ # A symbol may be used if the adapter supports that lock style.
1372
1371
  #
1373
1372
  # a = Artist[1]
1374
1373
  # Artist.db.transaction do
@@ -1378,7 +1377,7 @@ END
1378
1377
  #
1379
1378
  # a = Artist[2]
1380
1379
  # Artist.db.transaction do
1381
- # a.lock!('FOR NO KEY UPDATE')
1380
+ # a.lock!(:no_key_update)
1382
1381
  # a.update(name: 'B')
1383
1382
  # end
1384
1383
  def lock!(style=:update)
@@ -106,13 +106,7 @@ module Sequel
106
106
  # and breaks some aspects of the json_serializer plugin. You can undo the damage
107
107
  # done by active_support/json by doing:
108
108
  #
109
- # module ActiveSupportBrokenJSONFix
110
- # def to_json(options = {})
111
- # JSON.generate(self)
112
- # end
113
- # end
114
- # Array.send(:prepend, ActiveSupportBrokenJSONFix)
115
- # Hash.send(:prepend, ActiveSupportBrokenJSONFix)
109
+ # ActiveSupport::ToJsonWithActiveSupportEncoder.send(:remove_method, :to_json)
116
110
  #
117
111
  # Note that this will probably cause active_support/json to no longer work
118
112
  # correctly in some cases.
@@ -6,7 +6,7 @@ module Sequel
6
6
 
7
7
  # The minor version of Sequel. Bumped for every non-patch level
8
8
  # release, generally around once a month.
9
- MINOR = 95
9
+ MINOR = 96
10
10
 
11
11
  # The tiny version of Sequel. Usually 0, only bumped for bugfix
12
12
  # releases that fix regressions from previous versions.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.95.0
4
+ version: 5.96.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans