sequel 4.46.0 → 4.49.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +210 -0
- data/Rakefile +1 -1
- data/doc/advanced_associations.rdoc +1 -1
- data/doc/opening_databases.rdoc +3 -2
- data/doc/release_notes/4.47.0.txt +56 -0
- data/doc/release_notes/4.48.0.txt +293 -0
- data/doc/release_notes/4.49.0.txt +222 -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 +30 -8
- data/lib/sequel/adapters/jdbc/as400.rb +1 -1
- data/lib/sequel/adapters/jdbc/db2.rb +12 -3
- data/lib/sequel/adapters/jdbc/derby.rb +4 -5
- data/lib/sequel/adapters/jdbc/h2.rb +10 -1
- data/lib/sequel/adapters/jdbc/oracle.rb +16 -2
- data/lib/sequel/adapters/jdbc/postgresql.rb +46 -20
- data/lib/sequel/adapters/jdbc/sqlanywhere.rb +9 -7
- data/lib/sequel/adapters/jdbc/sqlserver.rb +20 -6
- data/lib/sequel/adapters/jdbc.rb +39 -23
- data/lib/sequel/adapters/mock.rb +27 -19
- data/lib/sequel/adapters/mysql.rb +17 -16
- data/lib/sequel/adapters/mysql2.rb +5 -6
- data/lib/sequel/adapters/oracle.rb +5 -9
- data/lib/sequel/adapters/postgres.rb +91 -103
- 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 +79 -25
- data/lib/sequel/adapters/shared/oracle.rb +26 -3
- data/lib/sequel/adapters/shared/postgres.rb +199 -95
- 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/ast_transformer.rb +1 -1
- data/lib/sequel/connection_pool/sharded_single.rb +1 -1
- data/lib/sequel/connection_pool/sharded_threaded.rb +1 -1
- data/lib/sequel/connection_pool/single.rb +2 -2
- data/lib/sequel/connection_pool/threaded.rb +2 -2
- data/lib/sequel/connection_pool.rb +9 -2
- data/lib/sequel/core.rb +2 -2
- data/lib/sequel/database/connecting.rb +8 -8
- data/lib/sequel/database/dataset.rb +6 -3
- data/lib/sequel/database/dataset_defaults.rb +14 -1
- 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 +72 -10
- data/lib/sequel/dataset/dataset_module.rb +58 -0
- 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 +22 -11
- data/lib/sequel/dataset.rb +1 -1
- data/lib/sequel/exceptions.rb +8 -0
- data/lib/sequel/extensions/_model_pg_row.rb +5 -2
- data/lib/sequel/extensions/core_extensions.rb +4 -1
- data/lib/sequel/extensions/current_datetime_timestamp.rb +2 -1
- data/lib/sequel/extensions/date_arithmetic.rb +1 -0
- data/lib/sequel/extensions/duplicate_columns_handler.rb +3 -3
- 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 +11 -8
- data/lib/sequel/extensions/no_auto_literal_strings.rb +1 -1
- data/lib/sequel/extensions/null_dataset.rb +1 -0
- 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 +29 -25
- 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/server_block.rb +32 -15
- 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/associations.rb +35 -7
- data/lib/sequel/model/base.rb +113 -87
- data/lib/sequel/model/dataset_module.rb +5 -43
- data/lib/sequel/model/errors.rb +2 -1
- data/lib/sequel/model/inflections.rb +17 -5
- data/lib/sequel/model.rb +26 -58
- data/lib/sequel/plugins/active_model.rb +2 -2
- data/lib/sequel/plugins/association_autoreloading.rb +2 -0
- data/lib/sequel/plugins/association_dependencies.rb +3 -3
- 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 +2 -2
- data/lib/sequel/plugins/boolean_subsets.rb +1 -1
- data/lib/sequel/plugins/caching.rb +19 -13
- data/lib/sequel/plugins/class_table_inheritance.rb +24 -13
- data/lib/sequel/plugins/column_conflicts.rb +7 -2
- data/lib/sequel/plugins/column_select.rb +3 -3
- data/lib/sequel/plugins/composition.rb +2 -2
- data/lib/sequel/plugins/csv_serializer.rb +8 -8
- data/lib/sequel/plugins/dataset_associations.rb +25 -13
- data/lib/sequel/plugins/defaults_setter.rb +13 -1
- 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 +19 -12
- data/lib/sequel/plugins/lazy_attributes.rb +8 -7
- data/lib/sequel/plugins/many_to_one_pk_lookup.rb +2 -0
- data/lib/sequel/plugins/modification_detection.rb +3 -0
- data/lib/sequel/plugins/nested_attributes.rb +6 -2
- data/lib/sequel/plugins/pg_array_associations.rb +5 -0
- data/lib/sequel/plugins/pg_row.rb +4 -2
- data/lib/sequel/plugins/pg_typecast_on_load.rb +2 -0
- data/lib/sequel/plugins/prepared_statements.rb +1 -0
- data/lib/sequel/plugins/rcte_tree.rb +4 -24
- data/lib/sequel/plugins/serialization.rb +9 -15
- data/lib/sequel/plugins/single_table_inheritance.rb +8 -3
- 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 +4 -2
- data/lib/sequel/plugins/validation_class_methods.rb +5 -6
- data/lib/sequel/plugins/validation_helpers.rb +14 -8
- data/lib/sequel/plugins/xml_serializer.rb +4 -4
- data/lib/sequel/sql.rb +18 -9
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/db2_spec.rb +115 -14
- data/spec/adapters/mssql_spec.rb +4 -4
- data/spec/adapters/mysql_spec.rb +83 -29
- data/spec/adapters/oracle_spec.rb +28 -24
- data/spec/adapters/postgres_spec.rb +40 -24
- data/spec/adapters/sqlanywhere_spec.rb +88 -86
- data/spec/adapters/sqlite_spec.rb +29 -24
- data/spec/bin_spec.rb +7 -1
- data/spec/core/connection_pool_spec.rb +45 -14
- data/spec/core/database_spec.rb +155 -0
- data/spec/core/dataset_spec.rb +219 -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 +106 -19
- data/spec/extensions/column_conflicts_spec.rb +11 -0
- data/spec/extensions/column_select_spec.rb +1 -0
- data/spec/extensions/composition_spec.rb +13 -0
- data/spec/extensions/connection_validator_spec.rb +1 -1
- data/spec/extensions/dataset_associations_spec.rb +20 -8
- data/spec/extensions/defaults_setter_spec.rb +15 -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/many_through_many_spec.rb +4 -4
- 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/null_dataset_spec.rb +1 -1
- 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/pg_typecast_on_load_spec.rb +11 -9
- 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 +108 -94
- 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/serialization_spec.rb +1 -1
- data/spec/extensions/server_block_spec.rb +7 -0
- data/spec/extensions/single_table_inheritance_spec.rb +17 -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 +10 -5
- data/spec/extensions/whitelist_security_spec.rb +26 -0
- data/spec/integration/associations_test.rb +8 -0
- data/spec/integration/dataset_test.rb +45 -44
- data/spec/integration/model_test.rb +53 -4
- data/spec/integration/plugin_test.rb +28 -4
- 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/association_reflection_spec.rb +43 -1
- data/spec/model/associations_spec.rb +29 -9
- data/spec/model/class_dataset_methods_spec.rb +20 -4
- data/spec/model/dataset_methods_spec.rb +12 -3
- data/spec/model/eager_loading_spec.rb +8 -8
- data/spec/model/model_spec.rb +45 -1
- data/spec/model/plugins_spec.rb +34 -0
- data/spec/model/record_spec.rb +1 -1
- data/spec/spec_config.rb +2 -0
- metadata +11 -4
- data/spec/adapters/firebird_spec.rb +0 -405
- data/spec/adapters/informix_spec.rb +0 -100
@@ -20,12 +20,14 @@ module Sequel
|
|
20
20
|
|
21
21
|
PRIMARY_KEY_INDEX_RE = /\Asqlite_autoindex_/.freeze
|
22
22
|
Sequel::Deprecation.deprecate_constant(self, :PRIMARY_KEY_INDEX_RE)
|
23
|
+
TABLES_FILTER = Sequel.~(:name=>'sqlite_sequence'.freeze) & {:type => 'table'.freeze}
|
24
|
+
Sequel::Deprecation.deprecate_constant(self, :TABLES_FILTER)
|
25
|
+
VIEWS_FILTER = {:type => 'view'.freeze}.freeze
|
26
|
+
Sequel::Deprecation.deprecate_constant(self, :VIEWS_FILTER)
|
23
27
|
|
24
28
|
AUTO_VACUUM = [:none, :full, :incremental].freeze
|
25
29
|
SYNCHRONOUS = [:off, :normal, :full].freeze
|
26
|
-
TABLES_FILTER = Sequel.~(:name=>'sqlite_sequence'.freeze) & {:type => 'table'.freeze}
|
27
30
|
TEMP_STORE = [:default, :file, :memory].freeze
|
28
|
-
VIEWS_FILTER = {:type => 'view'.freeze}.freeze
|
29
31
|
TRANSACTION_MODE = {
|
30
32
|
:deferred => "BEGIN DEFERRED TRANSACTION".freeze,
|
31
33
|
:immediate => "BEGIN IMMEDIATE TRANSACTION".freeze,
|
@@ -37,26 +39,6 @@ module Sequel
|
|
37
39
|
# booleans be stored as integers, but historically Sequel has used 't'/'f'.
|
38
40
|
attr_accessor :integer_booleans
|
39
41
|
|
40
|
-
# A symbol signifying the value of the auto_vacuum PRAGMA.
|
41
|
-
def auto_vacuum
|
42
|
-
AUTO_VACUUM[pragma_get(:auto_vacuum).to_i]
|
43
|
-
end
|
44
|
-
|
45
|
-
# Set the auto_vacuum PRAGMA using the given symbol (:none, :full, or
|
46
|
-
# :incremental). See pragma_set. Consider using the :auto_vacuum
|
47
|
-
# Database option instead.
|
48
|
-
def auto_vacuum=(value)
|
49
|
-
value = AUTO_VACUUM.index(value) || (raise Error, "Invalid value for auto_vacuum option. Please specify one of :none, :full, :incremental.")
|
50
|
-
pragma_set(:auto_vacuum, value)
|
51
|
-
end
|
52
|
-
|
53
|
-
# Set the case_sensitive_like PRAGMA using the given boolean value, if using
|
54
|
-
# SQLite 3.2.3+. If not using 3.2.3+, no error is raised. See pragma_set.
|
55
|
-
# Consider using the :case_sensitive_like Database option instead.
|
56
|
-
def case_sensitive_like=(value)
|
57
|
-
pragma_set(:case_sensitive_like, !!value ? 'on' : 'off') if sqlite_version >= 30203
|
58
|
-
end
|
59
|
-
|
60
42
|
# A symbol signifying the value of the default transaction mode
|
61
43
|
attr_reader :transaction_mode
|
62
44
|
|
@@ -74,18 +56,50 @@ module Sequel
|
|
74
56
|
:sqlite
|
75
57
|
end
|
76
58
|
|
77
|
-
#
|
78
|
-
|
59
|
+
# SEQUEL5: Remove
|
60
|
+
def auto_vacuum
|
61
|
+
AUTO_VACUUM[pragma_get(:auto_vacuum).to_i]
|
62
|
+
end
|
63
|
+
def auto_vacuum=(value)
|
64
|
+
value = AUTO_VACUUM.index(value) || (raise Error, "Invalid value for auto_vacuum option. Please specify one of :none, :full, :incremental.")
|
65
|
+
pragma_set(:auto_vacuum, value)
|
66
|
+
end
|
67
|
+
def case_sensitive_like=(value)
|
68
|
+
pragma_set(:case_sensitive_like, !!value ? 'on' : 'off') if sqlite_version >= 30203
|
69
|
+
end
|
79
70
|
def foreign_keys
|
80
71
|
pragma_get(:foreign_keys).to_i == 1 if sqlite_version >= 30619
|
81
72
|
end
|
82
|
-
|
83
|
-
# Set the foreign_keys PRAGMA using the given boolean value, if using
|
84
|
-
# SQLite 3.6.19+. If not using 3.6.19+, no error is raised. See pragma_set.
|
85
|
-
# Consider using the :foreign_keys Database option instead.
|
86
73
|
def foreign_keys=(value)
|
87
74
|
pragma_set(:foreign_keys, !!value ? 'on' : 'off') if sqlite_version >= 30619
|
88
75
|
end
|
76
|
+
def pragma_get(name)
|
77
|
+
Sequel::Deprecation.deprecate('Database#{pragma_get,auto_vacuum,case_sensitive_like,foreign_keys,synchronous,temp_store} on SQLite', "These methods may not be safe when using multiple connections, call fetch(#{"PRAGMA #{name}".inspect}).single_value if you really want to get the pragma value")
|
78
|
+
self["PRAGMA #{name}"].single_value
|
79
|
+
end
|
80
|
+
def pragma_set(name, value)
|
81
|
+
Sequel::Deprecation.deprecate('Database#{pragma_set,auto_vacuum=,case_sensitive_like=,foreign_keys=,synchronous=,temp_store=} on SQLite', "These methods are not thread safe or safe when using multiple connections, pass the appropriate option when connecting to set the pragma correctly for all connections")
|
82
|
+
execute_ddl("PRAGMA #{name} = #{value}")
|
83
|
+
end
|
84
|
+
def synchronous
|
85
|
+
SYNCHRONOUS[pragma_get(:synchronous).to_i]
|
86
|
+
end
|
87
|
+
def synchronous=(value)
|
88
|
+
value = SYNCHRONOUS.index(value) || (raise Error, "Invalid value for synchronous option. Please specify one of :off, :normal, :full.")
|
89
|
+
pragma_set(:synchronous, value)
|
90
|
+
end
|
91
|
+
def temp_store
|
92
|
+
TEMP_STORE[pragma_get(:temp_store).to_i]
|
93
|
+
end
|
94
|
+
def temp_store=(value)
|
95
|
+
value = TEMP_STORE.index(value) || (raise Error, "Invalid value for temp_store option. Please specify one of :default, :file, :memory.")
|
96
|
+
pragma_set(:temp_store, value)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Set the integer_booleans option using the passed in :integer_boolean option.
|
100
|
+
def set_integer_booleans
|
101
|
+
@integer_booleans = @opts.has_key?(:integer_booleans) ? typecast_value_boolean(@opts[:integer_booleans]) : true
|
102
|
+
end
|
89
103
|
|
90
104
|
# Return the array of foreign key info hashes using the foreign_key_list PRAGMA,
|
91
105
|
# including information for the :on_update and :on_delete entries.
|
@@ -115,8 +129,18 @@ module Sequel
|
|
115
129
|
im = input_identifier_meth
|
116
130
|
indexes = {}
|
117
131
|
metadata_dataset.with_sql("PRAGMA index_list(?)", im.call(table)).each do |r|
|
118
|
-
|
119
|
-
|
132
|
+
if opts[:only_autocreated]
|
133
|
+
# If specifically asked for only autocreated indexes, then return those an only those
|
134
|
+
next unless r[:name] =~ /\Asqlite_autoindex_/
|
135
|
+
elsif r.has_key?(:origin)
|
136
|
+
# If origin is set, then only exclude primary key indexes and partial indexes
|
137
|
+
next if r[:origin] == 'pk'
|
138
|
+
next if r[:partial].to_i == 1
|
139
|
+
else
|
140
|
+
# When :origin key not present, assume any autoindex could be a primary key one and exclude it
|
141
|
+
next if r[:name] =~ /\Asqlite_autoindex_/
|
142
|
+
end
|
143
|
+
|
120
144
|
indexes[m.call(r[:name])] = {:unique=>r[:unique].to_i==1}
|
121
145
|
end
|
122
146
|
indexes.each do |k, v|
|
@@ -125,28 +149,6 @@ module Sequel
|
|
125
149
|
indexes
|
126
150
|
end
|
127
151
|
|
128
|
-
# Get the value of the given PRAGMA.
|
129
|
-
def pragma_get(name)
|
130
|
-
Sequel::Deprecation.deprecate('Database#{pragma_get,auto_vacuum,case_sensitive_like,foreign_keys,synchronous,temp_store} on SQLite', "These methods may not be safe when using multiple connections, call fetch(#{"PRAGMA #{name}".inspect}).single_value if you really want to get the pragma value")
|
131
|
-
self["PRAGMA #{name}"].single_value
|
132
|
-
end
|
133
|
-
|
134
|
-
# Set the value of the given PRAGMA to value.
|
135
|
-
#
|
136
|
-
# This method is not thread safe, and will not work correctly if there
|
137
|
-
# are multiple connections in the Database's connection pool. PRAGMA
|
138
|
-
# modifications should be done when the connection is created, using
|
139
|
-
# an option provided when creating the Database object.
|
140
|
-
def pragma_set(name, value)
|
141
|
-
Sequel::Deprecation.deprecate('Database#{pragma_set,auto_vacuum=,case_sensitive_like=,foreign_keys=,synchronous=,temp_store=} on SQLite', "These methods are not thread safe or safe when using multiple connections, pass the appropriate option when connecting to set the pragma correctly for all connections")
|
142
|
-
execute_ddl("PRAGMA #{name} = #{value}")
|
143
|
-
end
|
144
|
-
|
145
|
-
# Set the integer_booleans option using the passed in :integer_boolean option.
|
146
|
-
def set_integer_booleans
|
147
|
-
@integer_booleans = @opts.has_key?(:integer_booleans) ? typecast_value_boolean(@opts[:integer_booleans]) : true
|
148
|
-
end
|
149
|
-
|
150
152
|
# The version of the server as an integer, where 3.6.19 = 30619.
|
151
153
|
# If the server version can't be determined, 0 is used.
|
152
154
|
def sqlite_version
|
@@ -190,36 +192,12 @@ module Sequel
|
|
190
192
|
defined?(@use_timestamp_timezones) ? @use_timestamp_timezones : (@use_timestamp_timezones = false)
|
191
193
|
end
|
192
194
|
|
193
|
-
# A symbol signifying the value of the synchronous PRAGMA.
|
194
|
-
def synchronous
|
195
|
-
SYNCHRONOUS[pragma_get(:synchronous).to_i]
|
196
|
-
end
|
197
|
-
|
198
|
-
# Set the synchronous PRAGMA using the given symbol (:off, :normal, or :full). See pragma_set.
|
199
|
-
# Consider using the :synchronous Database option instead.
|
200
|
-
def synchronous=(value)
|
201
|
-
value = SYNCHRONOUS.index(value) || (raise Error, "Invalid value for synchronous option. Please specify one of :off, :normal, :full.")
|
202
|
-
pragma_set(:synchronous, value)
|
203
|
-
end
|
204
|
-
|
205
195
|
# Array of symbols specifying the table names in the current database.
|
206
196
|
#
|
207
197
|
# Options:
|
208
198
|
# :server :: Set the server to use.
|
209
199
|
def tables(opts=OPTS)
|
210
|
-
tables_and_views(
|
211
|
-
end
|
212
|
-
|
213
|
-
# A symbol signifying the value of the temp_store PRAGMA.
|
214
|
-
def temp_store
|
215
|
-
TEMP_STORE[pragma_get(:temp_store).to_i]
|
216
|
-
end
|
217
|
-
|
218
|
-
# Set the temp_store PRAGMA using the given symbol (:default, :file, or :memory). See pragma_set.
|
219
|
-
# Consider using the :temp_store Database option instead.
|
220
|
-
def temp_store=(value)
|
221
|
-
value = TEMP_STORE.index(value) || (raise Error, "Invalid value for temp_store option. Please specify one of :default, :file, :memory.")
|
222
|
-
pragma_set(:temp_store, value)
|
200
|
+
tables_and_views(Sequel.~(:name=>'sqlite_sequence') & {:type => 'table'}, opts)
|
223
201
|
end
|
224
202
|
|
225
203
|
# Creates a dataset that uses the VALUES clause:
|
@@ -235,7 +213,7 @@ module Sequel
|
|
235
213
|
# Options:
|
236
214
|
# :server :: Set the server to use.
|
237
215
|
def views(opts=OPTS)
|
238
|
-
tables_and_views(
|
216
|
+
tables_and_views({:type => 'view'}, opts)
|
239
217
|
end
|
240
218
|
|
241
219
|
private
|
@@ -438,8 +416,12 @@ module Sequel
|
|
438
416
|
|
439
417
|
# Determine unique constraints and make sure the new columns have them
|
440
418
|
unique_columns = []
|
441
|
-
|
442
|
-
|
419
|
+
skip_indexes = []
|
420
|
+
indexes(table, :only_autocreated=>true).each do |name, h|
|
421
|
+
skip_indexes << name
|
422
|
+
if h[:columns].length == 1 && h[:unique]
|
423
|
+
unique_columns.concat(h[:columns])
|
424
|
+
end
|
443
425
|
end
|
444
426
|
unique_columns -= pks
|
445
427
|
unless unique_columns.empty?
|
@@ -462,6 +444,7 @@ module Sequel
|
|
462
444
|
"DROP TABLE #{bt}"
|
463
445
|
]
|
464
446
|
indexes(table).each do |name, h|
|
447
|
+
next if skip_indexes.include?(name)
|
465
448
|
if (h[:columns].map(&:to_s) - new_columns).empty?
|
466
449
|
a << alter_table_sql(table, h.merge(:op=>:add_index, :name=>name))
|
467
450
|
end
|
@@ -471,7 +454,7 @@ module Sequel
|
|
471
454
|
|
472
455
|
# Does the reverse of on_delete_clause, eg. converts strings like +'SET NULL'+
|
473
456
|
# to symbols +:set_null+.
|
474
|
-
def on_delete_sql_to_sym
|
457
|
+
def on_delete_sql_to_sym(str)
|
475
458
|
case str
|
476
459
|
when 'RESTRICT'
|
477
460
|
:restrict
|
@@ -549,6 +532,9 @@ module Sequel
|
|
549
532
|
include Dataset::Replace
|
550
533
|
include UnmodifiedIdentifiers::DatasetMethods
|
551
534
|
|
535
|
+
# The allowed values for insert_conflict
|
536
|
+
INSERT_CONFLICT_RESOLUTIONS = %w'ROLLBACK ABORT FAIL IGNORE REPLACE'.each(&:freeze).freeze
|
537
|
+
|
552
538
|
CONSTANT_MAP = {:CURRENT_DATE=>"date(CURRENT_TIMESTAMP, 'localtime')".freeze, :CURRENT_TIMESTAMP=>"datetime(CURRENT_TIMESTAMP, 'localtime')".freeze, :CURRENT_TIME=>"time(CURRENT_TIMESTAMP, 'localtime')".freeze}#.freeze # SEQUEL5
|
553
539
|
EXTRACT_MAP = {:year=>"'%Y'", :month=>"'%m'", :day=>"'%d'", :hour=>"'%H'", :minute=>"'%M'", :second=>"'%f'"}#.freeze # SEQUEL5
|
554
540
|
#EXTRACT_MAP.each_value(&:freeze) # SEQUEL5
|
@@ -676,7 +662,7 @@ module Sequel
|
|
676
662
|
end
|
677
663
|
|
678
664
|
# Return an array of strings specifying a query explanation for a SELECT of the
|
679
|
-
# current dataset. Currently, the options are
|
665
|
+
# current dataset. Currently, the options are ignored, but it accepts options
|
680
666
|
# to be compatible with other adapters.
|
681
667
|
def explain(opts=nil)
|
682
668
|
# Load the PrettyTable class, needed for explain output
|
@@ -723,6 +709,10 @@ module Sequel
|
|
723
709
|
# DB[:table].insert_conflict(:replace).insert(:a=>1, :b=>2)
|
724
710
|
# # INSERT OR REPLACE INTO TABLE (a, b) VALUES (1, 2)
|
725
711
|
def insert_conflict(resolution = :ignore)
|
712
|
+
unless INSERT_CONFLICT_RESOLUTIONS.include?(resolution.to_s.upcase)
|
713
|
+
Sequel::Deprecation.deprecate("Passing #{resolution.inspect} argument to Dataset#insert_conflict", "The allowed values are: :rollback, :abort, :fail, :ignore, or :replace")
|
714
|
+
# raise Error, "Invalid value passed to Dataset#insert_conflict: #{resolution.inspect}. The allowed values are: :rollback, :abort, :fail, :ignore, or :replace"
|
715
|
+
end
|
726
716
|
clone(:insert_conflict => resolution)
|
727
717
|
end
|
728
718
|
|
@@ -19,7 +19,7 @@ module Sequel
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
tt = Class.new do
|
23
23
|
def blob(s) ::Sequel::SQL::Blob.new(s) end
|
24
24
|
def boolean(s) s.to_i != 0 end
|
25
25
|
def date(s) ::Date.strptime(s) end
|
@@ -27,6 +27,9 @@ module Sequel
|
|
27
27
|
def time(s) ::Sequel.string_to_time(s) end
|
28
28
|
end.new
|
29
29
|
|
30
|
+
TYPE_TRANSLATOR = tt
|
31
|
+
Sequel::Deprecation.deprecate_constant(self, :TYPE_TRANSLATOR)
|
32
|
+
|
30
33
|
SQLANYWHERE_TYPES = {}
|
31
34
|
{
|
32
35
|
[0, 484] => tt.method(:decimal),
|
@@ -7,9 +7,9 @@ module Sequel
|
|
7
7
|
# Top level module for holding all SQLite-related modules and classes
|
8
8
|
# for Sequel.
|
9
9
|
module SQLite
|
10
|
-
|
11
|
-
FALSE_VALUES = (%w'0 false f no n' + [0]).freeze
|
10
|
+
FALSE_VALUES = (%w'0 false f no n' + [0]).freeze
|
12
11
|
|
12
|
+
tt = Class.new do
|
13
13
|
def blob(s)
|
14
14
|
Sequel::SQL::Blob.new(s.to_s)
|
15
15
|
end
|
@@ -58,9 +58,11 @@ module Sequel
|
|
58
58
|
raise Sequel::Error, "unhandled type when converting to date: #{s.inspect} (#{s.class.inspect})"
|
59
59
|
end
|
60
60
|
end
|
61
|
-
|
62
61
|
end.new
|
63
62
|
|
63
|
+
TYPE_TRANSLATOR = tt
|
64
|
+
Sequel::Deprecation.deprecate_constant(self, :TYPE_TRANSLATOR)
|
65
|
+
|
64
66
|
# Hash with string keys and callable values for converting SQLite types.
|
65
67
|
SQLITE_TYPES = {}
|
66
68
|
{
|
@@ -4,8 +4,6 @@ require 'swift/db/postgres'
|
|
4
4
|
Sequel.require 'adapters/shared/postgres'
|
5
5
|
|
6
6
|
module Sequel
|
7
|
-
Postgres::CONVERTED_EXCEPTIONS << ::Swift::Error
|
8
|
-
|
9
7
|
module Swift
|
10
8
|
# Adapter, Database, and Dataset support for accessing a PostgreSQL
|
11
9
|
# database via Swift.
|
@@ -23,6 +21,11 @@ module Sequel
|
|
23
21
|
|
24
22
|
private
|
25
23
|
|
24
|
+
DATABASE_ERROR_CLASSES = [::Swift::Error].freeze
|
25
|
+
def database_error_classes
|
26
|
+
DATABASE_ERROR_CLASSES
|
27
|
+
end
|
28
|
+
|
26
29
|
# Remove all other options except for ones specifically handled, as
|
27
30
|
# otherwise swift passes them to dbic++ which passes them to PostgreSQL
|
28
31
|
# which can raise an error.
|
@@ -188,14 +188,11 @@ module Sequel
|
|
188
188
|
Database::DatasetClass = self
|
189
189
|
Sequel::Deprecation.deprecate_constant(Database, :DatasetClass)
|
190
190
|
|
191
|
-
# SQLite already supports named bind arguments, so use directly.
|
192
191
|
module ArgumentMapper
|
193
192
|
include Sequel::Dataset::ArgumentMapper
|
194
193
|
|
195
194
|
protected
|
196
195
|
|
197
|
-
# Return a hash with the same values as the given hash,
|
198
|
-
# but with the keys converted to strings.
|
199
196
|
def map_to_prepared_args(hash)
|
200
197
|
args = {}
|
201
198
|
hash.each{|k,v| args[k.to_s.gsub('.', '__')] = v}
|
@@ -204,8 +201,6 @@ module Sequel
|
|
204
201
|
|
205
202
|
private
|
206
203
|
|
207
|
-
# SQLite uses a : before the name of the argument for named
|
208
|
-
# arguments.
|
209
204
|
def prepared_arg(k)
|
210
205
|
LiteralString.new("@#{k.to_s.gsub('.', '__')}")
|
211
206
|
end
|
@@ -18,7 +18,7 @@ module Sequel
|
|
18
18
|
closed MySQL connection
|
19
19
|
END
|
20
20
|
# Error messages for mysql and mysql2 that indicate the current connection should be disconnected
|
21
|
-
MYSQL_DATABASE_DISCONNECT_ERRORS = /\A#{Regexp.union(disconnect_errors)}/
|
21
|
+
MYSQL_DATABASE_DISCONNECT_ERRORS = /\A#{Regexp.union(disconnect_errors)}/
|
22
22
|
|
23
23
|
# Support stored procedures on MySQL
|
24
24
|
def call_sproc(name, opts=OPTS, &block)
|
@@ -1,78 +1,4 @@
|
|
1
1
|
# frozen-string-literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
NAN = 0.0/0.0
|
6
|
-
PLUS_INFINITY = 1.0/0.0
|
7
|
-
MINUS_INFINITY = -1.0/0.0
|
8
|
-
|
9
|
-
NAN_STR = 'NaN'.freeze
|
10
|
-
Sequel::Deprecation.deprecate_constant(self, :NAN_STR)
|
11
|
-
PLUS_INFINITY_STR = 'Infinity'.freeze
|
12
|
-
Sequel::Deprecation.deprecate_constant(self, :PLUS_INFINITY_STR)
|
13
|
-
MINUS_INFINITY_STR = '-Infinity'.freeze
|
14
|
-
Sequel::Deprecation.deprecate_constant(self, :MINUS_INFINITY_STR)
|
15
|
-
TRUE_STR = 't'.freeze
|
16
|
-
Sequel::Deprecation.deprecate_constant(self, :TRUE_STR)
|
17
|
-
DASH_STR = '-'.freeze
|
18
|
-
Sequel::Deprecation.deprecate_constant(self, :DASH_STR)
|
19
|
-
|
20
|
-
TYPE_TRANSLATOR = tt = Class.new do
|
21
|
-
def boolean(s) s == 't' end
|
22
|
-
def integer(s) s.to_i end
|
23
|
-
def float(s)
|
24
|
-
case s
|
25
|
-
when 'NaN'
|
26
|
-
NAN
|
27
|
-
when 'Infinity'
|
28
|
-
PLUS_INFINITY
|
29
|
-
when '-Infinity'
|
30
|
-
MINUS_INFINITY
|
31
|
-
else
|
32
|
-
s.to_f
|
33
|
-
end
|
34
|
-
end
|
35
|
-
def date(s) ::Date.new(*s.split('-').map(&:to_i)) end
|
36
|
-
def bytea(str)
|
37
|
-
str = if str =~ /\A\\x/
|
38
|
-
# PostgreSQL 9.0+ bytea hex format
|
39
|
-
str[2..-1].gsub(/(..)/){|s| s.to_i(16).chr}
|
40
|
-
else
|
41
|
-
# Historical PostgreSQL bytea escape format
|
42
|
-
str.gsub(/\\(\\|'|[0-3][0-7][0-7])/) {|s|
|
43
|
-
if s.size == 2 then s[1,1] else s[1,3].oct.chr end
|
44
|
-
}
|
45
|
-
end
|
46
|
-
::Sequel::SQL::Blob.new(str)
|
47
|
-
end
|
48
|
-
end.new
|
49
|
-
|
50
|
-
# Type OIDs for string types used by PostgreSQL. These types don't
|
51
|
-
# have conversion procs associated with them (since the data is
|
52
|
-
# already in the form of a string).
|
53
|
-
STRING_TYPES = [18, 19, 25, 1042, 1043]#.freeze # SEQUEL5
|
54
|
-
|
55
|
-
# Hash with type name strings/symbols and callable values for converting PostgreSQL types.
|
56
|
-
# Non-builtin types that don't have fixed numbers should use this to register
|
57
|
-
# conversion procs.
|
58
|
-
PG_NAMED_TYPES = {} unless defined?(PG_NAMED_TYPES)
|
59
|
-
PG_NAMED__TYPES = PG_NAMED_TYPES
|
60
|
-
Sequel::Deprecation.deprecate_constant(self, :PG_NAMED_TYPES)
|
61
|
-
|
62
|
-
# Hash with integer keys and callable values for converting PostgreSQL types.
|
63
|
-
PG_TYPES = {} unless defined?(PG_TYPES)
|
64
|
-
|
65
|
-
{
|
66
|
-
[16] => tt.method(:boolean),
|
67
|
-
[17] => tt.method(:bytea),
|
68
|
-
[20, 21, 23, 26] => tt.method(:integer),
|
69
|
-
[700, 701] => tt.method(:float),
|
70
|
-
[1700] => ::BigDecimal.method(:new),
|
71
|
-
[1083, 1266] => ::Sequel.method(:string_to_time),
|
72
|
-
[1082] => ::Sequel.method(:string_to_date),
|
73
|
-
[1184, 1114] => ::Sequel.method(:database_to_application_timestamp),
|
74
|
-
}.each do |k,v|
|
75
|
-
k.each{|n| PG_TYPES[n] = v}
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
3
|
+
Sequel::Deprecation.deprecate("requiring sequel/adapters/utils/pg_types", "This file should no longer be required, use Database#conversion_procs to modify conversion procs for a Database instance")
|
4
|
+
Sequel.require 'adapters/shared/postgres'
|
@@ -93,7 +93,7 @@ module Sequel
|
|
93
93
|
def initialize(table, unused=nil)
|
94
94
|
if unused
|
95
95
|
# :nocov:
|
96
|
-
Sequel::Deprecation.deprecate("Passing two arguments to Sequel::Qualifier.new", 'Pass only the second
|
96
|
+
Sequel::Deprecation.deprecate("Passing two arguments to Sequel::Qualifier.new", 'Pass only the second argument specifying the table used for qualification')
|
97
97
|
@table = unused
|
98
98
|
# :nocov:
|
99
99
|
else
|
@@ -26,7 +26,7 @@ class Sequel::SingleConnectionPool < Sequel::ConnectionPool
|
|
26
26
|
def hold(server=nil)
|
27
27
|
begin
|
28
28
|
unless c = @conn.first
|
29
|
-
@conn.replace([c = make_new(
|
29
|
+
@conn.replace([c = make_new(:default)])
|
30
30
|
end
|
31
31
|
yield c
|
32
32
|
rescue Sequel::DatabaseDisconnectError, *@error_classes => e
|
@@ -57,5 +57,5 @@ class Sequel::SingleConnectionPool < Sequel::ConnectionPool
|
|
57
57
|
hold{}
|
58
58
|
end
|
59
59
|
|
60
|
-
|
60
|
+
CONNECTION_POOL__MAP[[true, false]] = self
|
61
61
|
end
|
@@ -198,7 +198,7 @@ class Sequel::ThreadedConnectionPool < Sequel::ConnectionPool
|
|
198
198
|
# available, tries to create a new connection. The calling code should already
|
199
199
|
# have the mutex before calling this.
|
200
200
|
def available
|
201
|
-
next_available || make_new(
|
201
|
+
next_available || make_new(:default)
|
202
202
|
end
|
203
203
|
|
204
204
|
# Return a connection to the pool of available connections, returns the connection.
|
@@ -282,5 +282,5 @@ class Sequel::ThreadedConnectionPool < Sequel::ConnectionPool
|
|
282
282
|
@mutex.synchronize{yield}
|
283
283
|
end
|
284
284
|
|
285
|
-
|
285
|
+
CONNECTION_POOL__MAP[[false, false]] = self
|
286
286
|
end
|
@@ -29,12 +29,15 @@ class Sequel::ConnectionPool
|
|
29
29
|
|
30
30
|
# The default server to use
|
31
31
|
DEFAULT_SERVER = :default
|
32
|
+
Sequel::Deprecation.deprecate_constant(self, :DEFAULT_SERVER)
|
32
33
|
|
33
34
|
# A map of [single threaded, sharded] values to symbols or ConnectionPool subclasses.
|
34
35
|
CONNECTION_POOL_MAP = {[true, false] => :single,
|
35
36
|
[true, true] => :sharded_single,
|
36
37
|
[false, false] => :threaded,
|
37
38
|
[false, true] => :sharded_threaded}
|
39
|
+
CONNECTION_POOL__MAP = CONNECTION_POOL_MAP
|
40
|
+
Sequel::Deprecation.deprecate_constant(self, :CONNECTION_POOL_MAP)
|
38
41
|
|
39
42
|
# Class methods used to return an appropriate pool subclass, separated
|
40
43
|
# into a module for easier overridding by extensions.
|
@@ -57,7 +60,10 @@ class Sequel::ConnectionPool
|
|
57
60
|
|
58
61
|
# Return a connection pool class based on the given options.
|
59
62
|
def connection_pool_class(opts)
|
60
|
-
|
63
|
+
if opts[:pool_class] && !opts[:pool_class].is_a?(Class) && ![:threaded, :single, :sharded_threaded, :sharded_single].include?(opts[:pool_class])
|
64
|
+
Sequel::Deprecation.deprecate("Using an unrecognized :pool_class option", "Use a class for the :pool_class option to select a custom pool class, or one of the following symbols for one of the default pool classes: :threaded, :single, :sharded_threaded, :sharded_single")
|
65
|
+
end
|
66
|
+
CONNECTION_POOL__MAP[opts[:pool_class]] || opts[:pool_class] || CONNECTION_POOL__MAP[[!!opts[:single_threaded], !!opts[:servers]]]
|
61
67
|
end
|
62
68
|
end
|
63
69
|
extend ClassMethods
|
@@ -89,12 +95,13 @@ class Sequel::ConnectionPool
|
|
89
95
|
|
90
96
|
# Alias for +size+, not aliased directly for ease of subclass implementation
|
91
97
|
def created_count(*args)
|
98
|
+
Sequel::Deprecation.deprecate("Sequel::ConnectionPool#created_count", "Use #size instead")
|
92
99
|
size(*args)
|
93
100
|
end
|
94
101
|
|
95
102
|
# An array of symbols for all shards/servers, which is a single <tt>:default</tt> by default.
|
96
103
|
def servers
|
97
|
-
[
|
104
|
+
[:default]
|
98
105
|
end
|
99
106
|
|
100
107
|
private
|
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
|
@@ -220,14 +220,14 @@ module Sequel
|
|
220
220
|
|
221
221
|
# Disconnects all available connections from the connection pool. Any
|
222
222
|
# connections currently in use will not be disconnected. Options:
|
223
|
-
# :
|
223
|
+
# :server :: Should be a symbol specifing the server to disconnect from,
|
224
224
|
# or an array of symbols to specify multiple servers.
|
225
225
|
#
|
226
226
|
# Example:
|
227
227
|
#
|
228
228
|
# DB.disconnect # All servers
|
229
|
-
# DB.disconnect(:
|
230
|
-
# DB.disconnect(:
|
229
|
+
# DB.disconnect(:server=>:server1) # Single server
|
230
|
+
# DB.disconnect(:server=>[:server1, :server2]) # Multiple servers
|
231
231
|
def disconnect(opts = OPTS)
|
232
232
|
pool.disconnect(opts)
|
233
233
|
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
|
|
@@ -69,6 +69,9 @@ module Sequel
|
|
69
69
|
# This allows you to override any of the dataset methods even if they are
|
70
70
|
# defined directly on the dataset class that this Database object uses.
|
71
71
|
#
|
72
|
+
# If a block is given, a Dataset::DatasetModule instance is created, allowing
|
73
|
+
# for the easy creation of named dataset methods that will do caching.
|
74
|
+
#
|
72
75
|
# Examples:
|
73
76
|
#
|
74
77
|
# # Introspec columns for all of DB's datasets
|
@@ -82,9 +85,19 @@ module Sequel
|
|
82
85
|
# super
|
83
86
|
# end
|
84
87
|
# end
|
88
|
+
#
|
89
|
+
# # Add some named dataset methods
|
90
|
+
# DB.extend_datasets do
|
91
|
+
# order :by_id, :id
|
92
|
+
# select :with_id_and_name, :id, :name
|
93
|
+
# where :active, :active
|
94
|
+
# end
|
95
|
+
#
|
96
|
+
# DB[:table].active.with_id_and_name.by_id
|
97
|
+
# # SELECT id, name FROM table WHERE active ORDER BY id
|
85
98
|
def extend_datasets(mod=nil, &block)
|
86
99
|
raise(Error, "must provide either mod or block, not both") if mod && block
|
87
|
-
mod =
|
100
|
+
mod = Dataset::DatasetModule.new(&block) if block
|
88
101
|
if @dataset_modules.empty?
|
89
102
|
@dataset_modules = [mod]
|
90
103
|
@dataset_class = Class.new(@dataset_class)
|