sequel 4.47.0 → 4.48.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 (177) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +134 -0
  3. data/Rakefile +1 -1
  4. data/doc/release_notes/4.48.0.txt +293 -0
  5. data/lib/sequel/adapters/ado/access.rb +2 -1
  6. data/lib/sequel/adapters/do/postgres.rb +5 -2
  7. data/lib/sequel/adapters/ibmdb.rb +24 -7
  8. data/lib/sequel/adapters/jdbc.rb +36 -22
  9. data/lib/sequel/adapters/jdbc/db2.rb +12 -3
  10. data/lib/sequel/adapters/jdbc/derby.rb +4 -5
  11. data/lib/sequel/adapters/jdbc/oracle.rb +16 -2
  12. data/lib/sequel/adapters/jdbc/postgresql.rb +43 -18
  13. data/lib/sequel/adapters/jdbc/sqlanywhere.rb +9 -7
  14. data/lib/sequel/adapters/jdbc/sqlserver.rb +11 -4
  15. data/lib/sequel/adapters/mock.rb +24 -19
  16. data/lib/sequel/adapters/mysql.rb +17 -16
  17. data/lib/sequel/adapters/mysql2.rb +4 -5
  18. data/lib/sequel/adapters/oracle.rb +5 -9
  19. data/lib/sequel/adapters/postgres.rb +89 -102
  20. data/lib/sequel/adapters/shared/db2.rb +22 -6
  21. data/lib/sequel/adapters/shared/mssql.rb +5 -4
  22. data/lib/sequel/adapters/shared/mysql.rb +75 -24
  23. data/lib/sequel/adapters/shared/postgres.rb +196 -94
  24. data/lib/sequel/adapters/shared/sqlanywhere.rb +23 -10
  25. data/lib/sequel/adapters/shared/sqlite.rb +72 -82
  26. data/lib/sequel/adapters/sqlanywhere.rb +4 -1
  27. data/lib/sequel/adapters/sqlite.rb +5 -3
  28. data/lib/sequel/adapters/swift/postgres.rb +5 -2
  29. data/lib/sequel/adapters/tinytds.rb +0 -5
  30. data/lib/sequel/adapters/utils/mysql_mysql2.rb +1 -1
  31. data/lib/sequel/adapters/utils/pg_types.rb +2 -76
  32. data/lib/sequel/core.rb +2 -2
  33. data/lib/sequel/database/connecting.rb +5 -5
  34. data/lib/sequel/database/dataset.rb +6 -3
  35. data/lib/sequel/database/misc.rb +1 -1
  36. data/lib/sequel/database/query.rb +3 -0
  37. data/lib/sequel/database/schema_methods.rb +1 -1
  38. data/lib/sequel/dataset/actions.rb +18 -10
  39. data/lib/sequel/dataset/graph.rb +1 -1
  40. data/lib/sequel/dataset/misc.rb +1 -0
  41. data/lib/sequel/dataset/prepared_statements.rb +3 -3
  42. data/lib/sequel/dataset/query.rb +19 -8
  43. data/lib/sequel/extensions/core_extensions.rb +4 -1
  44. data/lib/sequel/extensions/duplicate_columns_handler.rb +1 -1
  45. data/lib/sequel/extensions/empty_array_ignore_nulls.rb +3 -0
  46. data/lib/sequel/extensions/filter_having.rb +2 -0
  47. data/lib/sequel/extensions/freeze_datasets.rb +2 -0
  48. data/lib/sequel/extensions/from_block.rb +1 -1
  49. data/lib/sequel/extensions/graph_each.rb +2 -2
  50. data/lib/sequel/extensions/hash_aliases.rb +2 -0
  51. data/lib/sequel/extensions/identifier_mangling.rb +0 -7
  52. data/lib/sequel/extensions/meta_def.rb +2 -0
  53. data/lib/sequel/extensions/migration.rb +6 -6
  54. data/lib/sequel/extensions/no_auto_literal_strings.rb +1 -1
  55. data/lib/sequel/extensions/pagination.rb +1 -1
  56. data/lib/sequel/extensions/pg_array.rb +207 -130
  57. data/lib/sequel/extensions/pg_hstore.rb +38 -20
  58. data/lib/sequel/extensions/pg_inet.rb +18 -6
  59. data/lib/sequel/extensions/pg_interval.rb +19 -12
  60. data/lib/sequel/extensions/pg_json.rb +25 -14
  61. data/lib/sequel/extensions/pg_json_ops.rb +2 -2
  62. data/lib/sequel/extensions/pg_range.rb +133 -100
  63. data/lib/sequel/extensions/pg_range_ops.rb +4 -3
  64. data/lib/sequel/extensions/pg_row.rb +68 -39
  65. data/lib/sequel/extensions/pg_row_ops.rb +11 -5
  66. data/lib/sequel/extensions/query_literals.rb +2 -0
  67. data/lib/sequel/extensions/ruby18_symbol_extensions.rb +2 -0
  68. data/lib/sequel/extensions/s.rb +1 -1
  69. data/lib/sequel/extensions/schema_dumper.rb +24 -24
  70. data/lib/sequel/extensions/sequel_3_dataset_methods.rb +3 -1
  71. data/lib/sequel/extensions/sequel_4_dataset_methods.rb +83 -0
  72. data/lib/sequel/extensions/set_overrides.rb +2 -2
  73. data/lib/sequel/extensions/string_agg.rb +0 -1
  74. data/lib/sequel/extensions/symbol_aref.rb +0 -4
  75. data/lib/sequel/model.rb +25 -57
  76. data/lib/sequel/model/associations.rb +14 -5
  77. data/lib/sequel/model/base.rb +96 -32
  78. data/lib/sequel/plugins/association_pks.rb +73 -46
  79. data/lib/sequel/plugins/association_proxies.rb +1 -1
  80. data/lib/sequel/plugins/auto_validations.rb +6 -2
  81. data/lib/sequel/plugins/boolean_readers.rb +1 -1
  82. data/lib/sequel/plugins/caching.rb +19 -13
  83. data/lib/sequel/plugins/class_table_inheritance.rb +19 -10
  84. data/lib/sequel/plugins/column_conflicts.rb +7 -2
  85. data/lib/sequel/plugins/column_select.rb +1 -1
  86. data/lib/sequel/plugins/csv_serializer.rb +8 -8
  87. data/lib/sequel/plugins/defaults_setter.rb +10 -0
  88. data/lib/sequel/plugins/eager_each.rb +1 -1
  89. data/lib/sequel/plugins/force_encoding.rb +2 -2
  90. data/lib/sequel/plugins/hook_class_methods.rb +9 -12
  91. data/lib/sequel/plugins/identifier_columns.rb +2 -0
  92. data/lib/sequel/plugins/instance_filters.rb +3 -1
  93. data/lib/sequel/plugins/instance_hooks.rb +17 -9
  94. data/lib/sequel/plugins/json_serializer.rb +17 -10
  95. data/lib/sequel/plugins/lazy_attributes.rb +8 -7
  96. data/lib/sequel/plugins/modification_detection.rb +3 -0
  97. data/lib/sequel/plugins/nested_attributes.rb +5 -1
  98. data/lib/sequel/plugins/pg_array_associations.rb +5 -0
  99. data/lib/sequel/plugins/prepared_statements.rb +1 -0
  100. data/lib/sequel/plugins/rcte_tree.rb +4 -4
  101. data/lib/sequel/plugins/serialization.rb +3 -10
  102. data/lib/sequel/plugins/single_table_inheritance.rb +2 -2
  103. data/lib/sequel/plugins/split_values.rb +6 -5
  104. data/lib/sequel/plugins/static_cache.rb +31 -25
  105. data/lib/sequel/plugins/subset_conditions.rb +3 -1
  106. data/lib/sequel/plugins/table_select.rb +1 -1
  107. data/lib/sequel/plugins/touch.rb +2 -1
  108. data/lib/sequel/plugins/validation_class_methods.rb +5 -6
  109. data/lib/sequel/plugins/validation_helpers.rb +2 -4
  110. data/lib/sequel/plugins/xml_serializer.rb +4 -4
  111. data/lib/sequel/sql.rb +2 -2
  112. data/lib/sequel/version.rb +1 -1
  113. data/spec/adapters/db2_spec.rb +115 -14
  114. data/spec/adapters/mysql_spec.rb +78 -28
  115. data/spec/adapters/oracle_spec.rb +24 -24
  116. data/spec/adapters/postgres_spec.rb +38 -24
  117. data/spec/adapters/sqlanywhere_spec.rb +88 -86
  118. data/spec/adapters/sqlite_spec.rb +29 -24
  119. data/spec/core/connection_pool_spec.rb +17 -0
  120. data/spec/core/database_spec.rb +6 -0
  121. data/spec/core/dataset_spec.rb +46 -36
  122. data/spec/core/schema_spec.rb +16 -0
  123. data/spec/core/spec_helper.rb +1 -0
  124. data/spec/core_extensions_spec.rb +6 -2
  125. data/spec/extensions/active_model_spec.rb +1 -1
  126. data/spec/extensions/arbitrary_servers_spec.rb +1 -1
  127. data/spec/extensions/association_pks_spec.rb +34 -2
  128. data/spec/extensions/auto_literal_strings_spec.rb +5 -1
  129. data/spec/extensions/auto_validations_spec.rb +2 -0
  130. data/spec/extensions/boolean_readers_spec.rb +1 -1
  131. data/spec/extensions/boolean_subsets_spec.rb +1 -1
  132. data/spec/extensions/class_table_inheritance_spec.rb +48 -2
  133. data/spec/extensions/column_conflicts_spec.rb +11 -0
  134. data/spec/extensions/connection_validator_spec.rb +1 -1
  135. data/spec/extensions/dataset_associations_spec.rb +8 -8
  136. data/spec/extensions/defaults_setter_spec.rb +1 -1
  137. data/spec/extensions/filter_having_spec.rb +5 -3
  138. data/spec/extensions/hash_aliases_spec.rb +3 -1
  139. data/spec/extensions/identifier_columns_spec.rb +3 -1
  140. data/spec/extensions/implicit_subquery_spec.rb +4 -2
  141. data/spec/extensions/json_serializer_spec.rb +18 -0
  142. data/spec/extensions/lazy_attributes_spec.rb +3 -3
  143. data/spec/extensions/meta_def_spec.rb +9 -0
  144. data/spec/extensions/migration_spec.rb +3 -3
  145. data/spec/extensions/nested_attributes_spec.rb +14 -3
  146. data/spec/extensions/no_auto_literal_strings_spec.rb +8 -4
  147. data/spec/extensions/pg_array_associations_spec.rb +29 -18
  148. data/spec/extensions/pg_array_spec.rb +44 -25
  149. data/spec/extensions/pg_hstore_spec.rb +10 -0
  150. data/spec/extensions/pg_inet_spec.rb +26 -0
  151. data/spec/extensions/pg_interval_spec.rb +20 -0
  152. data/spec/extensions/pg_json_spec.rb +24 -0
  153. data/spec/extensions/pg_range_spec.rb +98 -14
  154. data/spec/extensions/pg_row_spec.rb +14 -4
  155. data/spec/extensions/prepared_statements_safe_spec.rb +1 -1
  156. data/spec/extensions/query_literals_spec.rb +3 -1
  157. data/spec/extensions/schema_dumper_spec.rb +96 -98
  158. data/spec/extensions/sequel_3_dataset_methods_spec.rb +10 -6
  159. data/spec/extensions/sequel_4_dataset_methods_spec.rb +121 -0
  160. data/spec/extensions/single_table_inheritance_spec.rb +1 -1
  161. data/spec/extensions/spec_helper.rb +7 -1
  162. data/spec/extensions/static_cache_spec.rb +75 -24
  163. data/spec/extensions/string_agg_spec.rb +1 -1
  164. data/spec/extensions/touch_spec.rb +9 -0
  165. data/spec/extensions/validation_helpers_spec.rb +9 -3
  166. data/spec/extensions/whitelist_security_spec.rb +26 -0
  167. data/spec/integration/dataset_test.rb +45 -44
  168. data/spec/integration/plugin_test.rb +20 -0
  169. data/spec/integration/prepared_statement_test.rb +3 -0
  170. data/spec/integration/schema_test.rb +21 -1
  171. data/spec/integration/transaction_test.rb +40 -40
  172. data/spec/model/class_dataset_methods_spec.rb +14 -4
  173. data/spec/model/dataset_methods_spec.rb +12 -3
  174. data/spec/model/model_spec.rb +8 -0
  175. metadata +6 -4
  176. data/spec/adapters/firebird_spec.rb +0 -405
  177. data/spec/adapters/informix_spec.rb +0 -100
@@ -188,8 +188,8 @@ module Sequel
188
188
 
189
189
  # Convert given object to json and return the result.
190
190
  # This can be overridden to use an alternative json implementation.
191
- def self.object_to_json(obj, *args)
192
- obj.to_json(*args)
191
+ def self.object_to_json(obj, *args, &block)
192
+ obj.to_json(*args, &block)
193
193
  end
194
194
 
195
195
  # Parse the string as JSON and return the result.
@@ -8,7 +8,7 @@ module Sequel
8
8
  # ---------------------
9
9
 
10
10
  # Array of supported database adapters
11
- ADAPTERS = %w'ado amalgalite cubrid do ibmdb jdbc mock mysql mysql2 odbc oracle postgres sqlanywhere sqlite swift tinytds'.collect(&:to_sym)
11
+ ADAPTERS = %w'ado amalgalite cubrid do ibmdb jdbc mock mysql mysql2 odbc oracle postgres sqlanywhere sqlite swift tinytds'.map(&:to_sym)
12
12
  # SEQUEL5: Remove cubrid do swift
13
13
 
14
14
  def self.single_threaded
@@ -49,7 +49,7 @@ module Sequel
49
49
  case conn_string
50
50
  when String
51
51
  # SEQUEL5: Remove do
52
- if match = /\A(jdbc|do):/o.match(conn_string)
52
+ if match = /\A(jdbc|do):/.match(conn_string)
53
53
  c = adapter_class(match[1].to_sym)
54
54
  opts = opts.merge(:orig_opts=>opts.dup)
55
55
  opts = {:uri=>conn_string}.merge!(opts)
@@ -58,7 +58,7 @@ module Sequel
58
58
  scheme = uri.scheme
59
59
  c = adapter_class(scheme)
60
60
  uri_options = c.send(:uri_to_options, uri)
61
- uri.query.split('&').collect{|s| s.split('=')}.each{|k,v| uri_options[k.to_sym] = v if k && !k.empty?} unless uri.query.to_s.strip.empty?
61
+ uri.query.split('&').map{|s| s.split('=')}.each{|k,v| uri_options[k.to_sym] = v if k && !k.empty?} unless uri.query.to_s.strip.empty?
62
62
  uri_options.to_a.each{|k,v| uri_options[k] = (defined?(URI::DEFAULT_PARSER) ? URI::DEFAULT_PARSER : URI).unescape(v) if v.is_a?(String)}
63
63
  opts = uri_options.merge(opts).merge!(:orig_opts=>opts.dup, :uri=>conn_string, :adapter=>scheme)
64
64
  end
@@ -197,7 +197,7 @@ module Sequel
197
197
  # DB.add_servers(:f=>{:host=>"hash_host_f"})
198
198
  def add_servers(servers)
199
199
  unless h = @opts[:servers]
200
- Sequel::Deprecation.deprecate("Calling Database#add_servers on a database that does not use sharding", "This method should only be called if the database supports sharding.")
200
+ Sequel::Deprecation.deprecate("Calling Database#add_servers on a database that does not use sharding", "This method should only be called if the database supports sharding")
201
201
  # raise Error, "cannot call Database#add_servers on a Database instance that does not use a sharded connection pool" # SEQUEL5
202
202
  return
203
203
  end
@@ -262,7 +262,7 @@ module Sequel
262
262
  # DB.remove_servers(:f1, :f2)
263
263
  def remove_servers(*servers)
264
264
  unless h = @opts[:servers]
265
- Sequel::Deprecation.deprecate("Calling Database#add_servers on a database that does not use sharding", "This method should only be called if the database supports sharding.")
265
+ Sequel::Deprecation.deprecate("Calling Database#add_servers on a database that does not use sharding", "This method should only be called if the database supports sharding")
266
266
  # raise Error, "cannot call Database#remove_servers on a Database instance that does not use a sharded connection pool" # SEQUEL5
267
267
  return
268
268
  end
@@ -58,12 +58,15 @@ module Sequel
58
58
  # DB.from(:items) # SELECT * FROM items
59
59
  # DB.from(:items){id > 2} # SELECT * FROM items WHERE (id > 2)
60
60
  def from(*args, &block)
61
- ds = @default_dataset.from(*args)
62
61
  if block
63
62
  Sequel::Deprecation.deprecate("Sequel::Database#from with a block", "Use .from(*args).where(&block) instead")
64
- ds.where(&block)
63
+ @default_dataset.from(*args).where(&block)
64
+ #SEQUEL5
65
+ # @default_dataset.from(*args, &block)
66
+ #elsif args.length == 1 && (table = args[0]).is_a?(Symbol)
67
+ # @default_dataset.send(:cached_dataset, :"_from_#{table}_ds"){@default_dataset.from(table)}
65
68
  else
66
- ds
69
+ @default_dataset.from(*args)
67
70
  end
68
71
  end
69
72
 
@@ -31,7 +31,7 @@ module Sequel
31
31
  module ResetIdentifierMangling
32
32
  def self.extended(obj)
33
33
  # :nocov:
34
- Sequel::Deprecation.deprecate("Sequel::Database::ResetIdentifierMangling is no longer needed and will be removed in Sequel 5. Please update your adapter.")
34
+ Sequel::Deprecation.deprecate("Sequel::Database::ResetIdentifierMangling is no longer needed and will be removed in Sequel 5. Please update your adapter")
35
35
  obj.send(:reset_identifier_mangling) if obj.respond_to?(:reset_identifier_mangling)
36
36
  # :nocov:
37
37
  end
@@ -310,6 +310,9 @@ module Sequel
310
310
 
311
311
  # Remove the cached schema for the given schema name
312
312
  def remove_cached_schema(table)
313
+ #SEQUEL5
314
+ #cache = @default_dataset.send(:cache)
315
+ #Sequel.synchronize{cache.clear}
313
316
  k = quote_schema_table(table)
314
317
  Sequel.synchronize{@schemas.delete(k)}
315
318
  end
@@ -707,7 +707,7 @@ module Sequel
707
707
  e = options[:ignore_index_errors] || options[:if_not_exists]
708
708
  generator.indexes.each do |index|
709
709
  begin
710
- index_sql_list(name, [index]).each{|sql| execute_ddl(sql)}
710
+ transaction(:savepoint=>:only){index_sql_list(name, [index]).each{|sql| execute_ddl(sql)}}
711
711
  rescue Error
712
712
  raise unless e
713
713
  end
@@ -11,11 +11,12 @@ module Sequel
11
11
 
12
12
  # Action methods defined by Sequel that execute code on the database.
13
13
  ACTION_METHODS = (<<-METHS).split.map(&:to_sym).freeze
14
- << [] all avg count columns columns! delete each
14
+ << [] all as_hash avg count columns columns! delete each
15
15
  empty? fetch_rows first first! get import insert interval last
16
16
  map max min multi_insert paged_each range select_hash select_hash_groups select_map select_order_map
17
17
  single_record single_record! single_value single_value! sum to_hash to_hash_groups truncate update
18
18
  METHS
19
+ # SEQUEL5: Remove interval, range
19
20
 
20
21
  # The clone options to use when retriveing columns for a dataset.
21
22
  COLUMNS_CLONE_OPTIONS = {:distinct => nil, :limit => 1, :offset=>nil, :where=>nil, :having=>nil, :order=>nil, :row_proc=>nil, :graph=>nil, :eager_graph=>nil}.freeze
@@ -410,6 +411,7 @@ module Sequel
410
411
  # DB[:table].interval{function(column)} # SELECT (max(function(column)) - min(function(column))) FROM table LIMIT 1
411
412
  # # => 7
412
413
  def interval(column=Sequel.virtual_row(&Proc.new))
414
+ Sequel::Deprecation.deprecate("Sequel::Dataset#interval", "Use #max - #min, or use the sequel_4_dataset_methods extension")
413
415
  if loader = cached_placeholder_literalizer(:_interval_loader) do |pl|
414
416
  arg = pl.arg
415
417
  aggregate_dataset.limit(1).select((SQL::Function.new(:max, arg) - SQL::Function.new(:min, arg)).as(:interval))
@@ -623,6 +625,7 @@ module Sequel
623
625
  # DB[:table].interval{function(column)} # SELECT max(function(column)) AS v1, min(function(column)) AS v2 FROM table LIMIT 1
624
626
  # # => 0..7
625
627
  def range(column=Sequel.virtual_row(&Proc.new))
628
+ Sequel::Deprecation.deprecate("Sequel::Dataset#range", "Use #min..#max, or use the sequel_4_dataset_methods extension")
626
629
  r = if loader = cached_placeholder_literalizer(:_range_loader) do |pl|
627
630
  arg = pl.arg
628
631
  aggregate_dataset.limit(1).select(SQL::Function.new(:min, arg).as(:v1), SQL::Function.new(:max, arg).as(:v2))
@@ -639,8 +642,8 @@ module Sequel
639
642
  end
640
643
 
641
644
  # Returns a hash with key_column values as keys and value_column values as
642
- # values. Similar to to_hash, but only selects the columns given. Like
643
- # to_hash, it accepts an optional :hash parameter, into which entries will
645
+ # values. Similar to as_hash, but only selects the columns given. Like
646
+ # as_hash, it accepts an optional :hash parameter, into which entries will
644
647
  # be merged.
645
648
  #
646
649
  # DB[:table].select_hash(:id, :name) # SELECT id, name FROM table
@@ -656,7 +659,7 @@ module Sequel
656
659
  # that Sequel can determine. Usually you can do this by calling the #as method
657
660
  # on the expression and providing an alias.
658
661
  def select_hash(key_column, value_column, opts = OPTS)
659
- _select_hash(:to_hash, key_column, value_column, opts)
662
+ _select_hash(:as_hash, key_column, value_column, opts)
660
663
  end
661
664
 
662
665
  # Returns a hash with key_column values as keys and an array of value_column values.
@@ -786,19 +789,19 @@ module Sequel
786
789
  # will overwrite the value of the previous row(s). If the value_column
787
790
  # is not given or nil, uses the entire hash as the value.
788
791
  #
789
- # DB[:table].to_hash(:id, :name) # SELECT * FROM table
792
+ # DB[:table].as_hash(:id, :name) # SELECT * FROM table
790
793
  # # {1=>'Jim', 2=>'Bob', ...}
791
794
  #
792
- # DB[:table].to_hash(:id) # SELECT * FROM table
795
+ # DB[:table].as_hash(:id) # SELECT * FROM table
793
796
  # # {1=>{:id=>1, :name=>'Jim'}, 2=>{:id=>2, :name=>'Bob'}, ...}
794
797
  #
795
798
  # You can also provide an array of column names for either the key_column,
796
799
  # the value column, or both:
797
800
  #
798
- # DB[:table].to_hash([:id, :foo], [:name, :bar]) # SELECT * FROM table
801
+ # DB[:table].as_hash([:id, :foo], [:name, :bar]) # SELECT * FROM table
799
802
  # # {[1, 3]=>['Jim', 'bo'], [2, 4]=>['Bob', 'be'], ...}
800
803
  #
801
- # DB[:table].to_hash([:id, :name]) # SELECT * FROM table
804
+ # DB[:table].as_hash([:id, :name]) # SELECT * FROM table
802
805
  # # {[1, 'Jim']=>{:id=>1, :name=>'Jim'}, [2, 'Bob']=>{:id=>2, :name=>'Bob'}, ...}
803
806
  #
804
807
  # Options:
@@ -806,11 +809,11 @@ module Sequel
806
809
  # :hash :: The object into which the values will be placed. If this is not
807
810
  # given, an empty hash is used. This can be used to use a hash with
808
811
  # a default value or default proc.
809
- def to_hash(key_column, value_column = nil, opts = OPTS)
812
+ def as_hash(key_column, value_column = nil, opts = OPTS)
810
813
  h = opts[:hash] || {}
811
814
  meth = opts[:all] ? :all : :each
812
815
  if value_column
813
- return naked.to_hash(key_column, value_column, opts) if row_proc
816
+ return naked.as_hash(key_column, value_column, opts) if row_proc
814
817
  if value_column.is_a?(Array)
815
818
  if key_column.is_a?(Array)
816
819
  send(meth){|r| h[r.values_at(*key_column)] = r.values_at(*value_column)}
@@ -832,6 +835,11 @@ module Sequel
832
835
  h
833
836
  end
834
837
 
838
+ # Alias of as_hash for backwards compatibility.
839
+ def to_hash(*a)
840
+ as_hash(*a)
841
+ end
842
+
835
843
  # Returns a hash with one column used as key and the values being an
836
844
  # array of column values. If the value_column is not given or nil, uses
837
845
  # the entire hash as the value.
@@ -275,7 +275,7 @@ module Sequel
275
275
  # a select method, and the second is a new hash of preprocessed graph aliases.
276
276
  def graph_alias_columns(graph_aliases)
277
277
  gas = {}
278
- identifiers = graph_aliases.collect do |col_alias, tc|
278
+ identifiers = graph_aliases.map do |col_alias, tc|
279
279
  table, column, value = Array(tc)
280
280
  column ||= col_alias
281
281
  gas[col_alias] = [table, column].freeze
@@ -35,6 +35,7 @@ module Sequel
35
35
  @db = db
36
36
  @opts = {} # OPTS # SEQUEL5
37
37
  @cache = {}
38
+ # freeze # SEQUEL5
38
39
  end
39
40
 
40
41
  # Define a hash value such that datasets with the same class, DB, and opts
@@ -41,7 +41,7 @@ module Sequel
41
41
  meths.each do |meth|
42
42
  mod.send(:define_method, :"#{meth}=") do |v|
43
43
  # :nocov:
44
- Sequel::Deprecation.deprecate("Dataset##{meth}=", "The API has changed, and this value should now be passed in as an option via Dataset#clone.")
44
+ Sequel::Deprecation.deprecate("Dataset##{meth}=", "The API has changed, and this value should now be passed in as an option via Dataset#clone")
45
45
  @opts[meth] = v
46
46
  # :nocov:
47
47
  end
@@ -214,7 +214,7 @@ module Sequel
214
214
  fetch_rows(prepared_sql){|r| return r.values.first}
215
215
  when Array
216
216
  case prepared_type[0]
217
- when :map, :to_hash, :to_hash_groups
217
+ when :map, :as_hash, :to_hash, :to_hash_groups
218
218
  send(*prepared_type, &block)
219
219
  end
220
220
  else
@@ -341,7 +341,7 @@ module Sequel
341
341
  else
342
342
  # :nocov:
343
343
  # SEQUEL5: Add coverage
344
- Sequel::Deprecation.deprecate("Dataset#prepare will change to requiring a name argument in Sequel 5, please update your code.") unless name
344
+ Sequel::Deprecation.deprecate("Dataset#prepare will change to requiring a name argument in Sequel 5, please update your code") unless name
345
345
  # :nocov:
346
346
  end
347
347
 
@@ -20,7 +20,7 @@ module Sequel
20
20
 
21
21
  # Which options don't affect the SQL generation. Used by simple_select_all?
22
22
  # to determine if this is a simple SELECT * FROM table.
23
- NON_SQL_OPTIONS = [:server, :graph, :eager, :eager_graph, :graph_aliases, :row_proc, :quote_identifiers, :identifier_input_method, :identifier_output_method, :skip_symbol_cache, :model, :model_object, :association_reflection, :fetch, :numrows, :autoid].freeze # SEQUEL5: Remove graph_aliases
23
+ NON_SQL_OPTIONS = [:server, :graph, :graph_aliases, :row_proc, :quote_identifiers, :identifier_input_method, :identifier_output_method, :skip_symbol_cache].freeze # SEQUEL5: Remove graph_aliases
24
24
 
25
25
  # These symbols have _join methods created (e.g. inner_join) that
26
26
  # call join_table with the symbol, passing along the arguments and
@@ -44,6 +44,7 @@ module Sequel
44
44
  set_graph_aliases unfiltered ungraphed ungrouped union
45
45
  unlimited unordered where with with_recursive with_sql
46
46
  METHS
47
+ # SEQUEL5: Remove and, exclude_where
47
48
 
48
49
  # Register an extension callback for Dataset objects. ext should be the
49
50
  # extension name symbol, and mod should either be a Module that the
@@ -68,6 +69,7 @@ module Sequel
68
69
 
69
70
  # Alias for where.
70
71
  def and(*cond, &block)
72
+ Sequel::Deprecation.deprecate("Sequel::Dataset#and", "Use #where, or use the sequel_4_dataset_methods extension")
71
73
  where(*cond, &block)
72
74
  end
73
75
 
@@ -190,6 +192,7 @@ module Sequel
190
192
 
191
193
  # Alias for exclude.
192
194
  def exclude_where(*cond, &block)
195
+ Sequel::Deprecation.deprecate("Sequel::Dataset#exclude_where", "Use #exclude, or use the sequel_4_dataset_methods extension")
193
196
  exclude(*cond, &block)
194
197
  end
195
198
 
@@ -281,8 +284,7 @@ module Sequel
281
284
  # # SELECT * FROM (SELECT id, name FROM items ORDER BY name) AS foo(c1, c2)
282
285
  def from_self(opts=OPTS)
283
286
  fs = {}
284
- non_sql = non_sql_options
285
- @opts.keys.each{|k| fs[k] = nil unless non_sql.include?(k)}
287
+ @opts.keys.each{|k| fs[k] = nil unless non_sql_option?(k)}
286
288
  c = clone(fs).from(opts[:alias] ? as(opts[:alias], opts[:column_aliases]) : self)
287
289
  if cols = _columns
288
290
  c.send(:columns=, cols)
@@ -576,7 +578,7 @@ module Sequel
576
578
  last_alias = options[:implicit_qualifier] || @opts[:last_joined_table] || first_source_alias
577
579
  qualify_type = options[:qualify]
578
580
  if Sequel.condition_specifier?(expr)
579
- expr = expr.collect do |k, v|
581
+ expr = expr.map do |k, v|
580
582
  qualify_type = default_join_table_qualification if qualify_type.nil?
581
583
  case qualify_type
582
584
  when false
@@ -1137,7 +1139,9 @@ module Sequel
1137
1139
  # * single_record (if only one record could be returned)
1138
1140
  # * single_value (if only one record could be returned, and a single column is selected)
1139
1141
  # * map
1142
+ # * as_hash
1140
1143
  # * to_hash
1144
+ # * to_hash_groups
1141
1145
  # * delete (if a DELETE statement)
1142
1146
  # * update (if an UPDATE statement, with no arguments)
1143
1147
  # * insert (if an INSERT statement, with no arguments)
@@ -1169,7 +1173,7 @@ module Sequel
1169
1173
 
1170
1174
  # Return true if the dataset has a non-nil value for any key in opts.
1171
1175
  def options_overlap(opts)
1172
- !(@opts.collect{|k,v| k unless v.nil?}.compact & opts).empty?
1176
+ !(@opts.map{|k,v| k unless v.nil?}.compact & opts).empty?
1173
1177
  end
1174
1178
 
1175
1179
  # From types allowed to be considered a simple_select_all
@@ -1181,8 +1185,7 @@ module Sequel
1181
1185
  # SELECT table.* FROM table
1182
1186
  def simple_select_all?
1183
1187
  return false unless (f = @opts[:from]) && f.length == 1
1184
- non_sql = non_sql_options
1185
- o = @opts.reject{|k,v| v.nil? || non_sql.include?(k)}
1188
+ o = @opts.reject{|k,v| v.nil? || non_sql_option?(k)}
1186
1189
  from = f.first
1187
1190
  from = from.expression if from.is_a?(SQL::AliasedExpression)
1188
1191
 
@@ -1358,9 +1361,17 @@ module Sequel
1358
1361
  server?(:default)
1359
1362
  end
1360
1363
 
1361
- # Dataset options that do not affect the generated SQL.
1364
+ # SEQUEL5: Remove
1362
1365
  def non_sql_options
1366
+ # :nocov:
1367
+ Sequel::Deprecation.deprecate("Dataset#non_sql_options (private method)", "Convert the related code to use the non_sql_option? method")
1363
1368
  NON_SQL_OPTIONS
1369
+ # :nocov:
1370
+ end
1371
+
1372
+ # Whether the given option key does not affect the generated SQL.
1373
+ def non_sql_option?(key)
1374
+ NON_SQL_OPTIONS.include?(key)
1364
1375
  end
1365
1376
 
1366
1377
  # Treat the +block+ as a virtual_row block if not +nil+ and
@@ -48,7 +48,10 @@ class Array
48
48
  def sql_value_list
49
49
  ::Sequel::SQL::ValueList.new(self)
50
50
  end
51
- alias sql_array sql_value_list
51
+ def sql_array
52
+ Sequel::Deprecation.deprecate("Array#sql_array in the core_extensions extension", "Use Array#sql_value_list instead")
53
+ sql_value_list
54
+ end
52
55
 
53
56
  # Return a <tt>Sequel::SQL::BooleanExpression</tt> created from this array, matching all of the
54
57
  # conditions. Rarely do you need to call this explicitly, as Sequel generally
@@ -35,7 +35,7 @@
35
35
 
36
36
  module Sequel
37
37
  module DuplicateColumnsHandler
38
- CALLER_ARGS = RUBY_VERSION >= '2.0' ? [0,1] : [0]
38
+ CALLER_ARGS = (RUBY_VERSION >= '2.0' ? [0,1] : [0]).freeze
39
39
 
40
40
  # Customize handling of duplicate columns for this dataset.
41
41
  def on_duplicate_columns(handler = (raise Error, "Must provide either an argument or a block to on_duplicate_columns" unless block_given?; nil), &block)
@@ -2,4 +2,7 @@
2
2
  #
3
3
  # This only exists for backwards compatibility, as the behavior
4
4
  # added by this extension is now the default Sequel behavior.
5
+
6
+ Sequel::Deprecation.deprecate("The empty_array_ignore_nulls", "It has been a no-op since 4.25.0")
7
+
5
8
  Sequel::Dataset.register_extension(:empty_array_ignore_nulls){}
@@ -18,6 +18,8 @@
18
18
  #
19
19
  # Related module: Sequel::FilterHaving
20
20
 
21
+ Sequel::Deprecation.deprecate("The filter_having extension", "Please consider maintaining it yourself as an external gem if you want to continue using it")
22
+
21
23
  #
22
24
  module Sequel
23
25
  module FilterHaving
@@ -67,3 +67,5 @@ module Sequel
67
67
  register_extension(:freeze_datasets, FreezeDatasets)
68
68
  end
69
69
  end
70
+
71
+ # Sequel::Database.register_extension(:freeze_datasets){} # SEQUEL5
@@ -29,9 +29,9 @@ module Sequel
29
29
  super
30
30
  end
31
31
  end
32
- # SEQUEL5: Make this an empty module, since it will be the default behavior
33
32
  end
34
33
 
35
34
  Database.register_extension(:from_block, Database::FromBlock)
36
35
  end
37
36
 
37
+ # Sequel::Database.register_extension(:from_block){} # SEQUEL5
@@ -50,10 +50,10 @@ module Sequel
50
50
  # the result set
51
51
  datasets = @opts[:graph][:table_aliases].to_a.reject{|ta,ds| ds.nil?}
52
52
  # Get just the list of table aliases into a local variable, for speed
53
- table_aliases = datasets.collect{|ta,ds| ta}
53
+ table_aliases = datasets.map{|ta,ds| ta}
54
54
  # Get an array of arrays, one for each dataset, with
55
55
  # the necessary information about each dataset, for speed
56
- datasets = datasets.collect{|ta, ds| [ta, ds, ds.row_proc]}
56
+ datasets = datasets.map{|ta, ds| [ta, ds, ds.row_proc]}
57
57
  # Use the manually set graph aliases, if any, otherwise
58
58
  # use the ones automatically created by .graph
59
59
  column_aliases = @opts[:graph_aliases] || @opts[:graph][:column_aliases] # SEQUEL5: Remove :graph_aliases support
@@ -18,6 +18,8 @@
18
18
  #
19
19
  # Related module: Sequel::HashAliases
20
20
 
21
+ Sequel::Deprecation.deprecate("The hash_aliases extension", "Please consider maintaining it yourself as an external gem if you want to continue using it")
22
+
21
23
  #
22
24
  module Sequel
23
25
  module HashAliases
@@ -34,13 +34,6 @@
34
34
  #
35
35
  # DB.extension :identifier_mangling
36
36
  #
37
- # Historically, Sequel supported these methods by default on
38
- # Databases and Datasets. Sequel 4 will continue to support
39
- # the methods for backwards compatibility, by loading this
40
- # extension automatically for databases unless the
41
- # <tt>:identifier_mangling=>false</tt> Database option is
42
- # used.
43
- #
44
37
  # Related modules: Sequel::IdentifierMangling::DatabaseMethods,
45
38
  # Sequel::IdentifierMangling::DatasetMethods
46
39
 
@@ -9,6 +9,8 @@
9
9
  #
10
10
  # Related module: Sequel::Metaprogramming
11
11
 
12
+ Sequel::Deprecation.deprecate("The meta_def extension", "Replace meta_def usage with define_singleton_method")
13
+
12
14
  #
13
15
  module Sequel
14
16
  # Contains meta_def method for adding methods to objects via blocks.