sequel 5.91.0 → 5.92.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: d13e0998a9eb78392a4f9f7793b2ceceebf87fa5a4dd6f9fcfd5bbd05a686d83
4
- data.tar.gz: d4c7da82fb811928c58a096b2d5fc500cdb7cee1bbff14795817b5bd3f4d3360
3
+ metadata.gz: df46d23e3607466eb34477a5ba9c31d14fd57294275088599f8ef4d561179faf
4
+ data.tar.gz: 9566fcb614fded77e5e20c929c9ed5cb6786e0548c3e59837ae2dd1a1877762d
5
5
  SHA512:
6
- metadata.gz: c2bbfc37fbd2b97796c96352a0f1d7d41053f91f4b61e3888a5aea712b9a59c7600e8ed58a15919cef7d8b0cc1c35e4bc3d142206ac245ed6f4f13575188f3b9
7
- data.tar.gz: 8f4c0b7b95ec967c471455df69e8b5b5ff9c2104790c7c18abaa9601f2e7c4514952d4410aac1e3f720304f30af2d7299ea0f1233a7e083bcb901c8a03f697bb
6
+ metadata.gz: 8375cb4204be00b492b841fea5427dce809e43d119c6fd9f559cbfa1b4b9f652e752d22e52a93942a8a228166829d4227202e0f783a89f790d4fad40a8eb0963
7
+ data.tar.gz: 4c6bbc4bd1172ed8c5117bd628651757b8685fab754b4d664ceb3254917fbeb58d778bccd3b8dbe998e4694f185baa4e630910dc1de8fe1b5026d23e95c215b4
@@ -61,7 +61,7 @@ module Sequel
61
61
  # # SELECT id, name FROM table WHERE active ORDER BY id
62
62
  def extend_datasets(mod=nil, &block)
63
63
  raise(Error, "must provide either mod or block, not both") if mod && block
64
- mod = Sequel.set_temp_name(Dataset::DatasetModule.new(&block)){"Sequel::Dataset::_DatasetModule(#{block.source_location.join(':')})"} if block
64
+ mod = Sequel.set_temp_name(Dataset::DatasetModule.new(&block)){"Sequel::Dataset::_DatasetModule(#{block.source_location[0,2].join(':')})"} if block
65
65
  if @dataset_modules.empty?
66
66
  @dataset_modules = [mod]
67
67
  @dataset_class = Sequel.set_temp_name(Class.new(@dataset_class)){"Sequel::Dataset::_Subclass"}
@@ -1240,7 +1240,7 @@ module Sequel
1240
1240
  def with_extend(*mods, &block)
1241
1241
  c = Sequel.set_temp_name(Class.new(self.class)){"Sequel::Dataset::_Subclass"}
1242
1242
  c.include(*mods) unless mods.empty?
1243
- c.include(Sequel.set_temp_name(DatasetModule.new(&block)){"Sequel::Dataset::_DatasetModule(#{block.source_location.join(':')})"}) if block
1243
+ c.include(Sequel.set_temp_name(DatasetModule.new(&block)){"Sequel::Dataset::_DatasetModule(#{block.source_location[0,2].join(':')})"}) if block
1244
1244
  o = c.freeze.allocate
1245
1245
  o.instance_variable_set(:@db, @db)
1246
1246
  o.instance_variable_set(:@opts, @opts)
@@ -1430,10 +1430,6 @@ module Sequel
1430
1430
  # calls +sql_literal+ if object responds to it, otherwise raises an error.
1431
1431
  # If a database specific type is allowed, this should be overriden in a subclass.
1432
1432
  def literal_other_append(sql, v)
1433
- # We can't be sure if v will always literalize to the same SQL, so
1434
- # don't cache SQL for a dataset that uses this.
1435
- disable_sql_caching!
1436
-
1437
1433
  if v.respond_to?(:sql_literal_append)
1438
1434
  v.sql_literal_append(self, sql)
1439
1435
  elsif v.respond_to?(:sql_literal)
@@ -1441,6 +1437,12 @@ module Sequel
1441
1437
  else
1442
1438
  raise Error, "can't express #{v.inspect} as a SQL literal"
1443
1439
  end
1440
+
1441
+ if !v.respond_to?(:sql_literal_allow_caching?) || !v.sql_literal_allow_caching?(self)
1442
+ # We can't be sure if v will always literalize to the same SQL, so
1443
+ # don't cache SQL for a dataset that uses this.
1444
+ disable_sql_caching!
1445
+ end
1444
1446
  end
1445
1447
 
1446
1448
  # SQL fragment for Sequel::SQLTime, containing just the time part
@@ -287,6 +287,10 @@ module Sequel
287
287
  def set_column_allow_null(name, allow_null=true)
288
288
  @actions << [:set_column_allow_null, name, !allow_null]
289
289
  end
290
+
291
+ def set_column_not_null(name)
292
+ @actions << [:set_column_allow_null, name]
293
+ end
290
294
  end
291
295
 
292
296
  # The preferred method for writing Sequel migrations, using a DSL:
@@ -533,10 +533,28 @@ module Sequel
533
533
  end
534
534
  end
535
535
 
536
+ # Return a qualified identifier or array of qualified identifiers for
537
+ # the model's primary key. Uses the given qualifier if provided, or
538
+ # the table_name otherwise. If the model does not have a primary key,
539
+ # raises an +Error+.
540
+ #
541
+ # Artist.order(Artist.qualified_primary_key)
542
+ # # SELECT * FROM artists ORDER BY artists.id
543
+ def qualified_primary_key(qualifier=table_name)
544
+ case key = @primary_key
545
+ when Symbol
546
+ SQL::QualifiedIdentifier.new(qualifier, key)
547
+ when Array
548
+ key.map{|k| SQL::QualifiedIdentifier.new(qualifier, k)}
549
+ else
550
+ raise(Error, "#{self} does not have a primary key")
551
+ end
552
+ end
553
+
536
554
  # Return a hash where the keys are qualified column references. Uses the given
537
555
  # qualifier if provided, or the table_name otherwise. This is useful if you
538
556
  # plan to join other tables to this table and you want the column references
539
- # to be qualified.
557
+ # to be qualified. If the model does not have a primary key, raises an +Error+.
540
558
  #
541
559
  # Artist.where(Artist.qualified_primary_key_hash(1))
542
560
  # # SELECT * FROM artists WHERE (artists.id = 1)
@@ -2260,7 +2278,7 @@ END
2260
2278
  # Return the dataset ordered by the model's primary key. This should not
2261
2279
  # be used if the model does not have a primary key.
2262
2280
  def _force_primary_key_order
2263
- cached_dataset(:_pk_order_ds){order(*model.primary_key)}
2281
+ cached_dataset(:_pk_order_ds){order(*unambiguous_primary_key)}
2264
2282
  end
2265
2283
 
2266
2284
  # If the dataset is not already ordered, and the model has a primary key,
@@ -2288,6 +2306,15 @@ END
2288
2306
  end
2289
2307
  end
2290
2308
 
2309
+ # The primary key for the dataset's model, qualified if the dataset is joined.
2310
+ def unambiguous_primary_key
2311
+ if joined_dataset?
2312
+ model.qualified_primary_key
2313
+ else
2314
+ model.primary_key
2315
+ end
2316
+ end
2317
+
2291
2318
  def non_sql_option?(key)
2292
2319
  super || key == :model
2293
2320
  end
@@ -102,7 +102,10 @@ module Sequel
102
102
 
103
103
  # Apply the instance filters to the given dataset
104
104
  def apply_instance_filters(ds)
105
- instance_filters.inject(ds){|ds1, i| ds1.where(*i[0], &i[1])}
105
+ instance_filters.inject(ds) do |ds1, i|
106
+ block = i[1]
107
+ ds1.where(*i[0], &block)
108
+ end
106
109
  end
107
110
 
108
111
  # Clear the instance filters.
@@ -157,13 +157,16 @@ module Sequel
157
157
  raise Error, "the paged_operations plugin is not supported on DB2 when using emulated offsets, set the :offset_strategy Database option to 'limit_offset' or 'offset_fetch'"
158
158
  end
159
159
 
160
- case pk = model.primary_key
160
+ case pk = unambiguous_primary_key
161
161
  when Symbol
162
162
  Sequel.identifier(pk)
163
163
  when Array
164
164
  raise Error, "cannot use #{meth} on a model with a composite primary key"
165
- else
165
+ when nil
166
166
  raise Error, "cannot use #{meth} on a model without a primary key"
167
+ else
168
+ # Likely SQL::QualifiedIdentifier, if the dataset is joined.
169
+ pk
167
170
  end
168
171
  end
169
172
 
@@ -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 = 91
9
+ MINOR = 92
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,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.91.0
4
+ version: 5.92.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-01 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bigdecimal
@@ -448,7 +448,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
448
448
  - !ruby/object:Gem::Version
449
449
  version: '0'
450
450
  requirements: []
451
- rubygems_version: 3.6.2
451
+ rubygems_version: 3.6.7
452
452
  specification_version: 4
453
453
  summary: The Database Toolkit for Ruby
454
454
  test_files: []