sequel 4.47.0 → 4.48.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +134 -0
- data/Rakefile +1 -1
- data/doc/release_notes/4.48.0.txt +293 -0
- data/lib/sequel/adapters/ado/access.rb +2 -1
- data/lib/sequel/adapters/do/postgres.rb +5 -2
- data/lib/sequel/adapters/ibmdb.rb +24 -7
- data/lib/sequel/adapters/jdbc.rb +36 -22
- data/lib/sequel/adapters/jdbc/db2.rb +12 -3
- data/lib/sequel/adapters/jdbc/derby.rb +4 -5
- data/lib/sequel/adapters/jdbc/oracle.rb +16 -2
- data/lib/sequel/adapters/jdbc/postgresql.rb +43 -18
- data/lib/sequel/adapters/jdbc/sqlanywhere.rb +9 -7
- data/lib/sequel/adapters/jdbc/sqlserver.rb +11 -4
- data/lib/sequel/adapters/mock.rb +24 -19
- data/lib/sequel/adapters/mysql.rb +17 -16
- data/lib/sequel/adapters/mysql2.rb +4 -5
- data/lib/sequel/adapters/oracle.rb +5 -9
- data/lib/sequel/adapters/postgres.rb +89 -102
- data/lib/sequel/adapters/shared/db2.rb +22 -6
- data/lib/sequel/adapters/shared/mssql.rb +5 -4
- data/lib/sequel/adapters/shared/mysql.rb +75 -24
- data/lib/sequel/adapters/shared/postgres.rb +196 -94
- data/lib/sequel/adapters/shared/sqlanywhere.rb +23 -10
- data/lib/sequel/adapters/shared/sqlite.rb +72 -82
- data/lib/sequel/adapters/sqlanywhere.rb +4 -1
- data/lib/sequel/adapters/sqlite.rb +5 -3
- data/lib/sequel/adapters/swift/postgres.rb +5 -2
- data/lib/sequel/adapters/tinytds.rb +0 -5
- data/lib/sequel/adapters/utils/mysql_mysql2.rb +1 -1
- data/lib/sequel/adapters/utils/pg_types.rb +2 -76
- data/lib/sequel/core.rb +2 -2
- data/lib/sequel/database/connecting.rb +5 -5
- data/lib/sequel/database/dataset.rb +6 -3
- data/lib/sequel/database/misc.rb +1 -1
- data/lib/sequel/database/query.rb +3 -0
- data/lib/sequel/database/schema_methods.rb +1 -1
- data/lib/sequel/dataset/actions.rb +18 -10
- data/lib/sequel/dataset/graph.rb +1 -1
- data/lib/sequel/dataset/misc.rb +1 -0
- data/lib/sequel/dataset/prepared_statements.rb +3 -3
- data/lib/sequel/dataset/query.rb +19 -8
- data/lib/sequel/extensions/core_extensions.rb +4 -1
- data/lib/sequel/extensions/duplicate_columns_handler.rb +1 -1
- data/lib/sequel/extensions/empty_array_ignore_nulls.rb +3 -0
- data/lib/sequel/extensions/filter_having.rb +2 -0
- data/lib/sequel/extensions/freeze_datasets.rb +2 -0
- data/lib/sequel/extensions/from_block.rb +1 -1
- data/lib/sequel/extensions/graph_each.rb +2 -2
- data/lib/sequel/extensions/hash_aliases.rb +2 -0
- data/lib/sequel/extensions/identifier_mangling.rb +0 -7
- data/lib/sequel/extensions/meta_def.rb +2 -0
- data/lib/sequel/extensions/migration.rb +6 -6
- data/lib/sequel/extensions/no_auto_literal_strings.rb +1 -1
- data/lib/sequel/extensions/pagination.rb +1 -1
- data/lib/sequel/extensions/pg_array.rb +207 -130
- data/lib/sequel/extensions/pg_hstore.rb +38 -20
- data/lib/sequel/extensions/pg_inet.rb +18 -6
- data/lib/sequel/extensions/pg_interval.rb +19 -12
- data/lib/sequel/extensions/pg_json.rb +25 -14
- data/lib/sequel/extensions/pg_json_ops.rb +2 -2
- data/lib/sequel/extensions/pg_range.rb +133 -100
- data/lib/sequel/extensions/pg_range_ops.rb +4 -3
- data/lib/sequel/extensions/pg_row.rb +68 -39
- data/lib/sequel/extensions/pg_row_ops.rb +11 -5
- data/lib/sequel/extensions/query_literals.rb +2 -0
- data/lib/sequel/extensions/ruby18_symbol_extensions.rb +2 -0
- data/lib/sequel/extensions/s.rb +1 -1
- data/lib/sequel/extensions/schema_dumper.rb +24 -24
- data/lib/sequel/extensions/sequel_3_dataset_methods.rb +3 -1
- data/lib/sequel/extensions/sequel_4_dataset_methods.rb +83 -0
- data/lib/sequel/extensions/set_overrides.rb +2 -2
- data/lib/sequel/extensions/string_agg.rb +0 -1
- data/lib/sequel/extensions/symbol_aref.rb +0 -4
- data/lib/sequel/model.rb +25 -57
- data/lib/sequel/model/associations.rb +14 -5
- data/lib/sequel/model/base.rb +96 -32
- data/lib/sequel/plugins/association_pks.rb +73 -46
- data/lib/sequel/plugins/association_proxies.rb +1 -1
- data/lib/sequel/plugins/auto_validations.rb +6 -2
- data/lib/sequel/plugins/boolean_readers.rb +1 -1
- data/lib/sequel/plugins/caching.rb +19 -13
- data/lib/sequel/plugins/class_table_inheritance.rb +19 -10
- data/lib/sequel/plugins/column_conflicts.rb +7 -2
- data/lib/sequel/plugins/column_select.rb +1 -1
- data/lib/sequel/plugins/csv_serializer.rb +8 -8
- data/lib/sequel/plugins/defaults_setter.rb +10 -0
- data/lib/sequel/plugins/eager_each.rb +1 -1
- data/lib/sequel/plugins/force_encoding.rb +2 -2
- data/lib/sequel/plugins/hook_class_methods.rb +9 -12
- data/lib/sequel/plugins/identifier_columns.rb +2 -0
- data/lib/sequel/plugins/instance_filters.rb +3 -1
- data/lib/sequel/plugins/instance_hooks.rb +17 -9
- data/lib/sequel/plugins/json_serializer.rb +17 -10
- data/lib/sequel/plugins/lazy_attributes.rb +8 -7
- data/lib/sequel/plugins/modification_detection.rb +3 -0
- data/lib/sequel/plugins/nested_attributes.rb +5 -1
- data/lib/sequel/plugins/pg_array_associations.rb +5 -0
- data/lib/sequel/plugins/prepared_statements.rb +1 -0
- data/lib/sequel/plugins/rcte_tree.rb +4 -4
- data/lib/sequel/plugins/serialization.rb +3 -10
- data/lib/sequel/plugins/single_table_inheritance.rb +2 -2
- data/lib/sequel/plugins/split_values.rb +6 -5
- data/lib/sequel/plugins/static_cache.rb +31 -25
- data/lib/sequel/plugins/subset_conditions.rb +3 -1
- data/lib/sequel/plugins/table_select.rb +1 -1
- data/lib/sequel/plugins/touch.rb +2 -1
- data/lib/sequel/plugins/validation_class_methods.rb +5 -6
- data/lib/sequel/plugins/validation_helpers.rb +2 -4
- data/lib/sequel/plugins/xml_serializer.rb +4 -4
- data/lib/sequel/sql.rb +2 -2
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/db2_spec.rb +115 -14
- data/spec/adapters/mysql_spec.rb +78 -28
- data/spec/adapters/oracle_spec.rb +24 -24
- data/spec/adapters/postgres_spec.rb +38 -24
- data/spec/adapters/sqlanywhere_spec.rb +88 -86
- data/spec/adapters/sqlite_spec.rb +29 -24
- data/spec/core/connection_pool_spec.rb +17 -0
- data/spec/core/database_spec.rb +6 -0
- data/spec/core/dataset_spec.rb +46 -36
- data/spec/core/schema_spec.rb +16 -0
- data/spec/core/spec_helper.rb +1 -0
- data/spec/core_extensions_spec.rb +6 -2
- data/spec/extensions/active_model_spec.rb +1 -1
- data/spec/extensions/arbitrary_servers_spec.rb +1 -1
- data/spec/extensions/association_pks_spec.rb +34 -2
- data/spec/extensions/auto_literal_strings_spec.rb +5 -1
- data/spec/extensions/auto_validations_spec.rb +2 -0
- data/spec/extensions/boolean_readers_spec.rb +1 -1
- data/spec/extensions/boolean_subsets_spec.rb +1 -1
- data/spec/extensions/class_table_inheritance_spec.rb +48 -2
- data/spec/extensions/column_conflicts_spec.rb +11 -0
- data/spec/extensions/connection_validator_spec.rb +1 -1
- data/spec/extensions/dataset_associations_spec.rb +8 -8
- data/spec/extensions/defaults_setter_spec.rb +1 -1
- data/spec/extensions/filter_having_spec.rb +5 -3
- data/spec/extensions/hash_aliases_spec.rb +3 -1
- data/spec/extensions/identifier_columns_spec.rb +3 -1
- data/spec/extensions/implicit_subquery_spec.rb +4 -2
- data/spec/extensions/json_serializer_spec.rb +18 -0
- data/spec/extensions/lazy_attributes_spec.rb +3 -3
- data/spec/extensions/meta_def_spec.rb +9 -0
- data/spec/extensions/migration_spec.rb +3 -3
- data/spec/extensions/nested_attributes_spec.rb +14 -3
- data/spec/extensions/no_auto_literal_strings_spec.rb +8 -4
- data/spec/extensions/pg_array_associations_spec.rb +29 -18
- data/spec/extensions/pg_array_spec.rb +44 -25
- data/spec/extensions/pg_hstore_spec.rb +10 -0
- data/spec/extensions/pg_inet_spec.rb +26 -0
- data/spec/extensions/pg_interval_spec.rb +20 -0
- data/spec/extensions/pg_json_spec.rb +24 -0
- data/spec/extensions/pg_range_spec.rb +98 -14
- data/spec/extensions/pg_row_spec.rb +14 -4
- data/spec/extensions/prepared_statements_safe_spec.rb +1 -1
- data/spec/extensions/query_literals_spec.rb +3 -1
- data/spec/extensions/schema_dumper_spec.rb +96 -98
- data/spec/extensions/sequel_3_dataset_methods_spec.rb +10 -6
- data/spec/extensions/sequel_4_dataset_methods_spec.rb +121 -0
- data/spec/extensions/single_table_inheritance_spec.rb +1 -1
- data/spec/extensions/spec_helper.rb +7 -1
- data/spec/extensions/static_cache_spec.rb +75 -24
- data/spec/extensions/string_agg_spec.rb +1 -1
- data/spec/extensions/touch_spec.rb +9 -0
- data/spec/extensions/validation_helpers_spec.rb +9 -3
- data/spec/extensions/whitelist_security_spec.rb +26 -0
- data/spec/integration/dataset_test.rb +45 -44
- data/spec/integration/plugin_test.rb +20 -0
- data/spec/integration/prepared_statement_test.rb +3 -0
- data/spec/integration/schema_test.rb +21 -1
- data/spec/integration/transaction_test.rb +40 -40
- data/spec/model/class_dataset_methods_spec.rb +14 -4
- data/spec/model/dataset_methods_spec.rb +12 -3
- data/spec/model/model_spec.rb +8 -0
- metadata +6 -4
- data/spec/adapters/firebird_spec.rb +0 -405
- data/spec/adapters/informix_spec.rb +0 -100
data/lib/sequel/core.rb
CHANGED
@@ -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'.
|
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)
|
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('&').
|
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
|
-
|
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
|
-
|
69
|
+
@default_dataset.from(*args)
|
67
70
|
end
|
68
71
|
end
|
69
72
|
|
data/lib/sequel/database/misc.rb
CHANGED
@@ -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
|
643
|
-
#
|
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(:
|
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].
|
792
|
+
# DB[:table].as_hash(:id, :name) # SELECT * FROM table
|
790
793
|
# # {1=>'Jim', 2=>'Bob', ...}
|
791
794
|
#
|
792
|
-
# DB[: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].
|
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].
|
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
|
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.
|
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.
|
data/lib/sequel/dataset/graph.rb
CHANGED
@@ -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.
|
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
|
data/lib/sequel/dataset/misc.rb
CHANGED
@@ -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
|
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
|
|
data/lib/sequel/dataset/query.rb
CHANGED
@@ -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, :
|
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
|
-
|
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.
|
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.
|
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
|
-
|
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
|
-
#
|
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
|
-
|
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){}
|
@@ -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.
|
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.
|
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
|
@@ -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
|
|