sequel 4.44.0 → 4.45.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +110 -0
- data/README.rdoc +8 -9
- data/doc/active_record.rdoc +2 -3
- data/doc/model_plugins.rdoc +1 -1
- data/doc/opening_databases.rdoc +0 -46
- data/doc/release_notes/4.45.0.txt +370 -0
- data/lib/sequel/adapters/cubrid.rb +2 -0
- data/lib/sequel/adapters/do.rb +2 -0
- data/lib/sequel/adapters/jdbc/as400.rb +2 -0
- data/lib/sequel/adapters/jdbc/cubrid.rb +2 -0
- data/lib/sequel/adapters/jdbc/firebirdsql.rb +2 -0
- data/lib/sequel/adapters/jdbc/informix-sqli.rb +2 -0
- data/lib/sequel/adapters/jdbc/jdbcprogress.rb +2 -0
- data/lib/sequel/adapters/jdbc/mysql.rb +1 -0
- data/lib/sequel/adapters/jdbc/postgresql.rb +5 -0
- data/lib/sequel/adapters/mysql.rb +1 -0
- data/lib/sequel/adapters/mysql2.rb +1 -0
- data/lib/sequel/adapters/odbc/oracle.rb +11 -0
- data/lib/sequel/adapters/odbc/progress.rb +2 -0
- data/lib/sequel/adapters/postgres.rb +0 -2
- data/lib/sequel/adapters/shared/cubrid.rb +2 -0
- data/lib/sequel/adapters/shared/firebird.rb +2 -0
- data/lib/sequel/adapters/shared/informix.rb +2 -0
- data/lib/sequel/adapters/shared/mssql.rb +47 -7
- data/lib/sequel/adapters/shared/mysql.rb +16 -1
- data/lib/sequel/adapters/shared/postgres.rb +9 -1
- data/lib/sequel/adapters/shared/progress.rb +2 -0
- data/lib/sequel/adapters/shared/sqlanywhere.rb +1 -1
- data/lib/sequel/adapters/swift.rb +2 -0
- data/lib/sequel/ast_transformer.rb +13 -6
- data/lib/sequel/core.rb +13 -16
- data/lib/sequel/database/connecting.rb +25 -10
- data/lib/sequel/database/dataset.rb +6 -1
- data/lib/sequel/database/dataset_defaults.rb +9 -2
- data/lib/sequel/database/misc.rb +10 -3
- data/lib/sequel/database/schema_methods.rb +4 -0
- data/lib/sequel/dataset/mutation.rb +8 -20
- data/lib/sequel/dataset/prepared_statements.rb +2 -0
- data/lib/sequel/dataset/query.rb +32 -7
- data/lib/sequel/dataset/sql.rb +13 -3
- data/lib/sequel/deprecated.rb +9 -1
- data/lib/sequel/exceptions.rb +37 -8
- data/lib/sequel/extensions/_deprecated_identifier_mangling.rb +117 -0
- data/lib/sequel/extensions/date_arithmetic.rb +1 -0
- data/lib/sequel/extensions/identifier_mangling.rb +3 -2
- data/lib/sequel/extensions/pg_hstore.rb +1 -5
- data/lib/sequel/extensions/schema_dumper.rb +3 -1
- data/lib/sequel/extensions/sequel_3_dataset_methods.rb +2 -2
- data/lib/sequel/extensions/string_agg.rb +1 -0
- data/lib/sequel/model.rb +23 -10
- data/lib/sequel/model/associations.rb +17 -5
- data/lib/sequel/model/base.rb +115 -62
- data/lib/sequel/model/dataset_module.rb +10 -3
- data/lib/sequel/model/exceptions.rb +7 -5
- data/lib/sequel/plugins/association_pks.rb +13 -1
- data/lib/sequel/plugins/association_proxies.rb +8 -1
- data/lib/sequel/plugins/before_after_save.rb +1 -0
- data/lib/sequel/plugins/class_table_inheritance.rb +7 -3
- data/lib/sequel/plugins/columns_updated.rb +42 -0
- data/lib/sequel/plugins/composition.rb +10 -5
- data/lib/sequel/plugins/error_splitter.rb +1 -1
- data/lib/sequel/plugins/hook_class_methods.rb +39 -5
- data/lib/sequel/plugins/instance_hooks.rb +58 -5
- data/lib/sequel/plugins/lazy_attributes.rb +10 -5
- data/lib/sequel/plugins/nested_attributes.rb +10 -5
- data/lib/sequel/plugins/prepared_statements.rb +7 -0
- data/lib/sequel/plugins/prepared_statements_associations.rb +2 -0
- data/lib/sequel/plugins/prepared_statements_with_pk.rb +2 -0
- data/lib/sequel/plugins/schema.rb +2 -0
- data/lib/sequel/plugins/scissors.rb +2 -0
- data/lib/sequel/plugins/serialization.rb +10 -5
- data/lib/sequel/plugins/split_values.rb +5 -1
- data/lib/sequel/plugins/static_cache.rb +2 -2
- data/lib/sequel/plugins/tactical_eager_loading.rb +1 -1
- data/lib/sequel/plugins/validation_contexts.rb +49 -0
- data/lib/sequel/plugins/validation_helpers.rb +1 -0
- data/lib/sequel/sql.rb +1 -1
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/mssql_spec.rb +31 -0
- data/spec/adapters/mysql_spec.rb +20 -2
- data/spec/adapters/postgres_spec.rb +43 -12
- data/spec/adapters/spec_helper.rb +5 -8
- data/spec/core/database_spec.rb +47 -12
- data/spec/core/dataset_mutation_spec.rb +22 -22
- data/spec/core/dataset_spec.rb +88 -20
- data/spec/core/deprecated_spec.rb +1 -1
- data/spec/core/expression_filters_spec.rb +1 -1
- data/spec/core/mock_adapter_spec.rb +0 -3
- data/spec/core/placeholder_literalizer_spec.rb +1 -1
- data/spec/core/schema_spec.rb +8 -1
- data/spec/core/spec_helper.rb +6 -1
- data/spec/core_extensions_spec.rb +4 -0
- data/spec/deprecation_helper.rb +17 -0
- data/spec/extensions/_deprecated_identifier_mangling_spec.rb +314 -0
- data/spec/extensions/association_pks_spec.rb +61 -13
- data/spec/extensions/association_proxies_spec.rb +3 -3
- data/spec/extensions/class_table_inheritance_spec.rb +39 -0
- data/spec/extensions/columns_updated_spec.rb +35 -0
- data/spec/extensions/composition_spec.rb +6 -1
- data/spec/extensions/hook_class_methods_spec.rb +114 -26
- data/spec/extensions/identifier_mangling_spec.rb +107 -73
- data/spec/extensions/instance_hooks_spec.rb +78 -14
- data/spec/extensions/lazy_attributes_spec.rb +8 -2
- data/spec/extensions/many_through_many_spec.rb +2 -2
- data/spec/extensions/mssql_optimistic_locking_spec.rb +1 -1
- data/spec/extensions/nested_attributes_spec.rb +8 -2
- data/spec/extensions/pg_array_spec.rb +18 -4
- data/spec/extensions/prepared_statements_associations_spec.rb +48 -39
- data/spec/extensions/prepared_statements_with_pk_spec.rb +13 -11
- data/spec/extensions/query_spec.rb +1 -1
- data/spec/extensions/schema_dumper_spec.rb +34 -6
- data/spec/extensions/schema_spec.rb +13 -7
- data/spec/extensions/scissors_spec.rb +3 -1
- data/spec/extensions/sequel_3_dataset_methods_spec.rb +4 -4
- data/spec/extensions/serialization_spec.rb +7 -1
- data/spec/extensions/set_overrides_spec.rb +2 -2
- data/spec/extensions/shared_caching_spec.rb +19 -15
- data/spec/extensions/spec_helper.rb +7 -3
- data/spec/extensions/split_values_spec.rb +45 -10
- data/spec/extensions/string_agg_spec.rb +2 -2
- data/spec/extensions/subset_conditions_spec.rb +3 -3
- data/spec/extensions/tactical_eager_loading_spec.rb +1 -1
- data/spec/extensions/validation_contexts_spec.rb +31 -0
- data/spec/guards_helper.rb +2 -0
- data/spec/integration/associations_test.rb +22 -20
- data/spec/integration/dataset_test.rb +25 -2
- data/spec/integration/model_test.rb +1 -1
- data/spec/integration/plugin_test.rb +11 -16
- data/spec/integration/prepared_statement_test.rb +40 -32
- data/spec/integration/spec_helper.rb +5 -8
- data/spec/model/association_reflection_spec.rb +4 -0
- data/spec/model/associations_spec.rb +37 -10
- data/spec/model/base_spec.rb +6 -0
- data/spec/model/hooks_spec.rb +56 -35
- data/spec/model/model_spec.rb +21 -5
- data/spec/model/record_spec.rb +14 -11
- data/spec/model/spec_helper.rb +7 -1
- data/spec/sequel_warning.rb +11 -0
- metadata +13 -3
data/lib/sequel/exceptions.rb
CHANGED
@@ -9,48 +9,72 @@ module Sequel
|
|
9
9
|
attr_accessor :wrapped_exception
|
10
10
|
end
|
11
11
|
|
12
|
+
(
|
12
13
|
# Error raised when the adapter requested doesn't exist or can't be loaded.
|
13
14
|
AdapterNotFound = Class.new(Error)
|
15
|
+
).name
|
14
16
|
|
17
|
+
(
|
15
18
|
# Generic error raised by the database adapters, indicating a
|
16
19
|
# problem originating from the database server. Usually raised
|
17
20
|
# because incorrect SQL syntax is used.
|
18
21
|
DatabaseError = Class.new(Error)
|
22
|
+
).name
|
19
23
|
|
24
|
+
(
|
20
25
|
# Error raised when the Sequel is unable to connect to the database with the
|
21
26
|
# connection parameters it was given.
|
22
27
|
DatabaseConnectionError = Class.new(DatabaseError)
|
28
|
+
).name
|
23
29
|
|
30
|
+
(
|
24
31
|
# Error raised by adapters when they determine that the connection
|
25
32
|
# to the database has been lost. Instructs the connection pool code to
|
26
33
|
# remove that connection from the pool so that other connections can be acquired
|
27
34
|
# automatically.
|
28
35
|
DatabaseDisconnectError = Class.new(DatabaseError)
|
36
|
+
).name
|
29
37
|
|
38
|
+
(
|
30
39
|
# Generic error raised when Sequel determines a database constraint has been violated.
|
31
40
|
ConstraintViolation = Class.new(DatabaseError)
|
41
|
+
).name
|
32
42
|
|
43
|
+
(
|
33
44
|
# Error raised when Sequel determines a database check constraint has been violated.
|
34
45
|
CheckConstraintViolation = Class.new(ConstraintViolation)
|
46
|
+
).name
|
35
47
|
|
48
|
+
(
|
36
49
|
# Error raised when Sequel determines a database foreign key constraint has been violated.
|
37
50
|
ForeignKeyConstraintViolation = Class.new(ConstraintViolation)
|
51
|
+
).name
|
38
52
|
|
53
|
+
(
|
39
54
|
# Error raised when Sequel determines a database NOT NULL constraint has been violated.
|
40
55
|
NotNullConstraintViolation = Class.new(ConstraintViolation)
|
56
|
+
).name
|
41
57
|
|
58
|
+
(
|
42
59
|
# Error raised when Sequel determines a database unique constraint has been violated.
|
43
60
|
UniqueConstraintViolation = Class.new(ConstraintViolation)
|
61
|
+
).name
|
44
62
|
|
63
|
+
(
|
45
64
|
# Error raised when Sequel determines a serialization failure/deadlock in the database.
|
46
65
|
SerializationFailure = Class.new(DatabaseError)
|
66
|
+
).name
|
47
67
|
|
68
|
+
(
|
48
69
|
# Error raised on an invalid operation, such as trying to update or delete
|
49
70
|
# a joined or grouped dataset.
|
50
71
|
InvalidOperation = Class.new(Error)
|
72
|
+
).name
|
51
73
|
|
74
|
+
(
|
52
75
|
# Error raised when attempting an invalid type conversion.
|
53
76
|
InvalidValue = Class.new(Error)
|
77
|
+
).name
|
54
78
|
|
55
79
|
# Error raised when the user requests a record via the first! or similar
|
56
80
|
# method, and the dataset does not yield any rows.
|
@@ -69,27 +93,32 @@ module Sequel
|
|
69
93
|
end
|
70
94
|
end
|
71
95
|
|
96
|
+
(
|
72
97
|
# Error raised when the connection pool cannot acquire a database connection
|
73
98
|
# before the timeout.
|
74
99
|
PoolTimeout = Class.new(Error)
|
100
|
+
).name
|
75
101
|
|
102
|
+
(
|
76
103
|
# Error that you should raise to signal a rollback of the current transaction.
|
77
104
|
# The transaction block will catch this exception, rollback the current transaction,
|
78
105
|
# and won't reraise it (unless a reraise is requested).
|
79
106
|
Rollback = Class.new(Error)
|
107
|
+
).name
|
80
108
|
|
81
|
-
#
|
82
|
-
|
83
|
-
UnbindDuplicate = Class.new(Error)
|
84
|
-
|
85
|
-
# Call name on each class to set the name for the class, so it gets cached.
|
86
|
-
constants.map{|c| const_get(c)}.each do |c|
|
87
|
-
Class === c && c.name
|
88
|
-
end
|
109
|
+
# SEQUEL5: Remove
|
110
|
+
(UnbindDuplicate = Class.new(Error)).name
|
89
111
|
|
90
112
|
Error::AdapterNotFound = AdapterNotFound
|
91
113
|
Error::InvalidOperation = InvalidOperation
|
92
114
|
Error::InvalidValue = InvalidValue
|
93
115
|
Error::PoolTimeoutError = PoolTimeout
|
94
116
|
Error::Rollback = Rollback
|
117
|
+
|
118
|
+
Sequel::Deprecation.deprecate_constant(self, :UnbindDuplicate)
|
119
|
+
Sequel::Deprecation.deprecate_constant(Error, :AdapterNotFound)
|
120
|
+
Sequel::Deprecation.deprecate_constant(Error, :InvalidOperation)
|
121
|
+
Sequel::Deprecation.deprecate_constant(Error, :InvalidValue)
|
122
|
+
Sequel::Deprecation.deprecate_constant(Error, :PoolTimeoutError)
|
123
|
+
Sequel::Deprecation.deprecate_constant(Error, :Rollback)
|
95
124
|
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
module Sequel
|
5
|
+
module DeprecatedIdentifierMangling
|
6
|
+
module DatabaseMethods
|
7
|
+
def self.extended(db)
|
8
|
+
db.instance_exec do
|
9
|
+
@identifier_input_method = nil
|
10
|
+
@identifier_output_method = nil
|
11
|
+
@quote_identifiers = nil
|
12
|
+
reset_identifier_mangling
|
13
|
+
extend_datasets(DatasetMethods)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_reader :identifier_input_method
|
18
|
+
attr_reader :identifier_output_method
|
19
|
+
|
20
|
+
def identifier_input_method=(v)
|
21
|
+
Sequel::Deprecation.deprecate("Database#identifier_input_method=", "Explicitly load the identifier_mangling extension if you would like to use this")
|
22
|
+
reset_default_dataset
|
23
|
+
@identifier_input_method = v
|
24
|
+
end
|
25
|
+
|
26
|
+
def identifier_output_method=(v)
|
27
|
+
Sequel::Deprecation.deprecate("Database#identifier_output_method=", "Explicitly load the identifier_mangling extension if you would like to use this")
|
28
|
+
reset_default_dataset
|
29
|
+
@identifier_output_method = v
|
30
|
+
end
|
31
|
+
|
32
|
+
def quote_identifiers=(v)
|
33
|
+
Sequel::Deprecation.deprecate("Database#quote_identifiers=", "Explicitly load the identifier_mangling extension if you would like to use this")
|
34
|
+
reset_default_dataset
|
35
|
+
@quote_identifiers = v
|
36
|
+
end
|
37
|
+
|
38
|
+
def quote_identifiers?
|
39
|
+
@quote_identifiers
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def _metadata_dataset
|
45
|
+
super.clone(:identifier_input_method=>identifier_input_method_default, :identifier_output_method=>identifier_output_method_default, :skip_symbol_cache=>true)
|
46
|
+
end
|
47
|
+
|
48
|
+
def identifier_input_method_default
|
49
|
+
return super if defined?(super)
|
50
|
+
:upcase if folds_unquoted_identifiers_to_uppercase?
|
51
|
+
end
|
52
|
+
|
53
|
+
def identifier_output_method_default
|
54
|
+
return super if defined?(super)
|
55
|
+
:downcase if folds_unquoted_identifiers_to_uppercase?
|
56
|
+
end
|
57
|
+
|
58
|
+
def reset_identifier_mangling
|
59
|
+
@quote_identifiers = @opts.fetch(:quote_identifiers){(qi = Database.quote_identifiers).nil? ? quote_identifiers_default : qi}
|
60
|
+
@identifier_input_method = @opts.fetch(:identifier_input_method){(iim = Database.identifier_input_method).nil? ? identifier_input_method_default : (iim if iim)}
|
61
|
+
@identifier_output_method = @opts.fetch(:identifier_output_method){(iom = Database.identifier_output_method).nil? ? identifier_output_method_default : (iom if iom)}
|
62
|
+
reset_default_dataset
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
module DatasetMethods
|
67
|
+
def identifier_input_method
|
68
|
+
@opts.fetch(:identifier_input_method, db.identifier_input_method)
|
69
|
+
end
|
70
|
+
|
71
|
+
def identifier_input_method=(v)
|
72
|
+
Sequel::Deprecation.deprecate("Dataset#identifier_input_method=", "Explicitly load the identifier_mangling extension if you would like to use this")
|
73
|
+
raise_if_frozen!("identifier_input_method=")
|
74
|
+
skip_symbol_cache!
|
75
|
+
@opts[:identifier_input_method] = v
|
76
|
+
end
|
77
|
+
|
78
|
+
def identifier_output_method
|
79
|
+
@opts.fetch(:identifier_output_method, db.identifier_output_method)
|
80
|
+
end
|
81
|
+
|
82
|
+
def identifier_output_method=(v)
|
83
|
+
Sequel::Deprecation.deprecate("Dataset#identifier_output_method=", "Explicitly load the identifier_mangling extension if you would like to use this")
|
84
|
+
raise_if_frozen!("identifier_output_method=")
|
85
|
+
@opts[:identifier_output_method] = v
|
86
|
+
end
|
87
|
+
|
88
|
+
def quote_identifiers?
|
89
|
+
@opts.fetch(:quote_identifiers, db.quote_identifiers?)
|
90
|
+
end
|
91
|
+
|
92
|
+
def with_identifier_input_method(meth)
|
93
|
+
Sequel::Deprecation.deprecate("Dataset#with_identifier_input_method", "Explicitly load the identifier_mangling extension if you would like to use this")
|
94
|
+
clone(:identifier_input_method=>meth, :skip_symbol_cache=>true)
|
95
|
+
end
|
96
|
+
|
97
|
+
def with_identifier_output_method(meth)
|
98
|
+
Sequel::Deprecation.deprecate("Dataset#with_identifier_output_method", "Explicitly load the identifier_mangling extension if you would like to use this")
|
99
|
+
clone(:identifier_output_method=>meth)
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
|
104
|
+
def input_identifier(v)
|
105
|
+
(i = identifier_input_method) ? v.to_s.send(i) : v.to_s
|
106
|
+
end
|
107
|
+
|
108
|
+
def output_identifier(v)
|
109
|
+
v = 'untitled' if v == ''
|
110
|
+
(i = identifier_output_method) ? v.to_s.send(i).to_sym : v.to_sym
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
Database.register_extension(:_deprecated_identifier_mangling, DeprecatedIdentifierMangling::DatabaseMethods)
|
116
|
+
end
|
117
|
+
|
@@ -92,6 +92,7 @@ module Sequel
|
|
92
92
|
args << "#{value} #{sql_unit}"
|
93
93
|
end
|
94
94
|
return function_sql_append(sql, Sequel.function(:datetime, *args))
|
95
|
+
# SEQUEL5: Remove cubrid
|
95
96
|
when :mysql, :hsqldb, :cubrid
|
96
97
|
if db_type == :hsqldb
|
97
98
|
# HSQLDB requires 2.2.9+ for the DATE_ADD function
|
@@ -127,6 +127,7 @@ module Sequel
|
|
127
127
|
# Reset the identifier mangling options. Overrides any already set on
|
128
128
|
# the instance. Only for internal use by shared adapters.
|
129
129
|
def reset_identifier_mangling
|
130
|
+
# SEQUEL5: Stop checking Database.*
|
130
131
|
@quote_identifiers = @opts.fetch(:quote_identifiers){(qi = Database.quote_identifiers).nil? ? quote_identifiers_default : qi}
|
131
132
|
@identifier_input_method = @opts.fetch(:identifier_input_method){(iim = Database.identifier_input_method).nil? ? identifier_input_method_default : (iim if iim)}
|
132
133
|
@identifier_output_method = @opts.fetch(:identifier_output_method){(iom = Database.identifier_output_method).nil? ? identifier_output_method_default : (iom if iom)}
|
@@ -143,7 +144,7 @@ module Sequel
|
|
143
144
|
|
144
145
|
# Set the method to call on identifiers going into the database for this dataset
|
145
146
|
def identifier_input_method=(v)
|
146
|
-
raise_if_frozen!
|
147
|
+
raise_if_frozen!("identifier_input_method=")
|
147
148
|
skip_symbol_cache!
|
148
149
|
@opts[:identifier_input_method] = v
|
149
150
|
end
|
@@ -156,7 +157,7 @@ module Sequel
|
|
156
157
|
|
157
158
|
# Set the method to call on identifiers coming the database for this dataset
|
158
159
|
def identifier_output_method=(v)
|
159
|
-
raise_if_frozen!
|
160
|
+
raise_if_frozen!("identifier_output_method=")
|
160
161
|
@opts[:identifier_output_method] = v
|
161
162
|
end
|
162
163
|
|
@@ -141,7 +141,7 @@ module Sequel
|
|
141
141
|
module DatabaseMethods
|
142
142
|
def self.extended(db)
|
143
143
|
db.instance_eval do
|
144
|
-
add_named_conversion_proc(:hstore)
|
144
|
+
add_named_conversion_proc(:hstore, &HStore.method(:parse))
|
145
145
|
@schema_type_classes[:hstore] = HStore
|
146
146
|
end
|
147
147
|
end
|
@@ -306,10 +306,6 @@ module Sequel
|
|
306
306
|
k.to_s.gsub(ESCAPE_RE, ESCAPE_REPLACE)
|
307
307
|
end
|
308
308
|
end
|
309
|
-
|
310
|
-
PG_NAMED_TYPES = {} unless defined?(PG_NAMED_TYPES)
|
311
|
-
# Associate the named types by default.
|
312
|
-
PG_NAMED_TYPES[:hstore] = HStore.method(:parse)
|
313
309
|
end
|
314
310
|
|
315
311
|
module SQL::Builders
|
@@ -170,6 +170,8 @@ END_MIG
|
|
170
170
|
[:table, :key, :on_delete, :on_update, :deferrable].each{|f| type_hash[f] = schema[f] if schema[f]}
|
171
171
|
if type_hash == {:type=>Integer} || type_hash == {:type=>"integer"}
|
172
172
|
type_hash.delete(:type)
|
173
|
+
elsif options[:same_db] && type_hash == {:type=>type_literal_generic_bignum_symbol(type_hash).to_s}
|
174
|
+
type_hash[:type] = :Bignum
|
173
175
|
end
|
174
176
|
|
175
177
|
unless gen.columns.empty?
|
@@ -243,7 +245,7 @@ END_MIG
|
|
243
245
|
# Return a Schema::Generator object that will recreate the
|
244
246
|
# table's schema. Takes the same options as dump_schema_migration.
|
245
247
|
def dump_table_generator(table, options=OPTS)
|
246
|
-
s = schema(table).dup
|
248
|
+
s = schema(table, options).dup
|
247
249
|
pks = s.find_all{|x| x.last[:primary_key] == true}.map(&:first)
|
248
250
|
options = options.merge(:single_pk=>true) if pks.length == 1
|
249
251
|
m = method(:recreate_column)
|
@@ -29,14 +29,14 @@ module Sequel
|
|
29
29
|
COMMA = Dataset::COMMA
|
30
30
|
# Change the database for this dataset.
|
31
31
|
def db=(v)
|
32
|
-
raise_if_frozen!
|
32
|
+
raise_if_frozen!("db=")
|
33
33
|
@db = v
|
34
34
|
@cache = {}
|
35
35
|
end
|
36
36
|
|
37
37
|
# Change the options for this dataset.
|
38
38
|
def opts=(v)
|
39
|
-
raise_if_frozen!
|
39
|
+
raise_if_frozen!("opts=")
|
40
40
|
@opts = v
|
41
41
|
@cache = {}
|
42
42
|
end
|
data/lib/sequel/model.rb
CHANGED
@@ -5,11 +5,13 @@ require 'sequel/core'
|
|
5
5
|
module Sequel
|
6
6
|
# Delegate to Sequel::Model, only for backwards compatibility.
|
7
7
|
def self.cache_anonymous_models
|
8
|
+
Sequel::Deprecation.deprecate("Sequel.cache_anonymous_models", "Use Sequel::Model.cache_anonymous_models")
|
8
9
|
Model.cache_anonymous_models
|
9
10
|
end
|
10
11
|
|
11
12
|
# Delegate to Sequel::Model, only for backwards compatibility.
|
12
13
|
def self.cache_anonymous_models=(v)
|
14
|
+
Sequel::Deprecation.deprecate("Sequel.cache_anonymous_models=", "Use Sequel::Model.cache_anonymous_models=")
|
13
15
|
Model.cache_anonymous_models = v
|
14
16
|
end
|
15
17
|
|
@@ -29,13 +31,6 @@ module Sequel
|
|
29
31
|
class Model
|
30
32
|
OPTS = Sequel::OPTS
|
31
33
|
|
32
|
-
# Map that stores model classes created with <tt>Sequel::Model()</tt>, to allow the reopening
|
33
|
-
# of classes when dealing with code reloading.
|
34
|
-
ANONYMOUS_MODEL_CLASSES = @Model_cache = {}
|
35
|
-
|
36
|
-
# Mutex protecting access to ANONYMOUS_MODEL_CLASSES
|
37
|
-
ANONYMOUS_MODEL_CLASSES_MUTEX = @Model_mutex = Mutex.new
|
38
|
-
|
39
34
|
# Class methods added to model that call the method of the same name on the dataset
|
40
35
|
DATASET_METHODS = (Dataset::ACTION_METHODS + Dataset::QUERY_METHODS + [:each_server, :where_all, :where_each, :where_single_value]) -
|
41
36
|
[:and, :or, :[], :columns, :columns!, :delete, :update, :add_graph_aliases, :first, :first!]
|
@@ -51,8 +46,8 @@ module Sequel
|
|
51
46
|
|
52
47
|
# Hooks that are called after an action. When overriding these, it is recommended to call
|
53
48
|
# +super+ on the first line of your method, so later hooks are called after earlier hooks.
|
54
|
-
AFTER_HOOKS = [:after_create, :after_update, :after_save, :after_destroy,
|
55
|
-
|
49
|
+
AFTER_HOOKS = [:after_create, :after_update, :after_save, :after_destroy, :after_validation,
|
50
|
+
:after_commit, :after_rollback, :after_destroy_commit, :after_destroy_rollback] # SEQUEL5: Remove commit/rollback hooks
|
56
51
|
|
57
52
|
# Hooks that are called around an action. If overridden, these methods must call super
|
58
53
|
# exactly once if the behavior they wrap is desired. The can be used to rescue exceptions
|
@@ -78,7 +73,7 @@ module Sequel
|
|
78
73
|
:@use_after_commit_rollback=>nil, :@fast_pk_lookup_sql=>nil,
|
79
74
|
:@fast_instance_delete_sql=>nil, :@finders=>:dup, :@finder_loaders=>:dup,
|
80
75
|
:@db=>nil, :@default_set_fields_options=>:dup, :@require_valid_table=>nil,
|
81
|
-
:@cache_anonymous_models=>nil, :@
|
76
|
+
:@cache_anonymous_models=>nil, :@dataset_module_class=>nil}
|
82
77
|
|
83
78
|
# Regular expression that determines if a method name is normal in the sense that
|
84
79
|
# it could be used literally in ruby code without using send. Used to
|
@@ -129,5 +124,23 @@ module Sequel
|
|
129
124
|
RESTRICTED_SETTER_METHODS = instance_methods.map(&:to_s).grep(SETTER_METHOD_REGEXP)
|
130
125
|
|
131
126
|
def_Model(::Sequel)
|
127
|
+
|
128
|
+
# SEQUEL5: Remove
|
129
|
+
class DeprecatedColumnsUpdated # :nodoc:
|
130
|
+
def initialize(columns_updated)
|
131
|
+
@columns_updated = columns_updated
|
132
|
+
end
|
133
|
+
|
134
|
+
def method_missing(*args, &block)
|
135
|
+
Sequel::Deprecation.deprecate("Accessing @columns_updated directly", "Use the columns_updated plugin and switch to the columns_updated method")
|
136
|
+
@columns_updated.send(*args, &block)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
ANONYMOUS_MODEL_CLASSES = @Model_cache # :nodoc:
|
141
|
+
Sequel::Deprecation.deprecate_constant(self, :ANONYMOUS_MODEL_CLASSES)
|
142
|
+
|
143
|
+
ANONYMOUS_MODEL_CLASSES_MUTEX = Mutex.new # :nodoc:
|
144
|
+
Sequel::Deprecation.deprecate_constant(self, :ANONYMOUS_MODEL_CLASSES_MUTEX)
|
132
145
|
end
|
133
146
|
end
|
@@ -15,9 +15,15 @@ module Sequel
|
|
15
15
|
@autoreloading_associations = {}
|
16
16
|
@cache_associations = true
|
17
17
|
@default_association_options = {}
|
18
|
+
@dataset_module_class = DatasetModule
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
22
|
+
# The dataset module to use for classes using the associations plugin.
|
23
|
+
class DatasetModule < Model::DatasetModule
|
24
|
+
def_dataset_caching_method(self, :eager)
|
25
|
+
end
|
26
|
+
|
21
27
|
# AssociationReflection is a Hash subclass that keeps information on Sequel::Model associations. It
|
22
28
|
# provides methods to reduce internal code duplication. It should not
|
23
29
|
# be instantiated by the user.
|
@@ -83,7 +89,7 @@ module Sequel
|
|
83
89
|
end
|
84
90
|
ds = ds.order(*self[:order]) if self[:order]
|
85
91
|
ds = ds.limit(*self[:limit]) if self[:limit]
|
86
|
-
ds = ds.limit(1) if limit_to_single_row?
|
92
|
+
ds = ds.limit(1).skip_limit_check if limit_to_single_row?
|
87
93
|
ds = ds.eager(self[:eager]) if self[:eager]
|
88
94
|
ds = ds.distinct if self[:distinct]
|
89
95
|
ds
|
@@ -426,7 +432,7 @@ module Sequel
|
|
426
432
|
if use_placeholder_loader?
|
427
433
|
cached_fetch(:placeholder_loader) do
|
428
434
|
Sequel::Dataset::PlaceholderLiteralizer.loader(associated_dataset) do |pl, ds|
|
429
|
-
ds.where(*predicate_keys.map{|k| SQL::BooleanExpression.new(:'=', k, pl.arg)})
|
435
|
+
ds.where(Sequel.&(*predicate_keys.map{|k| SQL::BooleanExpression.new(:'=', k, pl.arg)}))
|
430
436
|
end
|
431
437
|
end
|
432
438
|
end
|
@@ -451,7 +457,7 @@ module Sequel
|
|
451
457
|
when Symbol, SQL::Identifier
|
452
458
|
SQL::QualifiedIdentifier.new(table, k)
|
453
459
|
else
|
454
|
-
Sequel::Qualifier.new(
|
460
|
+
Sequel::Qualifier.new(table).transform(k)
|
455
461
|
end
|
456
462
|
end
|
457
463
|
end
|
@@ -1891,7 +1897,10 @@ module Sequel
|
|
1891
1897
|
|
1892
1898
|
# Adds the association method to the association methods module.
|
1893
1899
|
def def_association_method(opts)
|
1894
|
-
association_module_def(opts.association_method, opts)
|
1900
|
+
association_module_def(opts.association_method, opts) do |*dynamic_opts, &block|
|
1901
|
+
Sequel::Deprecation.deprecate("Passing multiple arguments to ##{opts.association_method}", "Additional arguments are currently ignored.") if dynamic_opts.length > 1
|
1902
|
+
load_associated_objects(opts, dynamic_opts.length == 0 ? OPTS : dynamic_opts[0], &block)
|
1903
|
+
end
|
1895
1904
|
end
|
1896
1905
|
|
1897
1906
|
# Define all of the association instance methods for this association.
|
@@ -2159,7 +2168,7 @@ module Sequel
|
|
2159
2168
|
cks.zip(cpks).each{|k, pk| o.set_column_value(:"#{k}=", get_column_value(pk))}
|
2160
2169
|
end
|
2161
2170
|
checked_transaction do
|
2162
|
-
up_ds.update(ck_nil_hash)
|
2171
|
+
up_ds.skip_limit_check.update(ck_nil_hash)
|
2163
2172
|
o.save(save_opts) || raise(Sequel::Error, "invalid associated object, cannot save") if o
|
2164
2173
|
end
|
2165
2174
|
end
|
@@ -2384,13 +2393,16 @@ module Sequel
|
|
2384
2393
|
def load_association_objects_options(dynamic_opts, &block)
|
2385
2394
|
dynamic_opts = case dynamic_opts
|
2386
2395
|
when true, false, nil
|
2396
|
+
Sequel::Deprecation.deprecate("Passing #{dynamic_opts.inspect} an argument to an association loading method", "Pass {:reload=>#{dynamic_opts.inspect}} instead")
|
2387
2397
|
{:reload=>dynamic_opts}
|
2388
2398
|
when Hash
|
2389
2399
|
Hash[dynamic_opts]
|
2390
2400
|
else
|
2391
2401
|
if dynamic_opts.respond_to?(:call)
|
2402
|
+
Sequel::Deprecation.deprecate("Passing callbable argument #{dynamic_opts.inspect} to an association loading method", "Pass a block to the method to use a callback")
|
2392
2403
|
{:callback=>dynamic_opts}
|
2393
2404
|
else
|
2405
|
+
Sequel::Deprecation.deprecate("Passing #{dynamic_opts.inspect} an argument to an association loading method", "Pass {:reload=>true} if you would like to reload the association")
|
2394
2406
|
{:reload=>true}
|
2395
2407
|
end
|
2396
2408
|
end
|