sequel 5.57.0 → 5.60.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +34 -0
  3. data/README.rdoc +25 -0
  4. data/bin/sequel +11 -3
  5. data/doc/cheat_sheet.rdoc +8 -0
  6. data/doc/opening_databases.rdoc +10 -6
  7. data/doc/release_notes/5.58.0.txt +31 -0
  8. data/doc/release_notes/5.59.0.txt +73 -0
  9. data/doc/release_notes/5.60.0.txt +22 -0
  10. data/doc/testing.rdoc +1 -1
  11. data/lib/sequel/adapters/jdbc/derby.rb +5 -0
  12. data/lib/sequel/adapters/jdbc/h2.rb +5 -0
  13. data/lib/sequel/adapters/jdbc/hsqldb.rb +6 -0
  14. data/lib/sequel/adapters/jdbc/sqlite.rb +1 -1
  15. data/lib/sequel/adapters/jdbc.rb +5 -5
  16. data/lib/sequel/adapters/mock.rb +1 -1
  17. data/lib/sequel/adapters/mysql.rb +3 -3
  18. data/lib/sequel/adapters/oracle.rb +1 -1
  19. data/lib/sequel/adapters/postgres.rb +58 -17
  20. data/lib/sequel/adapters/shared/db2.rb +28 -0
  21. data/lib/sequel/adapters/shared/mssql.rb +35 -1
  22. data/lib/sequel/adapters/shared/mysql.rb +6 -0
  23. data/lib/sequel/adapters/shared/oracle.rb +70 -1
  24. data/lib/sequel/adapters/shared/postgres.rb +94 -18
  25. data/lib/sequel/adapters/shared/sqlite.rb +1 -1
  26. data/lib/sequel/adapters/sqlite.rb +1 -1
  27. data/lib/sequel/ast_transformer.rb +1 -1
  28. data/lib/sequel/database/misc.rb +2 -2
  29. data/lib/sequel/database/schema_generator.rb +1 -0
  30. data/lib/sequel/database/schema_methods.rb +3 -0
  31. data/lib/sequel/dataset/actions.rb +49 -0
  32. data/lib/sequel/dataset/features.rb +5 -0
  33. data/lib/sequel/dataset/query.rb +62 -0
  34. data/lib/sequel/dataset/sql.rb +114 -27
  35. data/lib/sequel/extensions/date_arithmetic.rb +35 -7
  36. data/lib/sequel/extensions/duplicate_columns_handler.rb +1 -1
  37. data/lib/sequel/extensions/is_distinct_from.rb +3 -1
  38. data/lib/sequel/extensions/pg_array.rb +2 -2
  39. data/lib/sequel/extensions/pg_array_ops.rb +1 -1
  40. data/lib/sequel/extensions/pg_enum.rb +1 -1
  41. data/lib/sequel/extensions/pg_hstore.rb +1 -1
  42. data/lib/sequel/extensions/pg_hstore_ops.rb +3 -3
  43. data/lib/sequel/extensions/pg_inet.rb +2 -2
  44. data/lib/sequel/extensions/pg_interval.rb +1 -1
  45. data/lib/sequel/extensions/pg_json.rb +1 -1
  46. data/lib/sequel/extensions/pg_json_ops.rb +55 -3
  47. data/lib/sequel/extensions/pg_multirange.rb +2 -2
  48. data/lib/sequel/extensions/pg_range.rb +2 -2
  49. data/lib/sequel/extensions/pg_row.rb +2 -2
  50. data/lib/sequel/extensions/pg_static_cache_updater.rb +2 -2
  51. data/lib/sequel/extensions/symbol_aref.rb +2 -0
  52. data/lib/sequel/model/associations.rb +18 -6
  53. data/lib/sequel/model/base.rb +17 -7
  54. data/lib/sequel/model/exceptions.rb +1 -1
  55. data/lib/sequel/model/inflections.rb +6 -6
  56. data/lib/sequel/plugins/auto_validations.rb +1 -1
  57. data/lib/sequel/plugins/defaults_setter.rb +1 -1
  58. data/lib/sequel/plugins/dirty.rb +1 -1
  59. data/lib/sequel/plugins/insert_conflict.rb +1 -1
  60. data/lib/sequel/plugins/json_serializer.rb +1 -1
  61. data/lib/sequel/plugins/list.rb +3 -1
  62. data/lib/sequel/plugins/nested_attributes.rb +1 -1
  63. data/lib/sequel/plugins/pg_auto_constraint_validations.rb +1 -1
  64. data/lib/sequel/plugins/require_valid_schema.rb +67 -0
  65. data/lib/sequel/plugins/serialization.rb +1 -1
  66. data/lib/sequel/plugins/sharding.rb +1 -1
  67. data/lib/sequel/plugins/sql_comments.rb +4 -4
  68. data/lib/sequel/plugins/subclasses.rb +1 -1
  69. data/lib/sequel/plugins/tactical_eager_loading.rb +7 -0
  70. data/lib/sequel/plugins/validation_class_methods.rb +3 -3
  71. data/lib/sequel/plugins/validation_helpers.rb +1 -1
  72. data/lib/sequel/sql.rb +1 -1
  73. data/lib/sequel/version.rb +1 -1
  74. metadata +9 -16
@@ -152,7 +152,7 @@ module Sequel
152
152
  if obj.is_a?(Array)
153
153
  obj.map{|x| object_to_json_data(x, *args, &block)}
154
154
  else
155
- if obj.respond_to?(:to_json_data)
155
+ if defined?(obj.to_json_data)
156
156
  obj.to_json_data(*args, &block)
157
157
  else
158
158
  begin
@@ -33,7 +33,9 @@ module Sequel
33
33
  # You can provide a <tt>:scope</tt> option to scope the list. This option
34
34
  # can be a symbol or array of symbols specifying column name(s), or a proc
35
35
  # that accepts a model instance and returns a dataset representing the list
36
- # the object is in.
36
+ # the object is in. You will need to provide a <tt>:scope</tt> option if
37
+ # the model's dataset uses a subquery (such as when using the class_table_inheritance
38
+ # plugin).
37
39
  #
38
40
  # For example, if each item has a +user_id+ field, and you want every user
39
41
  # to have their own list:
@@ -259,7 +259,7 @@ module Sequel
259
259
  # specific :fields if configured.
260
260
  def nested_attributes_set_attributes(meta, obj, attributes)
261
261
  if fields = meta[:fields]
262
- fields = fields.call(obj) if fields.respond_to?(:call)
262
+ fields = fields.call(obj) if defined?(fields.call)
263
263
  obj.set_fields(attributes, fields, :missing=>:skip)
264
264
  else
265
265
  obj.set(attributes)
@@ -159,7 +159,7 @@ module Sequel
159
159
 
160
160
  case @dataset.first_source_table
161
161
  when Symbol, String, SQL::Identifier, SQL::QualifiedIdentifier
162
- convert_errors = db.respond_to?(:error_info)
162
+ convert_errors = defined?(db.error_info)
163
163
  end
164
164
 
165
165
  unless convert_errors
@@ -0,0 +1,67 @@
1
+ # frozen-string-literal: true
2
+
3
+ module Sequel
4
+ module Plugins
5
+ # The require_valid_schema plugin makes Sequel raise or warn if attempting
6
+ # to set the dataset of a model class to a simple table, where the database
7
+ # supports schema parsing, but schema parsing does not work for the model's
8
+ # table.
9
+ #
10
+ # The plugin's default behavior requires that all models that select from a
11
+ # single identifier have a valid table schema, if the database supports
12
+ # schema parsing. If the schema cannot be determined for such
13
+ # a model, an error is raised:
14
+ #
15
+ # Sequel::Model.plugin :require_valid_schema
16
+ #
17
+ # If you load the plugin with an argument of :warn, Sequel will warn instead
18
+ # of raising for such tables:
19
+ #
20
+ # Sequel::Model.plugin :require_valid_schema, :warn
21
+ #
22
+ # This can catch bugs where you expect models to have valid schema, but
23
+ # they do not. This setting only affects future attempts to set datasets
24
+ # in the current class and subclasses created in the future.
25
+ #
26
+ # If you load the plugin with an argument of false, it will not require valid schema.
27
+ # This can be used in subclasses where you do not want to require valid schema,
28
+ # but the plugin must be loaded before a dataset with invalid schema is set:
29
+ #
30
+ # Sequel::Model.plugin :require_valid_schema
31
+ # InvalidSchemaAllowed = Class.new(Sequel::Model)
32
+ # InvalidSchemaAllowed.plugin :require_valid_schema, false
33
+ # class MyModel < InvalidSchemaAllowed
34
+ # end
35
+ module RequireValidSchema
36
+ # Modify the current model's dataset selection, if the model
37
+ # has a dataset.
38
+ def self.configure(model, setting=true)
39
+ model.instance_variable_set(:@require_valid_schema, setting)
40
+ end
41
+
42
+ module ClassMethods
43
+ Plugins.inherited_instance_variables(self, :@require_valid_schema=>nil)
44
+
45
+ private
46
+
47
+ # If the schema cannot be determined, the model uses a simple table,
48
+ # require_valid_schema is set, and the database supports schema parsing, raise or
49
+ # warn based on the require_valid_schema setting.
50
+ def get_db_schema_array(reload)
51
+ schema_array = super
52
+
53
+ if !schema_array && simple_table && @require_valid_schema
54
+ message = "Not able to parse schema for model: #{inspect}, table: #{simple_table}"
55
+ if @require_valid_schema == :warn
56
+ warn message
57
+ else
58
+ raise Error, message
59
+ end
60
+ end
61
+
62
+ schema_array
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -162,7 +162,7 @@ module Sequel
162
162
  if !cc.include?(column) && (new? || get_column_value(column) != v)
163
163
  cc << column
164
164
 
165
- will_change_column(column) if respond_to?(:will_change_column)
165
+ will_change_column(column) if defined?(will_change_column)
166
166
  end
167
167
 
168
168
  deserialized_values[column] = v
@@ -91,7 +91,7 @@ module Sequel
91
91
  # +many_to_many+ association, make sure the associated object is created on the
92
92
  # current object's shard, unless the passed object already has an assigned shard.
93
93
  def ensure_associated_primary_key(opts, o, *args)
94
- o.set_server?(@server) if o.respond_to?(:set_server?)
94
+ o.set_server?(@server) if defined?(o.set_server?)
95
95
  super
96
96
  end
97
97
 
@@ -63,7 +63,7 @@ module Sequel
63
63
  end
64
64
  end
65
65
  # :nocov:
66
- ruby2_keywords(meth) if respond_to?(:ruby2_keywords, false)
66
+ mod.send(:ruby2_keywords, meth) if mod.respond_to?(:ruby2_keywords, true)
67
67
  # :nocov:
68
68
  end
69
69
 
@@ -97,7 +97,7 @@ module Sequel
97
97
  end
98
98
  end
99
99
  # :nocov:
100
- ruby2_keywords(meth) if respond_to?(:ruby2_keywords, false)
100
+ ruby2_keywords(meth) if respond_to?(:ruby2_keywords, true)
101
101
  # :nocov:
102
102
  end
103
103
 
@@ -129,7 +129,7 @@ module Sequel
129
129
  end
130
130
  end
131
131
  # :nocov:
132
- ruby2_keywords(meth) if respond_to?(:ruby2_keywords, false)
132
+ ruby2_keywords(meth) if respond_to?(:ruby2_keywords, true)
133
133
  # :nocov:
134
134
  end
135
135
 
@@ -159,7 +159,7 @@ module Sequel
159
159
  end
160
160
  end
161
161
  # :nocov:
162
- ruby2_keywords(meth) if respond_to?(:ruby2_keywords, false)
162
+ ruby2_keywords(meth) if respond_to?(:ruby2_keywords, true)
163
163
  # :nocov:
164
164
  end
165
165
 
@@ -35,7 +35,7 @@ module Sequel
35
35
  # class B < Sequel::Model; end
36
36
  # a # => [A, B]
37
37
  module Subclasses
38
- NEED_SUBCLASSES = !Object.respond_to?(:subclasses) || Object.method(:subclasses).source_location
38
+ NEED_SUBCLASSES = !defined?(Object.subclasses) || Object.method(:subclasses).source_location
39
39
  private_constant :NEED_SUBCLASSES
40
40
 
41
41
  # Initialize the subclasses instance variable for the model.
@@ -109,6 +109,13 @@ module Sequel
109
109
  # to eagerly set the associated objects, and having separate threads
110
110
  # modify the same model instance is not thread-safe.
111
111
  #
112
+ # Because this plugin will automatically use eager loading for
113
+ # performance, it can break code that defines associations that
114
+ # do not support eager loading, without marking that they do not
115
+ # support eager loading via the <tt>allow_eager: false</tt> option.
116
+ # Make sure to set <tt>allow_eager: false</tt> on any association
117
+ # used with this plugin if the association doesn't support eager loading.
118
+ #
112
119
  # Usage:
113
120
  #
114
121
  # # Make all model subclass instances use tactical eager loading (called before loading subclasses)
@@ -282,7 +282,7 @@ module Sequel
282
282
  o.errors.add(a, opts[:message] || opts[:wrong_length]) unless v && v.size == i
283
283
  end
284
284
  if w = opts[:within]
285
- o.errors.add(a, opts[:message] || opts[:wrong_length]) unless v && w.public_send(w.respond_to?(:cover?) ? :cover? : :include?, v.size)
285
+ o.errors.add(a, opts[:message] || opts[:wrong_length]) unless v && w.public_send(defined?(w.cover?) ? :cover? : :include?, v.size)
286
286
  end
287
287
  end
288
288
  end
@@ -337,14 +337,14 @@ module Sequel
337
337
  def validates_inclusion_of(*atts)
338
338
  opts = extract_options!(atts)
339
339
  n = opts[:in]
340
- unless n && (n.respond_to?(:cover?) || n.respond_to?(:include?))
340
+ unless n && (defined?(n.cover?) || defined?(n.include?))
341
341
  raise ArgumentError, "The :in parameter is required, and must respond to cover? or include?"
342
342
  end
343
343
  opts[:message] ||= "is not in range or set: #{n.inspect}"
344
344
  reflect_validation(:inclusion, opts, atts)
345
345
  atts << opts
346
346
  validates_each(*atts) do |o, a, v|
347
- o.errors.add(a, opts[:message]) unless n.public_send(n.respond_to?(:cover?) ? :cover? : :include?, v)
347
+ o.errors.add(a, opts[:message]) unless n.public_send(defined?(n.cover?) ? :cover? : :include?, v)
348
348
  end
349
349
  end
350
350
 
@@ -107,7 +107,7 @@ module Sequel
107
107
 
108
108
  # Check attribute value(s) is included in the given set.
109
109
  def validates_includes(set, atts, opts=OPTS)
110
- validatable_attributes_for_type(:includes, atts, opts){|a,v,m| validation_error_message(m, set) unless set.public_send(set.respond_to?(:cover?) ? :cover? : :include?, v)}
110
+ validatable_attributes_for_type(:includes, atts, opts){|a,v,m| validation_error_message(m, set) unless set.public_send(defined?(set.cover?) ? :cover? : :include?, v)}
111
111
  end
112
112
 
113
113
  # Check attribute value(s) string representation is a valid integer.
data/lib/sequel/sql.rb CHANGED
@@ -1347,7 +1347,7 @@ module Sequel
1347
1347
  # underlying callable only accepts a single argument, call it
1348
1348
  # with the given dataset.
1349
1349
  def call(ds)
1350
- if @callable.respond_to?(:arity) && @callable.arity == 1
1350
+ if defined?(@callable.arity) && @callable.arity == 1
1351
1351
  @callable.call(ds)
1352
1352
  else
1353
1353
  @callable.call
@@ -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 = 57
9
+ MINOR = 60
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.57.0
4
+ version: 5.60.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-01 00:00:00.000000000 Z
11
+ date: 2022-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: minitest-shared_description
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: tzinfo
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -202,7 +188,10 @@ extra_rdoc_files:
202
188
  - doc/release_notes/5.55.0.txt
203
189
  - doc/release_notes/5.56.0.txt
204
190
  - doc/release_notes/5.57.0.txt
191
+ - doc/release_notes/5.58.0.txt
192
+ - doc/release_notes/5.59.0.txt
205
193
  - doc/release_notes/5.6.0.txt
194
+ - doc/release_notes/5.60.0.txt
206
195
  - doc/release_notes/5.7.0.txt
207
196
  - doc/release_notes/5.8.0.txt
208
197
  - doc/release_notes/5.9.0.txt
@@ -287,7 +276,10 @@ files:
287
276
  - doc/release_notes/5.55.0.txt
288
277
  - doc/release_notes/5.56.0.txt
289
278
  - doc/release_notes/5.57.0.txt
279
+ - doc/release_notes/5.58.0.txt
280
+ - doc/release_notes/5.59.0.txt
290
281
  - doc/release_notes/5.6.0.txt
282
+ - doc/release_notes/5.60.0.txt
291
283
  - doc/release_notes/5.7.0.txt
292
284
  - doc/release_notes/5.8.0.txt
293
285
  - doc/release_notes/5.9.0.txt
@@ -539,6 +531,7 @@ files:
539
531
  - lib/sequel/plugins/prepared_statements.rb
540
532
  - lib/sequel/plugins/prepared_statements_safe.rb
541
533
  - lib/sequel/plugins/rcte_tree.rb
534
+ - lib/sequel/plugins/require_valid_schema.rb
542
535
  - lib/sequel/plugins/serialization.rb
543
536
  - lib/sequel/plugins/serialization_modification_detection.rb
544
537
  - lib/sequel/plugins/sharding.rb