sequel 5.61.0 → 5.63.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 (76) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +46 -0
  3. data/README.rdoc +20 -19
  4. data/doc/advanced_associations.rdoc +13 -13
  5. data/doc/association_basics.rdoc +21 -15
  6. data/doc/cheat_sheet.rdoc +3 -3
  7. data/doc/model_hooks.rdoc +1 -1
  8. data/doc/object_model.rdoc +8 -8
  9. data/doc/opening_databases.rdoc +4 -4
  10. data/doc/postgresql.rdoc +8 -8
  11. data/doc/querying.rdoc +1 -1
  12. data/doc/release_notes/5.62.0.txt +132 -0
  13. data/doc/release_notes/5.63.0.txt +33 -0
  14. data/doc/schema_modification.rdoc +1 -1
  15. data/doc/security.rdoc +9 -9
  16. data/doc/sql.rdoc +13 -13
  17. data/doc/testing.rdoc +13 -11
  18. data/doc/transactions.rdoc +6 -6
  19. data/doc/virtual_rows.rdoc +1 -1
  20. data/lib/sequel/adapters/postgres.rb +4 -0
  21. data/lib/sequel/adapters/shared/access.rb +9 -1
  22. data/lib/sequel/adapters/shared/mssql.rb +9 -5
  23. data/lib/sequel/adapters/shared/mysql.rb +7 -0
  24. data/lib/sequel/adapters/shared/oracle.rb +7 -0
  25. data/lib/sequel/adapters/shared/postgres.rb +275 -152
  26. data/lib/sequel/adapters/shared/sqlanywhere.rb +7 -0
  27. data/lib/sequel/adapters/shared/sqlite.rb +5 -0
  28. data/lib/sequel/connection_pool/sharded_threaded.rb +5 -1
  29. data/lib/sequel/connection_pool/threaded.rb +8 -8
  30. data/lib/sequel/connection_pool/timed_queue.rb +257 -0
  31. data/lib/sequel/connection_pool.rb +47 -30
  32. data/lib/sequel/database/connecting.rb +24 -0
  33. data/lib/sequel/database/misc.rb +8 -2
  34. data/lib/sequel/database/query.rb +37 -0
  35. data/lib/sequel/dataset/actions.rb +56 -11
  36. data/lib/sequel/dataset/features.rb +5 -0
  37. data/lib/sequel/dataset/misc.rb +1 -1
  38. data/lib/sequel/dataset/query.rb +9 -9
  39. data/lib/sequel/dataset/sql.rb +5 -1
  40. data/lib/sequel/extensions/_model_pg_row.rb +0 -12
  41. data/lib/sequel/extensions/_pretty_table.rb +1 -1
  42. data/lib/sequel/extensions/async_thread_pool.rb +11 -11
  43. data/lib/sequel/extensions/auto_literal_strings.rb +1 -1
  44. data/lib/sequel/extensions/constraint_validations.rb +1 -1
  45. data/lib/sequel/extensions/date_arithmetic.rb +1 -1
  46. data/lib/sequel/extensions/migration.rb +1 -1
  47. data/lib/sequel/extensions/named_timezones.rb +21 -5
  48. data/lib/sequel/extensions/pg_array.rb +22 -3
  49. data/lib/sequel/extensions/pg_auto_parameterize.rb +478 -0
  50. data/lib/sequel/extensions/pg_extended_date_support.rb +12 -0
  51. data/lib/sequel/extensions/pg_extended_integer_support.rb +116 -0
  52. data/lib/sequel/extensions/pg_hstore.rb +5 -0
  53. data/lib/sequel/extensions/pg_inet.rb +9 -10
  54. data/lib/sequel/extensions/pg_interval.rb +9 -10
  55. data/lib/sequel/extensions/pg_json.rb +10 -10
  56. data/lib/sequel/extensions/pg_multirange.rb +5 -10
  57. data/lib/sequel/extensions/pg_range.rb +5 -10
  58. data/lib/sequel/extensions/pg_row.rb +18 -13
  59. data/lib/sequel/model/associations.rb +9 -4
  60. data/lib/sequel/model/base.rb +6 -5
  61. data/lib/sequel/plugins/auto_validations.rb +53 -15
  62. data/lib/sequel/plugins/class_table_inheritance.rb +2 -2
  63. data/lib/sequel/plugins/composition.rb +2 -2
  64. data/lib/sequel/plugins/concurrent_eager_loading.rb +4 -4
  65. data/lib/sequel/plugins/dirty.rb +1 -1
  66. data/lib/sequel/plugins/finder.rb +3 -1
  67. data/lib/sequel/plugins/nested_attributes.rb +4 -4
  68. data/lib/sequel/plugins/pg_auto_constraint_validations.rb +1 -1
  69. data/lib/sequel/plugins/primary_key_lookup_check_values.rb +154 -0
  70. data/lib/sequel/plugins/single_table_inheritance.rb +8 -0
  71. data/lib/sequel/plugins/sql_comments.rb +1 -1
  72. data/lib/sequel/plugins/tactical_eager_loading.rb +14 -14
  73. data/lib/sequel/plugins/validate_associated.rb +22 -12
  74. data/lib/sequel/plugins/validation_helpers.rb +20 -0
  75. data/lib/sequel/version.rb +1 -1
  76. metadata +14 -6
@@ -253,6 +253,14 @@ module Sequel
253
253
 
254
254
  private
255
255
 
256
+ # Limit tactical eager loading objects to objects that support the same association.
257
+ def _filter_tactical_eager_load_objects(opts)
258
+ objects = defined?(super) ? super : retrieved_with.dup
259
+ name = opts[:name]
260
+ objects.select!{|x| x.model.association_reflections.include?(name)}
261
+ objects
262
+ end
263
+
256
264
  # Don't allow use of prepared statements.
257
265
  def use_prepared_statements_for?(type)
258
266
  false
@@ -12,7 +12,7 @@ module Sequel
12
12
  # # SELECT * FROM albums WHERE (id = 1) LIMIT 1
13
13
  # # -- model:Album,method_type:class,method:[]
14
14
  #
15
- # album.update(:name=>'A')
15
+ # album.update(name: 'A')
16
16
  # # UPDATE albums SET name = 'baz' WHERE (id = 1)
17
17
  # # -- model:Album,method_type:instance,method:update
18
18
  #
@@ -152,23 +152,23 @@ module Sequel
152
152
  name = opts[:name]
153
153
  eager_reload = dynamic_opts[:eager_reload]
154
154
  if (!associations.include?(name) || eager_reload) && opts[:allow_eager] != false && retrieved_by && !frozen? && !dynamic_opts[:callback] && !dynamic_opts[:reload]
155
- begin
156
- objects = if eager_reload
157
- retrieved_with.reject(&:frozen?)
158
- else
159
- retrieved_with.reject{|x| x.frozen? || x.associations.include?(name)}
160
- end
161
- retrieved_by.send(:eager_load, objects, name=>dynamic_opts[:eager] || OPTS)
162
- rescue Sequel::UndefinedAssociation
163
- # This can happen if class table inheritance is used and the association
164
- # is only defined in a subclass. This particular instance can use the
165
- # association, but it can't be eagerly loaded as the parent class doesn't
166
- # have access to the association, and that's the class doing the eager loading.
167
- nil
168
- end
155
+ retrieved_by.send(:eager_load, _filter_tactical_eager_load_objects(:eager_reload=>eager_reload, :name=>name), {name=>dynamic_opts[:eager] || OPTS}, model)
169
156
  end
170
157
  super
171
158
  end
159
+
160
+ # Filter the objects used when tactical eager loading.
161
+ # By default, this removes frozen objects and objects that alreayd have the association loaded
162
+ def _filter_tactical_eager_load_objects(opts)
163
+ objects = defined?(super) ? super : retrieved_with.dup
164
+ if opts[:eager_reload]
165
+ objects.reject!(&:frozen?)
166
+ else
167
+ name = opts[:name]
168
+ objects.reject!{|x| x.frozen? || x.associations.include?(name)}
169
+ end
170
+ objects
171
+ end
172
172
  end
173
173
 
174
174
  module DatasetMethods
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Sequel
4
4
  module Plugins
5
- # The validates_associated plugin allows you to validate associated
5
+ # The validate_associated plugin allows you to validate associated
6
6
  # objects. It also offers the ability to delay the validation of
7
7
  # associated objects until the current object is validated.
8
8
  # If the associated object is invalid, validation error messages
@@ -54,22 +54,32 @@ module Sequel
54
54
  return if reflection[:validate] == false
55
55
  association = reflection[:name]
56
56
  if (reflection[:type] == :one_to_many || reflection[:type] == :one_to_one) && (key = reflection[:key]).is_a?(Symbol) && !(pk_val = obj.values[key])
57
- # There could be a presence validation on the foreign key in the associated model,
58
- # which will fail if we validate before saving the current object. If there is
59
- # no value for the foreign key, set it to the current primary key value, or a dummy
60
- # value of 0 if we haven't saved the current object.
61
57
  p_key = pk unless pk.is_a?(Array)
62
- obj.values[key] = p_key || 0
63
- key = nil if p_key
58
+ if p_key
59
+ obj.values[key] = p_key
60
+ else
61
+ ignore_key_errors = true
62
+ end
64
63
  end
65
- obj.errors.full_messages.each{|m| errors.add(association, m)} unless obj.valid?
66
- if key && !pk_val
67
- # If we used a dummy value of 0, remove it so it doesn't accidently remain.
68
- obj.values.delete(key)
64
+
65
+ unless obj.valid?
66
+ if ignore_key_errors
67
+ # Ignore errors on the key column in the associated object. This column
68
+ # will be set when saving to a presumably valid value using a column
69
+ # in the current object (which may not be available until after the current
70
+ # object is saved).
71
+ obj.errors.delete(key)
72
+ obj.errors.delete_if{|k,| Array === k && k.include?(key)}
73
+ end
74
+
75
+ obj.errors.full_messages.each do |m|
76
+ errors.add(association, m)
77
+ end
69
78
  end
79
+
80
+ nil
70
81
  end
71
82
  end
72
83
  end
73
84
  end
74
85
  end
75
-
@@ -83,7 +83,9 @@ module Sequel
83
83
  :integer=>{:message=>lambda{"is not a number"}},
84
84
  :length_range=>{:message=>lambda{|range| "is too short or too long"}},
85
85
  :max_length=>{:message=>lambda{|max| "is longer than #{max} characters"}, :nil_message=>lambda{"is not present"}},
86
+ :max_value=>{:message=>lambda{|max| "is greater than maximum allowed value"}},
86
87
  :min_length=>{:message=>lambda{|min| "is shorter than #{min} characters"}},
88
+ :min_value=>{:message=>lambda{|min| "is less than minimum allowed value"}},
87
89
  :not_null=>{:message=>lambda{"is not present"}},
88
90
  :no_null_byte=>{:message=>lambda{"contains a null byte"}},
89
91
  :numeric=>{:message=>lambda{"is not a number"}},
@@ -141,11 +143,29 @@ module Sequel
141
143
  end
142
144
  end
143
145
 
146
+ # Check that the attribute values are not greater that the given maximum value.
147
+ # Does not perform validation if attribute value is nil.
148
+ # You should only call this if you have checked the attribute value has the expected type.
149
+ def validates_max_value(max, atts, opts=OPTS)
150
+ validatable_attributes_for_type(:max_value, atts, opts) do |a,v,m|
151
+ validation_error_message(m, max) if !v.nil? && v > max
152
+ end
153
+ end
154
+
144
155
  # Check that the attribute values are not shorter than the given min length.
145
156
  def validates_min_length(min, atts, opts=OPTS)
146
157
  validatable_attributes_for_type(:min_length, atts, opts){|a,v,m| validation_error_message(m, min) if v.nil? || v.length < min}
147
158
  end
148
159
 
160
+ # Check that the attribute values are not less that the given minimum value.
161
+ # Does not perform validation if attribute value is nil.
162
+ # You should only call this if you have checked the attribute value has the expected type.
163
+ def validates_min_value(min, atts, opts=OPTS)
164
+ validatable_attributes_for_type(:min_value, atts, opts) do |a,v,m|
165
+ validation_error_message(m, min) if !v.nil? && v < min
166
+ end
167
+ end
168
+
149
169
  # Check attribute value(s) are not NULL/nil.
150
170
  def validates_not_null(atts, opts=OPTS)
151
171
  validatable_attributes_for_type(:not_null, atts, opts){|a,v,m| validation_error_message(m) if v.nil?}
@@ -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 = 61
9
+ MINOR = 63
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.61.0
4
+ version: 5.63.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-01 00:00:00.000000000 Z
11
+ date: 2022-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -193,6 +193,8 @@ extra_rdoc_files:
193
193
  - doc/release_notes/5.6.0.txt
194
194
  - doc/release_notes/5.60.0.txt
195
195
  - doc/release_notes/5.61.0.txt
196
+ - doc/release_notes/5.62.0.txt
197
+ - doc/release_notes/5.63.0.txt
196
198
  - doc/release_notes/5.7.0.txt
197
199
  - doc/release_notes/5.8.0.txt
198
200
  - doc/release_notes/5.9.0.txt
@@ -282,6 +284,8 @@ files:
282
284
  - doc/release_notes/5.6.0.txt
283
285
  - doc/release_notes/5.60.0.txt
284
286
  - doc/release_notes/5.61.0.txt
287
+ - doc/release_notes/5.62.0.txt
288
+ - doc/release_notes/5.63.0.txt
285
289
  - doc/release_notes/5.7.0.txt
286
290
  - doc/release_notes/5.8.0.txt
287
291
  - doc/release_notes/5.9.0.txt
@@ -350,6 +354,7 @@ files:
350
354
  - lib/sequel/connection_pool/sharded_threaded.rb
351
355
  - lib/sequel/connection_pool/single.rb
352
356
  - lib/sequel/connection_pool/threaded.rb
357
+ - lib/sequel/connection_pool/timed_queue.rb
353
358
  - lib/sequel/core.rb
354
359
  - lib/sequel/database.rb
355
360
  - lib/sequel/database/connecting.rb
@@ -420,8 +425,10 @@ files:
420
425
  - lib/sequel/extensions/pagination.rb
421
426
  - lib/sequel/extensions/pg_array.rb
422
427
  - lib/sequel/extensions/pg_array_ops.rb
428
+ - lib/sequel/extensions/pg_auto_parameterize.rb
423
429
  - lib/sequel/extensions/pg_enum.rb
424
430
  - lib/sequel/extensions/pg_extended_date_support.rb
431
+ - lib/sequel/extensions/pg_extended_integer_support.rb
425
432
  - lib/sequel/extensions/pg_hstore.rb
426
433
  - lib/sequel/extensions/pg_hstore_ops.rb
427
434
  - lib/sequel/extensions/pg_inet.rb
@@ -532,6 +539,7 @@ files:
532
539
  - lib/sequel/plugins/pg_row.rb
533
540
  - lib/sequel/plugins/prepared_statements.rb
534
541
  - lib/sequel/plugins/prepared_statements_safe.rb
542
+ - lib/sequel/plugins/primary_key_lookup_check_values.rb
535
543
  - lib/sequel/plugins/rcte_tree.rb
536
544
  - lib/sequel/plugins/require_valid_schema.rb
537
545
  - lib/sequel/plugins/serialization.rb
@@ -579,7 +587,7 @@ metadata:
579
587
  documentation_uri: https://sequel.jeremyevans.net/documentation.html
580
588
  mailing_list_uri: https://github.com/jeremyevans/sequel/discussions
581
589
  source_code_uri: https://github.com/jeremyevans/sequel
582
- post_install_message:
590
+ post_install_message:
583
591
  rdoc_options:
584
592
  - "--quiet"
585
593
  - "--line-numbers"
@@ -601,8 +609,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
601
609
  - !ruby/object:Gem::Version
602
610
  version: '0'
603
611
  requirements: []
604
- rubygems_version: 3.3.7
605
- signing_key:
612
+ rubygems_version: 3.3.26
613
+ signing_key:
606
614
  specification_version: 4
607
615
  summary: The Database Toolkit for Ruby
608
616
  test_files: []