sequel 5.106.0 → 5.109.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/sequel +5 -5
- data/lib/sequel/adapters/ado.rb +1 -1
- data/lib/sequel/adapters/amalgalite.rb +34 -8
- data/lib/sequel/adapters/ibmdb.rb +2 -2
- data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -1
- data/lib/sequel/adapters/jdbc/mssql.rb +28 -5
- data/lib/sequel/adapters/jdbc/mysql.rb +1 -1
- data/lib/sequel/adapters/jdbc/postgresql.rb +14 -3
- data/lib/sequel/adapters/jdbc.rb +4 -3
- data/lib/sequel/adapters/mock.rb +1 -1
- data/lib/sequel/adapters/mysql.rb +7 -2
- data/lib/sequel/adapters/mysql2.rb +5 -4
- data/lib/sequel/adapters/postgres.rb +42 -39
- data/lib/sequel/adapters/shared/db2.rb +5 -2
- data/lib/sequel/adapters/shared/mssql.rb +11 -5
- data/lib/sequel/adapters/shared/mysql.rb +2 -2
- data/lib/sequel/adapters/shared/postgres.rb +80 -92
- data/lib/sequel/adapters/shared/sqlanywhere.rb +0 -32
- data/lib/sequel/adapters/shared/sqlite.rb +8 -7
- data/lib/sequel/adapters/sqlite.rb +13 -9
- data/lib/sequel/adapters/trilogy.rb +2 -1
- data/lib/sequel/adapters/utils/emulate_offset_with_reverse_and_count.rb +1 -1
- data/lib/sequel/adapters/utils/mysql_mysql2.rb +11 -1
- data/lib/sequel/connection_pool/sharded_single.rb +1 -1
- data/lib/sequel/connection_pool/sharded_threaded.rb +7 -5
- data/lib/sequel/connection_pool/sharded_timed_queue.rb +3 -3
- data/lib/sequel/connection_pool/threaded.rb +9 -7
- data/lib/sequel/connection_pool/timed_queue.rb +2 -2
- data/lib/sequel/connection_pool.rb +3 -3
- data/lib/sequel/core.rb +44 -24
- data/lib/sequel/database/connecting.rb +1 -1
- data/lib/sequel/database/features.rb +1 -1
- data/lib/sequel/database/misc.rb +6 -11
- data/lib/sequel/database/query.rb +2 -2
- data/lib/sequel/database/schema_generator.rb +7 -5
- data/lib/sequel/database/schema_methods.rb +2 -2
- data/lib/sequel/database/transactions.rb +5 -7
- data/lib/sequel/dataset/actions.rb +2 -2
- data/lib/sequel/dataset/features.rb +4 -4
- data/lib/sequel/dataset/graph.rb +1 -1
- data/lib/sequel/dataset/misc.rb +3 -3
- data/lib/sequel/dataset/prepared_statements.rb +2 -2
- data/lib/sequel/dataset/query.rb +8 -8
- data/lib/sequel/dataset/sql.rb +32 -13
- data/lib/sequel/dataset.rb +2 -2
- data/lib/sequel/deprecated.rb +2 -2
- data/lib/sequel/exceptions.rb +2 -2
- data/lib/sequel/extensions/_pretty_table.rb +1 -1
- data/lib/sequel/extensions/async_thread_pool.rb +3 -3
- data/lib/sequel/extensions/auto_cast_date_and_time.rb +2 -2
- data/lib/sequel/extensions/blank.rb +2 -2
- data/lib/sequel/extensions/constraint_validations.rb +1 -1
- data/lib/sequel/extensions/core_refinements.rb +7 -10
- data/lib/sequel/extensions/date_arithmetic.rb +1 -1
- data/lib/sequel/extensions/datetime_parse_to_time.rb +2 -2
- data/lib/sequel/extensions/duplicate_columns_handler.rb +1 -3
- data/lib/sequel/extensions/graph_each.rb +1 -1
- data/lib/sequel/extensions/index_caching.rb +1 -1
- data/lib/sequel/extensions/inflector.rb +5 -5
- data/lib/sequel/extensions/is_distinct_from.rb +2 -2
- data/lib/sequel/extensions/lit_require_frozen.rb +20 -4
- data/lib/sequel/extensions/migration.rb +21 -7
- data/lib/sequel/extensions/named_timezones.rb +9 -9
- data/lib/sequel/extensions/pg_array.rb +10 -8
- data/lib/sequel/extensions/pg_array_ops.rb +69 -14
- data/lib/sequel/extensions/pg_auto_parameterize.rb +2 -2
- data/lib/sequel/extensions/pg_auto_parameterize_in_array.rb +3 -3
- data/lib/sequel/extensions/pg_enum.rb +2 -2
- data/lib/sequel/extensions/pg_extended_date_support.rb +5 -5
- data/lib/sequel/extensions/pg_extended_integer_support.rb +1 -1
- data/lib/sequel/extensions/pg_hstore.rb +2 -2
- data/lib/sequel/extensions/pg_hstore_ops.rb +5 -5
- data/lib/sequel/extensions/pg_inet.rb +2 -2
- data/lib/sequel/extensions/pg_inet_ops.rb +2 -2
- data/lib/sequel/extensions/pg_interval.rb +6 -6
- data/lib/sequel/extensions/pg_json.rb +4 -4
- data/lib/sequel/extensions/pg_json_ops.rb +15 -13
- data/lib/sequel/extensions/pg_range.rb +6 -6
- data/lib/sequel/extensions/pg_range_ops.rb +7 -7
- data/lib/sequel/extensions/pg_row.rb +4 -4
- data/lib/sequel/extensions/pg_row_ops.rb +6 -6
- data/lib/sequel/extensions/provenance.rb +2 -2
- data/lib/sequel/extensions/query.rb +2 -2
- data/lib/sequel/extensions/s.rb +6 -10
- data/lib/sequel/extensions/schema_dumper.rb +10 -6
- data/lib/sequel/extensions/sequel_4_dataset_methods.rb +2 -0
- data/lib/sequel/extensions/sql_comments.rb +1 -1
- data/lib/sequel/extensions/sql_log_normalizer.rb +1 -1
- data/lib/sequel/extensions/sqlite_json_ops.rb +2 -2
- data/lib/sequel/extensions/string_agg.rb +5 -5
- data/lib/sequel/extensions/symbol_aref.rb +12 -32
- data/lib/sequel/extensions/symbol_aref_refinement.rb +2 -5
- data/lib/sequel/extensions/symbol_as.rb +1 -2
- data/lib/sequel/extensions/symbol_as_refinement.rb +1 -5
- data/lib/sequel/extensions/transaction_connection_validator.rb +1 -1
- data/lib/sequel/model/associations.rb +17 -17
- data/lib/sequel/model/base.rb +18 -15
- data/lib/sequel/model/inflections.rb +1 -1
- data/lib/sequel/model/plugins.rb +2 -2
- data/lib/sequel/model.rb +2 -2
- data/lib/sequel/plugins/association_pks.rb +1 -1
- data/lib/sequel/plugins/association_proxies.rb +4 -4
- data/lib/sequel/plugins/auto_restrict_eager_graph.rb +2 -0
- data/lib/sequel/plugins/caching.rb +28 -3
- data/lib/sequel/plugins/class_table_inheritance.rb +1 -1
- data/lib/sequel/plugins/column_encryption.rb +10 -10
- data/lib/sequel/plugins/concurrent_eager_loading.rb +2 -2
- data/lib/sequel/plugins/csv_serializer.rb +9 -20
- data/lib/sequel/plugins/deprecated_associations.rb +2 -2
- data/lib/sequel/plugins/eager_each.rb +1 -1
- data/lib/sequel/plugins/finder.rb +1 -1
- data/lib/sequel/plugins/forbid_lazy_load.rb +3 -3
- data/lib/sequel/plugins/insert_conflict.rb +1 -1
- data/lib/sequel/plugins/insert_returning_select.rb +1 -1
- data/lib/sequel/plugins/instance_filters.rb +8 -0
- data/lib/sequel/plugins/instance_hooks.rb +19 -0
- data/lib/sequel/plugins/json_serializer.rb +4 -4
- data/lib/sequel/plugins/lazy_attributes.rb +1 -1
- data/lib/sequel/plugins/many_through_many.rb +1 -1
- data/lib/sequel/plugins/mssql_optimistic_locking.rb +9 -0
- data/lib/sequel/plugins/optimistic_locking.rb +12 -2
- data/lib/sequel/plugins/optimistic_locking_base.rb +14 -0
- data/lib/sequel/plugins/pg_array_associations.rb +4 -4
- data/lib/sequel/plugins/pg_auto_constraint_validations.rb +3 -3
- data/lib/sequel/plugins/pg_eager_any_typed_array.rb +2 -2
- data/lib/sequel/plugins/pg_xmin_optimistic_locking.rb +11 -2
- data/lib/sequel/plugins/prepared_statements.rb +2 -2
- data/lib/sequel/plugins/select_on_skipped_update.rb +63 -0
- data/lib/sequel/plugins/serialization.rb +1 -1
- data/lib/sequel/plugins/sharding.rb +1 -1
- data/lib/sequel/plugins/single_table_inheritance.rb +21 -3
- data/lib/sequel/plugins/skip_saving_columns.rb +2 -2
- data/lib/sequel/plugins/split_values.rb +1 -1
- data/lib/sequel/plugins/sql_comments.rb +8 -8
- data/lib/sequel/plugins/subclasses.rb +6 -6
- data/lib/sequel/plugins/subset_conditions.rb +5 -16
- data/lib/sequel/plugins/tactical_eager_loading.rb +1 -1
- data/lib/sequel/plugins/throw_failures.rb +3 -3
- data/lib/sequel/plugins/unused_associations.rb +5 -5
- data/lib/sequel/plugins/validate_associated.rb +7 -1
- data/lib/sequel/plugins/validate_associated_context.rb +52 -0
- data/lib/sequel/plugins/validation_helpers.rb +1 -1
- data/lib/sequel/plugins/xml_serializer.rb +2 -0
- data/lib/sequel/sql.rb +120 -116
- data/lib/sequel/version.rb +1 -1
- metadata +5 -3
data/lib/sequel/dataset/query.rb
CHANGED
|
@@ -98,7 +98,7 @@ module Sequel
|
|
|
98
98
|
c.freeze
|
|
99
99
|
end
|
|
100
100
|
else
|
|
101
|
-
# :
|
|
101
|
+
# simplecov:disable
|
|
102
102
|
def clone(opts = OPTS) # :nodoc:
|
|
103
103
|
c = super()
|
|
104
104
|
c.opts.merge!(opts)
|
|
@@ -108,7 +108,7 @@ module Sequel
|
|
|
108
108
|
c.opts.freeze
|
|
109
109
|
c
|
|
110
110
|
end
|
|
111
|
-
# :
|
|
111
|
+
# simplecov:enable
|
|
112
112
|
end
|
|
113
113
|
|
|
114
114
|
# Returns a copy of the dataset with the SQL DISTINCT clause. The DISTINCT
|
|
@@ -213,13 +213,13 @@ module Sequel
|
|
|
213
213
|
end
|
|
214
214
|
end
|
|
215
215
|
else
|
|
216
|
-
# :
|
|
216
|
+
# simplecov:disable
|
|
217
217
|
def extension(*exts) # :nodoc:
|
|
218
218
|
c = clone
|
|
219
219
|
c.send(:_extension!, exts)
|
|
220
220
|
c
|
|
221
221
|
end
|
|
222
|
-
# :
|
|
222
|
+
# simplecov:enable
|
|
223
223
|
end
|
|
224
224
|
|
|
225
225
|
# Alias for where.
|
|
@@ -1250,14 +1250,14 @@ module Sequel
|
|
|
1250
1250
|
o.freeze
|
|
1251
1251
|
end
|
|
1252
1252
|
else
|
|
1253
|
-
# :
|
|
1253
|
+
# simplecov:disable
|
|
1254
1254
|
def with_extend(*mods, &block) # :nodoc:
|
|
1255
1255
|
c = clone
|
|
1256
1256
|
c.extend(*mods) unless mods.empty?
|
|
1257
1257
|
c.extend(DatasetModule.new(&block)) if block
|
|
1258
1258
|
c
|
|
1259
1259
|
end
|
|
1260
|
-
# :
|
|
1260
|
+
# simplecov:enable
|
|
1261
1261
|
end
|
|
1262
1262
|
|
|
1263
1263
|
# Returns a cloned dataset with the given row_proc.
|
|
@@ -1354,7 +1354,7 @@ module Sequel
|
|
|
1354
1354
|
|
|
1355
1355
|
private
|
|
1356
1356
|
|
|
1357
|
-
# :
|
|
1357
|
+
# simplecov:disable
|
|
1358
1358
|
unless TRUE_FREEZE
|
|
1359
1359
|
# Load the extensions into the receiver, without checking if the receiver is frozen.
|
|
1360
1360
|
def _extension!(exts)
|
|
@@ -1373,7 +1373,7 @@ module Sequel
|
|
|
1373
1373
|
self
|
|
1374
1374
|
end
|
|
1375
1375
|
end
|
|
1376
|
-
# :
|
|
1376
|
+
# simplecov:enable
|
|
1377
1377
|
|
|
1378
1378
|
# A frozen array for the currently selected columns.
|
|
1379
1379
|
def _current_select(allow_plain_wildcard)
|
data/lib/sequel/dataset/sql.rb
CHANGED
|
@@ -1022,11 +1022,19 @@ module Sequel
|
|
|
1022
1022
|
# order if not. Also removes the row_proc, which isn't needed
|
|
1023
1023
|
# for aggregate calculations.
|
|
1024
1024
|
def aggregate_dataset
|
|
1025
|
-
(
|
|
1025
|
+
(aggregate_dataset_use_from_self? ? from_self : unordered).naked
|
|
1026
|
+
end
|
|
1027
|
+
|
|
1028
|
+
def aggreate_dataset_use_from_self? # :nodoc:
|
|
1029
|
+
# SEQUEL6: Remove
|
|
1030
|
+
# simplecov:disable
|
|
1031
|
+
Sequel::Deprecation.deprecate("Dataset#aggreate_dataset_use_from_self", "Use #aggregate_dataset_use_from_self? instead")
|
|
1032
|
+
aggregate_dataset_use_from_self?
|
|
1033
|
+
# simplecov:enable
|
|
1026
1034
|
end
|
|
1027
1035
|
|
|
1028
1036
|
# Whether to use from_self for an aggregate dataset.
|
|
1029
|
-
def
|
|
1037
|
+
def aggregate_dataset_use_from_self?
|
|
1030
1038
|
options_overlap(COUNT_FROM_SELF_OPTS)
|
|
1031
1039
|
end
|
|
1032
1040
|
|
|
@@ -1120,9 +1128,9 @@ module Sequel
|
|
|
1120
1128
|
# operators unsupported by some databases. Used by adapters for databases
|
|
1121
1129
|
# that don't support the operators natively.
|
|
1122
1130
|
def complex_expression_emulate_append(sql, op, args)
|
|
1123
|
-
# :
|
|
1131
|
+
# simplecov:disable
|
|
1124
1132
|
case op
|
|
1125
|
-
# :
|
|
1133
|
+
# simplecov:enable
|
|
1126
1134
|
when :%
|
|
1127
1135
|
complex_expression_arg_pairs_append(sql, args){|a, b| Sequel.function(:MOD, a, b)}
|
|
1128
1136
|
when :>>
|
|
@@ -1204,7 +1212,7 @@ module Sequel
|
|
|
1204
1212
|
end
|
|
1205
1213
|
end
|
|
1206
1214
|
|
|
1207
|
-
# Append literalization of array of grouping elements to SQL string,
|
|
1215
|
+
# Append literalization of array of grouping elements to SQL string, separating them with commas.
|
|
1208
1216
|
def grouping_element_list_append(sql, columns)
|
|
1209
1217
|
c = false
|
|
1210
1218
|
co = ', '
|
|
@@ -1229,7 +1237,7 @@ module Sequel
|
|
|
1229
1237
|
db.from_application_timestamp(v).strftime(default_timestamp_format)
|
|
1230
1238
|
end
|
|
1231
1239
|
|
|
1232
|
-
# :
|
|
1240
|
+
# simplecov:disable
|
|
1233
1241
|
|
|
1234
1242
|
# Return the SQL timestamp fragment to use for the fractional time part.
|
|
1235
1243
|
# Should start with the decimal point. Uses 6 decimal places by default.
|
|
@@ -1240,7 +1248,7 @@ module Sequel
|
|
|
1240
1248
|
end
|
|
1241
1249
|
sprintf(".%0#{ts}d", usec)
|
|
1242
1250
|
end
|
|
1243
|
-
# :
|
|
1251
|
+
# simplecov:enable
|
|
1244
1252
|
|
|
1245
1253
|
# Append literalization of identifier to SQL string, considering regular strings
|
|
1246
1254
|
# as SQL identifiers instead of SQL strings.
|
|
@@ -1338,10 +1346,21 @@ module Sequel
|
|
|
1338
1346
|
alias delete_returning_sql insert_returning_sql
|
|
1339
1347
|
alias update_returning_sql insert_returning_sql
|
|
1340
1348
|
|
|
1341
|
-
|
|
1342
|
-
|
|
1349
|
+
JOIN_TYPE_SQL = {}
|
|
1350
|
+
(CONDITIONED_JOIN_TYPES + UNCONDITIONED_JOIN_TYPES + %i[natural_inner natural_left_outer natural_right_outer natural_full_outer]).each do |join_type|
|
|
1351
|
+
JOIN_TYPE_SQL[join_type] = "#{join_type.to_s.tr('_', ' ').upcase} JOIN".freeze
|
|
1352
|
+
end
|
|
1353
|
+
JOIN_TYPE_SQL[nil] = "JOIN"
|
|
1354
|
+
JOIN_TYPE_SQL.freeze
|
|
1355
|
+
private_constant :JOIN_TYPE_SQL
|
|
1356
|
+
|
|
1357
|
+
# SQL fragment for join type
|
|
1343
1358
|
def join_type_sql(join_type)
|
|
1344
|
-
|
|
1359
|
+
JOIN_TYPE_SQL.fetch(join_type) do
|
|
1360
|
+
# SEQUEL6: Raise error
|
|
1361
|
+
Sequel::Deprecation.deprecate("Unrecognized join type used: #{join_type.inspect}. This will raise an error starting in Sequel 6.")
|
|
1362
|
+
"#{join_type.to_s.tr('_', ' ').upcase} JOIN"
|
|
1363
|
+
end
|
|
1345
1364
|
end
|
|
1346
1365
|
|
|
1347
1366
|
# Append USING clause for JOIN USING
|
|
@@ -1372,7 +1391,7 @@ module Sequel
|
|
|
1372
1391
|
literal_string_append(sql, v)
|
|
1373
1392
|
end
|
|
1374
1393
|
|
|
1375
|
-
# Append literalization of dataset to SQL string. Does a subselect inside
|
|
1394
|
+
# Append literalization of dataset to SQL string. Does a subselect inside parentheses.
|
|
1376
1395
|
def literal_dataset_append(sql, v)
|
|
1377
1396
|
sql << 'LATERAL ' if v.opts[:lateral]
|
|
1378
1397
|
sql << '('
|
|
@@ -1438,7 +1457,7 @@ module Sequel
|
|
|
1438
1457
|
# Append a literalization of the object to the given SQL string.
|
|
1439
1458
|
# Calls +sql_literal_append+ if object responds to it, otherwise
|
|
1440
1459
|
# calls +sql_literal+ if object responds to it, otherwise raises an error.
|
|
1441
|
-
# If a database specific type is allowed, this should be
|
|
1460
|
+
# If a database specific type is allowed, this should be overridden in a subclass.
|
|
1442
1461
|
def literal_other_append(sql, v)
|
|
1443
1462
|
if v.respond_to?(:sql_literal_append)
|
|
1444
1463
|
v.sql_literal_append(self, sql)
|
|
@@ -1559,7 +1578,7 @@ module Sequel
|
|
|
1559
1578
|
end
|
|
1560
1579
|
|
|
1561
1580
|
# Modify the sql to add a dataset to the via an EXCEPT, INTERSECT, or UNION clause.
|
|
1562
|
-
# This uses a subselect for the compound datasets used, because using
|
|
1581
|
+
# This uses a subselect for the compound datasets used, because using parentheses doesn't
|
|
1563
1582
|
# work on all databases.
|
|
1564
1583
|
def select_compounds_sql(sql)
|
|
1565
1584
|
return unless c = @opts[:compounds]
|
data/lib/sequel/dataset.rb
CHANGED
|
@@ -54,7 +54,7 @@ module Sequel
|
|
|
54
54
|
require_relative "dataset/placeholder_literalizer"
|
|
55
55
|
require_relative "dataset/dataset_module"
|
|
56
56
|
|
|
57
|
-
# :
|
|
57
|
+
# simplecov:disable
|
|
58
58
|
require_relative "dataset/deprecated_singleton_class_methods" if Dataset::TRUE_FREEZE
|
|
59
|
-
# :
|
|
59
|
+
# simplecov:enable
|
|
60
60
|
end
|
data/lib/sequel/deprecated.rb
CHANGED
|
@@ -60,9 +60,9 @@ module Sequel
|
|
|
60
60
|
# If using ruby 2.3+, use Module#deprecate_constant to deprecate the constant,
|
|
61
61
|
# otherwise do nothing as the ruby implementation does not support constant deprecation.
|
|
62
62
|
def self.deprecate_constant(mod, constant)
|
|
63
|
-
# :
|
|
63
|
+
# simplecov:disable
|
|
64
64
|
if RUBY_VERSION > '2.3'
|
|
65
|
-
# :
|
|
65
|
+
# simplecov:enable
|
|
66
66
|
mod.deprecate_constant(constant)
|
|
67
67
|
end
|
|
68
68
|
end
|
data/lib/sequel/exceptions.rb
CHANGED
|
@@ -8,9 +8,9 @@ module Sequel
|
|
|
8
8
|
# exception is held here.
|
|
9
9
|
attr_accessor :wrapped_exception
|
|
10
10
|
|
|
11
|
-
# :
|
|
11
|
+
# simplecov:disable
|
|
12
12
|
if RUBY_VERSION >= '2.1'
|
|
13
|
-
# :
|
|
13
|
+
# simplecov:enable
|
|
14
14
|
# Returned the wrapped exception if one exists, otherwise use
|
|
15
15
|
# ruby's default behavior.
|
|
16
16
|
def cause
|
|
@@ -74,7 +74,7 @@ module Sequel
|
|
|
74
74
|
String.new << '|' << columns.map {|c| "%-#{sizes[c]}s" % c.to_s}.join('|') << '|'
|
|
75
75
|
end
|
|
76
76
|
|
|
77
|
-
# String for
|
|
77
|
+
# String for separator line
|
|
78
78
|
def self.separator_line(columns, sizes) # :nodoc:
|
|
79
79
|
String.new << '+' << columns.map {|c| '-' * sizes[c]}.join('+') << '+'
|
|
80
80
|
end
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
#
|
|
79
79
|
# # ...
|
|
80
80
|
# if result
|
|
81
|
-
# # will always execute this
|
|
81
|
+
# # will always execute this branch, since result is a proxy object
|
|
82
82
|
# end
|
|
83
83
|
#
|
|
84
84
|
# In this case, you can call the +__value+ method to return the actual
|
|
@@ -244,9 +244,9 @@ module Sequel
|
|
|
244
244
|
def method_missing(*args, &block)
|
|
245
245
|
__value.public_send(*args, &block)
|
|
246
246
|
end
|
|
247
|
-
# :
|
|
247
|
+
# simplecov:disable
|
|
248
248
|
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
|
|
249
|
-
# :
|
|
249
|
+
# simplecov:enable
|
|
250
250
|
|
|
251
251
|
# Delegate respond_to? calls to the returned result.
|
|
252
252
|
def respond_to_missing?(*args)
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
#
|
|
46
46
|
module Sequel
|
|
47
47
|
module AutoCastDateAndTime
|
|
48
|
-
# :
|
|
48
|
+
# simplecov:disable
|
|
49
49
|
|
|
50
50
|
# Mark the datasets as requiring sql standard date times. This is only needed
|
|
51
51
|
# for backwards compatibility.
|
|
@@ -53,7 +53,7 @@ module Sequel
|
|
|
53
53
|
# SEQUEL6: Remove
|
|
54
54
|
true
|
|
55
55
|
end
|
|
56
|
-
# :
|
|
56
|
+
# simplecov:enable
|
|
57
57
|
|
|
58
58
|
private
|
|
59
59
|
|
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
# Sequel.extension :blank
|
|
8
8
|
|
|
9
9
|
[FalseClass, Object, NilClass, Numeric, String, TrueClass].each do |klass|
|
|
10
|
-
# :
|
|
10
|
+
# simplecov:disable
|
|
11
11
|
if klass.method_defined?(:blank?)
|
|
12
12
|
klass.send(:alias_method, :blank?, :blank?)
|
|
13
13
|
end
|
|
14
|
-
# :
|
|
14
|
+
# simplecov:enable
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
class FalseClass
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
# integers, and a range of integers.
|
|
96
96
|
# * There are like and ilike validations, which are similar to the format
|
|
97
97
|
# validation but use a case sensitive or case insensitive LIKE pattern. LIKE
|
|
98
|
-
#
|
|
98
|
+
# patterns are very simple, so many regexp patterns cannot be expressed by
|
|
99
99
|
# them, but only a couple databases (PostgreSQL and MySQL) support regexp
|
|
100
100
|
# patterns.
|
|
101
101
|
# * The operator validation only supports >, >=, <, and <= operators, and the
|
|
@@ -10,14 +10,11 @@
|
|
|
10
10
|
#
|
|
11
11
|
# using Sequel::CoreRefinements
|
|
12
12
|
|
|
13
|
-
#
|
|
14
|
-
raise(Sequel::Error, "Refinements require ruby 2.0.0 or greater") unless RUBY_VERSION >= '2.0.0'
|
|
15
|
-
# :nocov:
|
|
16
|
-
|
|
13
|
+
#
|
|
17
14
|
module Sequel::CoreRefinements
|
|
18
|
-
# :
|
|
15
|
+
# simplecov:disable
|
|
19
16
|
include_meth = RUBY_VERSION >= '3.1' ? :import_methods : :include
|
|
20
|
-
# :
|
|
17
|
+
# simplecov:enable
|
|
21
18
|
INCLUDE_METH = include_meth
|
|
22
19
|
private_constant :INCLUDE_METH
|
|
23
20
|
|
|
@@ -201,16 +198,16 @@ module Sequel::CoreRefinements
|
|
|
201
198
|
send include_meth, Sequel::SQL::BooleanMethods
|
|
202
199
|
send include_meth, Sequel::SQL::NumericMethods
|
|
203
200
|
|
|
204
|
-
# :
|
|
201
|
+
# simplecov:disable
|
|
205
202
|
remove_method :* if RUBY_VERSION >= '3.1'
|
|
206
|
-
# :
|
|
203
|
+
# simplecov:enable
|
|
207
204
|
|
|
208
205
|
send include_meth, Sequel::SQL::QualifyingMethods
|
|
209
206
|
send include_meth, Sequel::SQL::StringMethods
|
|
210
207
|
send include_meth, Sequel::SQL::SubscriptMethods
|
|
211
208
|
send include_meth, Sequel::SQL::ComplexExpressionMethods
|
|
212
209
|
|
|
213
|
-
# :
|
|
210
|
+
# simplecov:disable
|
|
214
211
|
if RUBY_VERSION >= '3.1'
|
|
215
212
|
remove_method :*
|
|
216
213
|
def *(ce=(arg=false;nil))
|
|
@@ -222,7 +219,7 @@ module Sequel::CoreRefinements
|
|
|
222
219
|
end
|
|
223
220
|
|
|
224
221
|
end
|
|
225
|
-
# :
|
|
222
|
+
# simplecov:enable
|
|
226
223
|
|
|
227
224
|
# Returns receiver wrapped in an <tt>Sequel::SQL::Identifier</tt>.
|
|
228
225
|
#
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen-string-literal: true
|
|
2
2
|
#
|
|
3
3
|
# The date_arithmetic extension adds the ability to perform database-independent
|
|
4
|
-
# addition/
|
|
4
|
+
# addition/subtraction of intervals to/from dates and timestamps.
|
|
5
5
|
#
|
|
6
6
|
# First, you need to load the extension into the database:
|
|
7
7
|
#
|
|
@@ -20,10 +20,10 @@ module Sequel::DateTimeParseToTime
|
|
|
20
20
|
# be in UTC and there is no offset information in the string.
|
|
21
21
|
def convert_input_timestamp(v, input_timezone)
|
|
22
22
|
if v.is_a?(String) && datetime_class == Time && input_timezone == :utc && !_date_parse(v).has_key?(:offset)
|
|
23
|
-
# :
|
|
23
|
+
# simplecov:disable
|
|
24
24
|
# Whether this is fully branch covered depends on the order in which the specs are run.
|
|
25
25
|
v = handle_date_parse_input(v) if respond_to?(:handle_date_parse_input, true)
|
|
26
|
-
# :
|
|
26
|
+
# simplecov:enable
|
|
27
27
|
t = DateTime.parse(v).to_time
|
|
28
28
|
case application_timezone
|
|
29
29
|
when nil, :local
|
|
@@ -40,9 +40,7 @@
|
|
|
40
40
|
|
|
41
41
|
module Sequel
|
|
42
42
|
module DuplicateColumnsHandler
|
|
43
|
-
|
|
44
|
-
CALLER_ARGS = (RUBY_VERSION >= '2.0' ? [0,1] : [0]).freeze
|
|
45
|
-
# :nocov:
|
|
43
|
+
CALLER_ARGS = [0,1].freeze
|
|
46
44
|
|
|
47
45
|
# Customize handling of duplicate columns for this dataset.
|
|
48
46
|
def on_duplicate_columns(handler = (raise Error, "Must provide either an argument or a block to on_duplicate_columns" unless defined?(yield); nil), &block)
|
|
@@ -43,7 +43,7 @@ module Sequel
|
|
|
43
43
|
private
|
|
44
44
|
|
|
45
45
|
# Fetch the rows, split them into component table parts,
|
|
46
|
-
#
|
|
46
|
+
# transform and run the row_proc on each part (if applicable),
|
|
47
47
|
# and yield a hash of the parts.
|
|
48
48
|
def graph_each(sql=select_sql)
|
|
49
49
|
# Reject tables with nil datasets, as they are excluded from
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
#
|
|
15
15
|
# # load model files
|
|
16
16
|
#
|
|
17
|
-
# Then, whenever database
|
|
17
|
+
# Then, whenever database indices are modified, write a new cached
|
|
18
18
|
# file. You can do that with <tt>bin/sequel</tt>'s -X option:
|
|
19
19
|
#
|
|
20
20
|
# bin/sequel -X /path/to/index_cache.dump postgres://...
|
|
@@ -31,7 +31,7 @@ class String
|
|
|
31
31
|
@plurals, @singulars, @uncountables = [], [], []
|
|
32
32
|
|
|
33
33
|
class << self
|
|
34
|
-
# Array of 2 element arrays, first containing a regex, and the second containing a substitution pattern, used for
|
|
34
|
+
# Array of 2 element arrays, first containing a regex, and the second containing a substitution pattern, used for pluralization.
|
|
35
35
|
attr_reader :plurals
|
|
36
36
|
|
|
37
37
|
# Array of 2 element arrays, first containing a regex, and the second containing a substitution pattern, used for singularization.
|
|
@@ -107,11 +107,11 @@ class String
|
|
|
107
107
|
end
|
|
108
108
|
|
|
109
109
|
%w'classify constantize dasherize demodulize foreign_key humanize pluralize singularize tableize underscore'.each do |m|
|
|
110
|
-
# :
|
|
110
|
+
# simplecov:disable
|
|
111
111
|
if method_defined?(m)
|
|
112
112
|
alias_method(m, m)
|
|
113
113
|
end
|
|
114
|
-
# :
|
|
114
|
+
# simplecov:enable
|
|
115
115
|
end
|
|
116
116
|
|
|
117
117
|
# By default, camelize converts the string to UpperCamelCase. If the argument to camelize
|
|
@@ -212,8 +212,8 @@ class String
|
|
|
212
212
|
# Examples
|
|
213
213
|
# "posts".singularize #=> "post"
|
|
214
214
|
# "octopi".singularize #=> "octopus"
|
|
215
|
-
# "sheep".
|
|
216
|
-
# "word".
|
|
215
|
+
# "sheep".singularize #=> "sheep"
|
|
216
|
+
# "word".singularize #=> "word"
|
|
217
217
|
# "the blue mailmen".singularize #=> "the blue mailman"
|
|
218
218
|
# "CamelOctopi".singularize #=> "CamelOctopus"
|
|
219
219
|
def singularize
|
|
@@ -124,7 +124,7 @@ module Sequel
|
|
|
124
124
|
Dataset.register_extension(:is_distinct_from, SQL::IsDistinctFrom::DatasetMethods)
|
|
125
125
|
end
|
|
126
126
|
|
|
127
|
-
# :
|
|
127
|
+
# simplecov:disable
|
|
128
128
|
if Sequel.core_extensions?
|
|
129
129
|
class Symbol
|
|
130
130
|
include Sequel::SQL::IsDistinctFrom::Methods
|
|
@@ -138,4 +138,4 @@ if defined?(Sequel::CoreRefinements)
|
|
|
138
138
|
end
|
|
139
139
|
end
|
|
140
140
|
end
|
|
141
|
-
# :
|
|
141
|
+
# simplecov:enable
|
|
@@ -46,16 +46,16 @@ module Sequel
|
|
|
46
46
|
class LiteralString
|
|
47
47
|
# The string used when creating the literal string (first argument to
|
|
48
48
|
# Sequel::LiteralString.new). This may be nil if no string was provided,
|
|
49
|
-
# or if the
|
|
49
|
+
# or if the literal string was created before this extension was required.
|
|
50
50
|
attr_reader :source
|
|
51
51
|
|
|
52
52
|
def initialize(*a)
|
|
53
53
|
@source = a.first
|
|
54
54
|
super
|
|
55
55
|
end
|
|
56
|
-
# :
|
|
56
|
+
# simplecov:disable
|
|
57
57
|
ruby2_keywords :initialize if respond_to?(:ruby2_keywords, true)
|
|
58
|
-
# :
|
|
58
|
+
# simplecov:enable
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
module LitRequireFrozen
|
|
@@ -63,6 +63,20 @@ module Sequel
|
|
|
63
63
|
class Error < Sequel::Error
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
+
module BooleanExpressionClassMethods
|
|
67
|
+
private
|
|
68
|
+
|
|
69
|
+
# Do not freeze literal strings in value pairs, so they don't skip
|
|
70
|
+
# the frozen checks.
|
|
71
|
+
def from_value_pair(l, r)
|
|
72
|
+
if LiteralString === r
|
|
73
|
+
new(:'=', l, r)
|
|
74
|
+
else
|
|
75
|
+
super
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
66
80
|
module DatabaseMethods
|
|
67
81
|
def self.extended(db)
|
|
68
82
|
db.extend_datasets(DatasetMethods)
|
|
@@ -105,7 +119,7 @@ module Sequel
|
|
|
105
119
|
def _check_unfrozen_literal_string(str)
|
|
106
120
|
return if !str.is_a?(String) || str.frozen?
|
|
107
121
|
|
|
108
|
-
if str.is_a?(LiteralString)
|
|
122
|
+
if str.is_a?(LiteralString) && str == str.source
|
|
109
123
|
_check_unfrozen_literal_string(str.source)
|
|
110
124
|
else
|
|
111
125
|
raise Error, "cannot treat unfrozen string as literal SQL: #{str.inspect}"
|
|
@@ -126,6 +140,8 @@ module Sequel
|
|
|
126
140
|
end
|
|
127
141
|
end
|
|
128
142
|
|
|
143
|
+
SQL::BooleanExpression.extend(LitRequireFrozen::BooleanExpressionClassMethods)
|
|
144
|
+
|
|
129
145
|
Dataset.register_extension(:lit_require_frozen, LitRequireFrozen::DatasetMethods)
|
|
130
146
|
Database.register_extension(:lit_require_frozen, LitRequireFrozen::DatabaseMethods)
|
|
131
147
|
end
|
|
@@ -68,9 +68,9 @@ module Sequel
|
|
|
68
68
|
# Allow calling private methods for backwards compatibility
|
|
69
69
|
@db.send(method_sym, *args, &block)
|
|
70
70
|
end
|
|
71
|
-
# :
|
|
71
|
+
# simplecov:disable
|
|
72
72
|
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
|
|
73
|
-
# :
|
|
73
|
+
# simplecov:enable
|
|
74
74
|
|
|
75
75
|
# This object responds to all methods the database responds to.
|
|
76
76
|
def respond_to_missing?(meth, include_private)
|
|
@@ -410,6 +410,11 @@ module Sequel
|
|
|
410
410
|
private_constant :MIGRATION_ADVISORY_LOCK_ID
|
|
411
411
|
|
|
412
412
|
# Migrates the supplied database using the migration files in the specified directory. Options:
|
|
413
|
+
# :allow_migration_number :: Set to check each migration number. If set, calls the
|
|
414
|
+
# <tt>===</tt> method on the object with the migration number,
|
|
415
|
+
# allowing it to work with both ranges and procs. If the
|
|
416
|
+
# <tt>===</tt> method returns false, an exception is raised
|
|
417
|
+
# (TimestampMigrator only).
|
|
413
418
|
# :allow_missing_migration_files :: Don't raise an error if there are missing migration files.
|
|
414
419
|
# It is very risky to use this option, since it can result in
|
|
415
420
|
# the database schema version number not matching the expected
|
|
@@ -699,6 +704,7 @@ module Sequel
|
|
|
699
704
|
|
|
700
705
|
# Set up all state for the migrator instance
|
|
701
706
|
def initialize(db, directory, opts=OPTS)
|
|
707
|
+
@allow_migration_number = opts[:allow_migration_number]
|
|
702
708
|
super
|
|
703
709
|
@target = opts[:target]
|
|
704
710
|
@applied_migrations = get_applied_migrations
|
|
@@ -788,20 +794,28 @@ module Sequel
|
|
|
788
794
|
# Returns any migration files found in the migrator's directory.
|
|
789
795
|
def get_migration_files
|
|
790
796
|
files = []
|
|
797
|
+
allow_migration_number = @allow_migration_number
|
|
798
|
+
|
|
791
799
|
Dir.new(directory).each do |file|
|
|
792
800
|
next unless MIGRATION_FILE_PATTERN.match(file)
|
|
793
801
|
files << File.join(directory, file)
|
|
794
802
|
end
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
803
|
+
|
|
804
|
+
files.map! do |f|
|
|
805
|
+
ver, = split = split_migration_filename(f)
|
|
806
|
+
if allow_migration_number && !(allow_migration_number === ver)
|
|
807
|
+
raise Error, "Migration filename uses version number that is not allowed: #{f}"
|
|
808
|
+
end
|
|
809
|
+
[f, *split]
|
|
810
|
+
end.sort! do |a, b|
|
|
811
|
+
_, a_ver, a_name = a
|
|
812
|
+
_, b_ver, b_name = b
|
|
798
813
|
x = a_ver <=> b_ver
|
|
799
814
|
if x.zero?
|
|
800
815
|
x = a_name <=> b_name
|
|
801
816
|
end
|
|
802
817
|
x
|
|
803
|
-
end
|
|
804
|
-
files
|
|
818
|
+
end.map!(&:first)
|
|
805
819
|
end
|
|
806
820
|
|
|
807
821
|
# Return an integer and name (without extension) for the given path.
|
|
@@ -69,7 +69,7 @@ module Sequel
|
|
|
69
69
|
|
|
70
70
|
if RUBY_VERSION >= '2.6'
|
|
71
71
|
# Whether Time.at with :nsec and :in is broken. True on JRuby < 9.3.9.0.
|
|
72
|
-
BROKEN_TIME_AT_WITH_NSEC = defined?(JRUBY_VERSION) && (JRUBY_VERSION < '9.3' || (JRUBY_VERSION < '9.4' && JRUBY_VERSION.split('.')[2].to_i < 9))
|
|
72
|
+
BROKEN_TIME_AT_WITH_NSEC = defined?(JRUBY_VERSION) && (JRUBY_VERSION.to_r < Rational('9.3') || (JRUBY_VERSION.to_r < Rational('9.4') && JRUBY_VERSION.split('.')[2].to_i < 9))
|
|
73
73
|
private_constant :BROKEN_TIME_AT_WITH_NSEC
|
|
74
74
|
|
|
75
75
|
# Convert the given input Time (which must be in UTC) to the given input timezone,
|
|
@@ -80,10 +80,10 @@ module Sequel
|
|
|
80
80
|
raise unless disamb = tzinfo_disambiguator_for(v)
|
|
81
81
|
period = input_timezone.period_for_local(v, &disamb)
|
|
82
82
|
offset = period.utc_total_offset
|
|
83
|
-
# :
|
|
83
|
+
# simplecov:disable
|
|
84
84
|
if BROKEN_TIME_AT_WITH_NSEC
|
|
85
85
|
Time.at(v.to_i - offset, :in => input_timezone) + v.nsec/1000000000.0
|
|
86
|
-
# :
|
|
86
|
+
# simplecov:enable
|
|
87
87
|
else
|
|
88
88
|
Time.at(v.to_i - offset, v.nsec, :nsec, :in => input_timezone)
|
|
89
89
|
end
|
|
@@ -92,16 +92,16 @@ module Sequel
|
|
|
92
92
|
# Convert the given input Time to the given output timezone,
|
|
93
93
|
# which should be a TZInfo::Timezone instance.
|
|
94
94
|
def convert_output_time_other(v, output_timezone)
|
|
95
|
-
# :
|
|
95
|
+
# simplecov:disable
|
|
96
96
|
if BROKEN_TIME_AT_WITH_NSEC
|
|
97
97
|
Time.at(v.to_i, :in => output_timezone) + v.nsec/1000000000.0
|
|
98
|
-
# :
|
|
98
|
+
# simplecov:enable
|
|
99
99
|
else
|
|
100
100
|
Time.at(v.to_i, v.nsec, :nsec, :in => output_timezone)
|
|
101
101
|
end
|
|
102
102
|
end
|
|
103
103
|
# :nodoc:
|
|
104
|
-
# :
|
|
104
|
+
# simplecov:disable
|
|
105
105
|
else
|
|
106
106
|
def convert_input_time_other(v, input_timezone)
|
|
107
107
|
local_offset = input_timezone.period_for_local(v, &tzinfo_disambiguator_for(v)).utc_total_offset
|
|
@@ -122,7 +122,7 @@ module Sequel
|
|
|
122
122
|
end
|
|
123
123
|
end
|
|
124
124
|
# :nodoc:
|
|
125
|
-
# :
|
|
125
|
+
# simplecov:enable
|
|
126
126
|
end
|
|
127
127
|
|
|
128
128
|
# Handle both TZInfo 1 and TZInfo 2
|
|
@@ -139,7 +139,7 @@ module Sequel
|
|
|
139
139
|
DateTime.civil(v.year, v.month, v.day, v.hour, v.minute, v.second + v.sec_fraction, v.offset, v.start)
|
|
140
140
|
end
|
|
141
141
|
# :nodoc:
|
|
142
|
-
# :
|
|
142
|
+
# simplecov:disable
|
|
143
143
|
else
|
|
144
144
|
# Assume the given DateTime has a correct time but a wrong timezone. It is
|
|
145
145
|
# currently in UTC timezone, but it should be converted to the input_timezone.
|
|
@@ -161,7 +161,7 @@ module Sequel
|
|
|
161
161
|
(v - local_offset).new_offset(local_offset)
|
|
162
162
|
end
|
|
163
163
|
# :nodoc:
|
|
164
|
-
# :
|
|
164
|
+
# simplecov:enable
|
|
165
165
|
end
|
|
166
166
|
|
|
167
167
|
# Returns TZInfo::Timezone instance if given a String.
|