sequel 5.107.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 -1028
- data/lib/sequel/adapters/shared/sqlanywhere.rb +0 -32
- data/lib/sequel/adapters/shared/sqlite.rb +3 -3
- 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 +4 -4
- 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
|
@@ -305,38 +305,6 @@ module Sequel
|
|
|
305
305
|
super(sql, :+, args)
|
|
306
306
|
when :<<, :>>
|
|
307
307
|
complex_expression_emulate_append(sql, op, args)
|
|
308
|
-
when :LIKE, :"NOT LIKE"
|
|
309
|
-
sql << '('
|
|
310
|
-
literal_append(sql, args[0])
|
|
311
|
-
sql << (op == :LIKE ? ' REGEXP ' : ' NOT REGEXP ')
|
|
312
|
-
pattern = String.new
|
|
313
|
-
last_c = ''
|
|
314
|
-
args[1].each_char do |c|
|
|
315
|
-
if c == '_' and not pattern.end_with?('\\') and last_c != '\\'
|
|
316
|
-
pattern << '.'
|
|
317
|
-
elsif c == '%' and not pattern.end_with?('\\') and last_c != '\\'
|
|
318
|
-
pattern << '.*'
|
|
319
|
-
elsif c == '[' and not pattern.end_with?('\\') and last_c != '\\'
|
|
320
|
-
pattern << '\['
|
|
321
|
-
elsif c == ']' and not pattern.end_with?('\\') and last_c != '\\'
|
|
322
|
-
pattern << '\]'
|
|
323
|
-
elsif c == '*' and not pattern.end_with?('\\') and last_c != '\\'
|
|
324
|
-
pattern << '\*'
|
|
325
|
-
elsif c == '?' and not pattern.end_with?('\\') and last_c != '\\'
|
|
326
|
-
pattern << '\?'
|
|
327
|
-
else
|
|
328
|
-
pattern << c
|
|
329
|
-
end
|
|
330
|
-
if c == '\\' and last_c == '\\'
|
|
331
|
-
last_c = ''
|
|
332
|
-
else
|
|
333
|
-
last_c = c
|
|
334
|
-
end
|
|
335
|
-
end
|
|
336
|
-
literal_append(sql, pattern)
|
|
337
|
-
sql << " ESCAPE "
|
|
338
|
-
literal_append(sql, "\\")
|
|
339
|
-
sql << ')'
|
|
340
308
|
when :ILIKE, :"NOT ILIKE"
|
|
341
309
|
super(sql, (op == :ILIKE ? :LIKE : :"NOT LIKE"), args)
|
|
342
310
|
when :extract
|
|
@@ -210,7 +210,7 @@ module Sequel
|
|
|
210
210
|
if ops.length > 1 && ops.all?{|op| op[:op] == :add_constraint || op[:op] == :set_column_null}
|
|
211
211
|
null_ops, ops = ops.partition{|op| op[:op] == :set_column_null}
|
|
212
212
|
|
|
213
|
-
# Apply NULL/NOT NULL ops first, since those should be purely
|
|
213
|
+
# Apply NULL/NOT NULL ops first, since those should be purely independent of the constraints.
|
|
214
214
|
null_ops.each{|op| alter_table_sql_list(table, [op]).flatten.each{|sql| execute_ddl(sql)}}
|
|
215
215
|
|
|
216
216
|
# If you are just doing constraints, apply all of them at the same time,
|
|
@@ -730,7 +730,7 @@ module Sequel
|
|
|
730
730
|
|
|
731
731
|
# Handle uniqueness violations when inserting, by using a specified
|
|
732
732
|
# resolution algorithm. With no options, uses INSERT OR REPLACE. SQLite
|
|
733
|
-
# supports the following conflict resolution
|
|
733
|
+
# supports the following conflict resolution algorithms: ROLLBACK, ABORT,
|
|
734
734
|
# FAIL, IGNORE and REPLACE.
|
|
735
735
|
#
|
|
736
736
|
# On SQLite 3.24.0+, you can pass a hash to use an ON CONFLICT clause.
|
|
@@ -892,7 +892,7 @@ module Sequel
|
|
|
892
892
|
end
|
|
893
893
|
|
|
894
894
|
# Use from_self for aggregate dataset using VALUES.
|
|
895
|
-
def
|
|
895
|
+
def aggregate_dataset_use_from_self?
|
|
896
896
|
super || @opts[:values]
|
|
897
897
|
end
|
|
898
898
|
|
|
@@ -336,16 +336,20 @@ module Sequel
|
|
|
336
336
|
log_sql << sql
|
|
337
337
|
log_sql << ")"
|
|
338
338
|
end
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
339
|
+
begin
|
|
340
|
+
if block
|
|
341
|
+
log_connection_yield(log_sql, conn, args){cps.execute(ps_args, &block)}
|
|
342
|
+
else
|
|
343
|
+
log_connection_yield(log_sql, conn, args){cps.execute!(ps_args){|r|}}
|
|
344
|
+
case type
|
|
345
|
+
when :insert
|
|
346
|
+
conn.last_insert_row_id
|
|
347
|
+
when :update
|
|
348
|
+
conn.changes
|
|
349
|
+
end
|
|
348
350
|
end
|
|
351
|
+
ensure
|
|
352
|
+
cps.clear_bindings!
|
|
349
353
|
end
|
|
350
354
|
end
|
|
351
355
|
|
|
@@ -49,7 +49,7 @@ module Sequel
|
|
|
49
49
|
else
|
|
50
50
|
# Sequel doesn't allow a nonpositive limit. If the offset
|
|
51
51
|
# is greater than the number of rows, the empty result set
|
|
52
|
-
#
|
|
52
|
+
# should be returned, so use a condition that is always false.
|
|
53
53
|
ds.where(1=>0)
|
|
54
54
|
end
|
|
55
55
|
sql = @opts[:append_sql] || String.new
|
|
@@ -22,7 +22,17 @@ module Sequel
|
|
|
22
22
|
END
|
|
23
23
|
# Error messages for mysql and mysql2 that indicate the current connection should be disconnected
|
|
24
24
|
MYSQL_DATABASE_DISCONNECT_ERRORS = /\A#{Regexp.union(disconnect_errors)}/
|
|
25
|
-
|
|
25
|
+
|
|
26
|
+
# 2027 (CR_MALFORMED_PACKET) deliberately not included (protocol error, not connection error)
|
|
27
|
+
MYSQL_DISCONNECT_ERROR_CODES = [
|
|
28
|
+
2002, # CR_CONNECTION_ERROR
|
|
29
|
+
2006, # CR_SERVER_GONE_ERROR
|
|
30
|
+
2013, # CR_SERVER_LOST
|
|
31
|
+
2014, # CR_COMMANDS_OUT_OF_SYNC
|
|
32
|
+
2055, # CR_SERVER_LOST_EXTENDED
|
|
33
|
+
].freeze
|
|
34
|
+
private_constant :MYSQL_DISCONNECT_ERROR_CODES
|
|
35
|
+
|
|
26
36
|
# Support stored procedures on MySQL
|
|
27
37
|
def call_sproc(name, opts=OPTS, &block)
|
|
28
38
|
args = opts[:args] || []
|
|
@@ -38,7 +38,7 @@ class Sequel::ShardedSingleConnectionPool < Sequel::ConnectionPool
|
|
|
38
38
|
|
|
39
39
|
# Disconnects from the database. Once a connection is requested using
|
|
40
40
|
# #hold, the connection is reestablished. Options:
|
|
41
|
-
# :server :: Should be a symbol
|
|
41
|
+
# :server :: Should be a symbol specifying the server to disconnect from,
|
|
42
42
|
# or an array of symbols to specify multiple servers.
|
|
43
43
|
def disconnect(opts=OPTS)
|
|
44
44
|
(opts[:server] ? Array(opts[:server]) : servers).each do |s|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen-string-literal: true
|
|
2
2
|
|
|
3
|
+
# SEQUEL6: Remove, deprecation: add warning if used on Ruby 3.2+
|
|
4
|
+
|
|
3
5
|
require_relative 'threaded'
|
|
4
6
|
|
|
5
7
|
# The slowest and most advanced connection pool, dealing with both multi-threaded
|
|
@@ -95,7 +97,7 @@ class Sequel::ShardedThreadedConnectionPool < Sequel::ThreadedConnectionPool
|
|
|
95
97
|
#
|
|
96
98
|
# Once a connection is requested using #hold, the connection pool
|
|
97
99
|
# creates new connections to the database. Options:
|
|
98
|
-
# :server :: Should be a symbol
|
|
100
|
+
# :server :: Should be a symbol specifying the server to disconnect from,
|
|
99
101
|
# or an array of symbols to specify multiple servers.
|
|
100
102
|
def disconnect(opts=OPTS)
|
|
101
103
|
(opts[:server] ? Array(opts[:server]) : sync{@servers.keys}).each do |s|
|
|
@@ -203,7 +205,7 @@ class Sequel::ShardedThreadedConnectionPool < Sequel::ThreadedConnectionPool
|
|
|
203
205
|
|
|
204
206
|
until conn = assign_connection(thread, server)
|
|
205
207
|
elapsed = Sequel.elapsed_seconds_since(timer)
|
|
206
|
-
# :
|
|
208
|
+
# simplecov:disable
|
|
207
209
|
raise_pool_timeout(elapsed, server) if elapsed > timeout
|
|
208
210
|
|
|
209
211
|
# It's difficult to get to this point, it can only happen if there is a race condition
|
|
@@ -211,7 +213,7 @@ class Sequel::ShardedThreadedConnectionPool < Sequel::ThreadedConnectionPool
|
|
|
211
213
|
if conn = acquire_available(thread, server, timeout - elapsed)
|
|
212
214
|
return conn
|
|
213
215
|
end
|
|
214
|
-
# :
|
|
216
|
+
# simplecov:enable
|
|
215
217
|
end
|
|
216
218
|
|
|
217
219
|
conn
|
|
@@ -223,11 +225,11 @@ class Sequel::ShardedThreadedConnectionPool < Sequel::ThreadedConnectionPool
|
|
|
223
225
|
# Check if connection was checked in between when assign_connection failed and now.
|
|
224
226
|
# This is very unlikely, but necessary to prevent a situation where the waiter
|
|
225
227
|
# will wait for a connection even though one has already been checked in.
|
|
226
|
-
# :
|
|
228
|
+
# simplecov:disable
|
|
227
229
|
if conn = next_available(server)
|
|
228
230
|
return(allocated(server)[thread] = conn)
|
|
229
231
|
end
|
|
230
|
-
# :
|
|
232
|
+
# simplecov:enable
|
|
231
233
|
|
|
232
234
|
@waiters[server].wait(@mutex, timeout)
|
|
233
235
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# frozen-string-literal: true
|
|
2
2
|
|
|
3
|
-
# :
|
|
3
|
+
# simplecov:disable
|
|
4
4
|
raise LoadError, "Sequel::ShardedTimedQueueConnectionPool is only available on Ruby 3.2+" unless RUBY_VERSION >= '3.2'
|
|
5
|
-
# :
|
|
5
|
+
# simplecov:enable
|
|
6
6
|
|
|
7
7
|
# A connection pool allowing multi-threaded access to a sharded pool of connections,
|
|
8
8
|
# using a timed queue (only available in Ruby 3.2+).
|
|
@@ -148,7 +148,7 @@ class Sequel::ShardedTimedQueueConnectionPool < Sequel::ConnectionPool
|
|
|
148
148
|
@queues[pick_server(server)].num_waiting
|
|
149
149
|
end
|
|
150
150
|
|
|
151
|
-
# The total number of connections in the pool. Using a non-
|
|
151
|
+
# The total number of connections in the pool. Using a non-existent server will return nil.
|
|
152
152
|
def size(server=:default)
|
|
153
153
|
sync{@sizes[server]}
|
|
154
154
|
end
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# frozen-string-literal: true
|
|
2
2
|
|
|
3
|
+
# SEQUEL6: Remove, deprecation: add warning if used on Ruby 3.2+
|
|
4
|
+
|
|
3
5
|
# A connection pool allowing multi-threaded access to a pool of connections.
|
|
4
6
|
# This is the default connection pool used by Sequel.
|
|
5
7
|
class Sequel::ThreadedConnectionPool < Sequel::ConnectionPool
|
|
6
|
-
USE_WAITER = true
|
|
8
|
+
USE_WAITER = true
|
|
7
9
|
Sequel::Deprecation.deprecate_constant(self, :USE_WAITER)
|
|
8
10
|
|
|
9
11
|
# The maximum number of connections this pool will create (per shard/server
|
|
@@ -12,11 +14,11 @@ class Sequel::ThreadedConnectionPool < Sequel::ConnectionPool
|
|
|
12
14
|
|
|
13
15
|
# An array of connections that are available for use by the pool.
|
|
14
16
|
# The calling code should already have the mutex before calling this.
|
|
15
|
-
attr_reader :available_connections
|
|
17
|
+
attr_reader :available_connections
|
|
16
18
|
|
|
17
19
|
# A hash with thread/fiber keys and connection values for currently allocated connections.
|
|
18
20
|
# The calling code should already have the mutex before calling this.
|
|
19
|
-
attr_reader :allocated
|
|
21
|
+
attr_reader :allocated
|
|
20
22
|
|
|
21
23
|
# The following additional options are respected:
|
|
22
24
|
# :max_connections :: The maximum number of connections the connection pool
|
|
@@ -149,7 +151,7 @@ class Sequel::ThreadedConnectionPool < Sequel::ConnectionPool
|
|
|
149
151
|
|
|
150
152
|
until conn = assign_connection(thread)
|
|
151
153
|
elapsed = Sequel.elapsed_seconds_since(timer)
|
|
152
|
-
# :
|
|
154
|
+
# simplecov:disable
|
|
153
155
|
raise_pool_timeout(elapsed) if elapsed > timeout
|
|
154
156
|
|
|
155
157
|
# It's difficult to get to this point, it can only happen if there is a race condition
|
|
@@ -157,7 +159,7 @@ class Sequel::ThreadedConnectionPool < Sequel::ConnectionPool
|
|
|
157
159
|
if conn = acquire_available(thread, timeout - elapsed)
|
|
158
160
|
return conn
|
|
159
161
|
end
|
|
160
|
-
# :
|
|
162
|
+
# simplecov:enable
|
|
161
163
|
end
|
|
162
164
|
|
|
163
165
|
conn
|
|
@@ -169,11 +171,11 @@ class Sequel::ThreadedConnectionPool < Sequel::ConnectionPool
|
|
|
169
171
|
# Check if connection was checked in between when assign_connection failed and now.
|
|
170
172
|
# This is very unlikely, but necessary to prevent a situation where the waiter
|
|
171
173
|
# will wait for a connection even though one has already been checked in.
|
|
172
|
-
# :
|
|
174
|
+
# simplecov:disable
|
|
173
175
|
if conn = next_available
|
|
174
176
|
return(@allocated[thread] = conn)
|
|
175
177
|
end
|
|
176
|
-
# :
|
|
178
|
+
# simplecov:enable
|
|
177
179
|
|
|
178
180
|
@waiter.wait(@mutex, timeout)
|
|
179
181
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# frozen-string-literal: true
|
|
2
2
|
|
|
3
|
-
# :
|
|
3
|
+
# simplecov:disable
|
|
4
4
|
raise LoadError, "Sequel::TimedQueueConnectionPool is only available on Ruby 3.2+" unless RUBY_VERSION >= '3.2'
|
|
5
|
-
# :
|
|
5
|
+
# simplecov:enable
|
|
6
6
|
|
|
7
7
|
# A connection pool allowing multi-threaded access to a pool of connections,
|
|
8
8
|
# using a timed queue (only available in Ruby 3.2+).
|
|
@@ -38,7 +38,7 @@ class Sequel::ConnectionPool
|
|
|
38
38
|
POOL_CLASS_MAP.freeze
|
|
39
39
|
|
|
40
40
|
# Class methods used to return an appropriate pool subclass, separated
|
|
41
|
-
# into a module for easier
|
|
41
|
+
# into a module for easier overriding by extensions.
|
|
42
42
|
module ClassMethods
|
|
43
43
|
# Return a pool subclass instance based on the given options. If a <tt>:pool_class</tt>
|
|
44
44
|
# option is provided is provided, use that pool class, otherwise
|
|
@@ -72,11 +72,11 @@ class Sequel::ConnectionPool
|
|
|
72
72
|
opts[:servers] ? :sharded_single : :single
|
|
73
73
|
elsif RUBY_VERSION >= '3.2'
|
|
74
74
|
opts[:servers] ? :sharded_timed_queue : :timed_queue
|
|
75
|
-
# :
|
|
75
|
+
# simplecov:disable
|
|
76
76
|
else
|
|
77
77
|
opts[:servers] ? :sharded_threaded : :threaded
|
|
78
78
|
end
|
|
79
|
-
# :
|
|
79
|
+
# simplecov:enable
|
|
80
80
|
|
|
81
81
|
connection_pool_class(:pool_class=>pc)
|
|
82
82
|
end
|
data/lib/sequel/core.rb
CHANGED
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
# For a quicker introduction, see the {cheat sheet}[rdoc-ref:doc/cheat_sheet.rdoc].
|
|
27
27
|
module Sequel
|
|
28
28
|
@convert_two_digit_years = true
|
|
29
|
-
@datetime_class = Time
|
|
30
|
-
@split_symbols = false
|
|
29
|
+
@datetime_class = Time # SEQUEL6: Remove
|
|
30
|
+
@split_symbols = false # SEQUEL6: Remove
|
|
31
31
|
@single_threaded = false
|
|
32
32
|
|
|
33
33
|
# Mutex used to protect mutable data structures
|
|
@@ -36,7 +36,7 @@ module Sequel
|
|
|
36
36
|
# Frozen hash used as the default options hash for most options.
|
|
37
37
|
OPTS = {}.freeze
|
|
38
38
|
|
|
39
|
-
SPLIT_SYMBOL_CACHE = {}
|
|
39
|
+
SPLIT_SYMBOL_CACHE = {} # SEQUEL6: Remove
|
|
40
40
|
|
|
41
41
|
module SequelMethods
|
|
42
42
|
# Sequel converts two digit years in <tt>Date</tt>s and <tt>DateTime</tt>s by default,
|
|
@@ -56,6 +56,8 @@ module Sequel
|
|
|
56
56
|
# cases where they implement the same methods, they often implement them
|
|
57
57
|
# differently (e.g. + using seconds on +Time+ and days on +DateTime+).
|
|
58
58
|
attr_accessor :datetime_class
|
|
59
|
+
# SEQUEL6: Remove datetime_class=
|
|
60
|
+
# SEQUEL6.1: Remove datetime_class
|
|
59
61
|
|
|
60
62
|
# Set whether Sequel is being used in single threaded mode. By default,
|
|
61
63
|
# Sequel uses a thread-safe connection pool, which isn't as fast as the
|
|
@@ -66,8 +68,7 @@ module Sequel
|
|
|
66
68
|
# Sequel.single_threaded = true
|
|
67
69
|
attr_accessor :single_threaded
|
|
68
70
|
|
|
69
|
-
#
|
|
70
|
-
# require for backwards compatibility.
|
|
71
|
+
# # SEQUEL6: Remove
|
|
71
72
|
alias orig_require require
|
|
72
73
|
private :orig_require
|
|
73
74
|
|
|
@@ -155,7 +156,15 @@ module Sequel
|
|
|
155
156
|
# Sequel.extension(:blank)
|
|
156
157
|
# Sequel.extension(:core_extensions, :named_timezones)
|
|
157
158
|
def extension(*extensions)
|
|
158
|
-
extensions.each
|
|
159
|
+
extensions.each do |e|
|
|
160
|
+
e = e.to_s
|
|
161
|
+
|
|
162
|
+
if %r{..[/\\]} =~ e
|
|
163
|
+
raise Error, "cannot use extension with ../ for security reasons"
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
orig_require("sequel/extensions/#{e}")
|
|
167
|
+
end
|
|
159
168
|
end
|
|
160
169
|
|
|
161
170
|
# The exception classed raised if there is an error parsing JSON.
|
|
@@ -169,14 +178,14 @@ module Sequel
|
|
|
169
178
|
def array_or_set_join(obj, arg)
|
|
170
179
|
obj.join(arg)
|
|
171
180
|
end
|
|
172
|
-
# :
|
|
181
|
+
# simplecov:disable
|
|
173
182
|
else
|
|
174
183
|
def array_or_set_join(obj, arg)
|
|
175
184
|
obj = obj.to_a if obj.is_a?(Set)
|
|
176
185
|
obj.join(arg)
|
|
177
186
|
end
|
|
178
187
|
end
|
|
179
|
-
# :
|
|
188
|
+
# simplecov:enable
|
|
180
189
|
|
|
181
190
|
if RUBY_VERSION >= '3.3'
|
|
182
191
|
# Create a new module using the block, and set the temporary name
|
|
@@ -185,13 +194,13 @@ module Sequel
|
|
|
185
194
|
mod.set_temporary_name(yield)
|
|
186
195
|
mod
|
|
187
196
|
end
|
|
188
|
-
# :
|
|
197
|
+
# simplecov:disable
|
|
189
198
|
else
|
|
190
199
|
def set_temp_name(mod)
|
|
191
200
|
mod
|
|
192
201
|
end
|
|
193
202
|
end
|
|
194
|
-
# :
|
|
203
|
+
# simplecov:enable
|
|
195
204
|
|
|
196
205
|
# Convert given object to json and return the result.
|
|
197
206
|
# This can be overridden to use an alternative json implementation.
|
|
@@ -202,7 +211,11 @@ module Sequel
|
|
|
202
211
|
# Parse the string as JSON and return the result.
|
|
203
212
|
# This can be overridden to use an alternative json implementation.
|
|
204
213
|
def parse_json(json)
|
|
205
|
-
JSON
|
|
214
|
+
if JSON::VERSION >= '3'
|
|
215
|
+
JSON.parse(json)
|
|
216
|
+
else
|
|
217
|
+
JSON.parse(json, :create_additions=>false)
|
|
218
|
+
end
|
|
206
219
|
end
|
|
207
220
|
|
|
208
221
|
# If a mutex is given, synchronize access using it. If nil is given, just
|
|
@@ -231,18 +244,23 @@ module Sequel
|
|
|
231
244
|
|
|
232
245
|
# For backwards compatibility only. require_relative should be used instead.
|
|
233
246
|
def require(files, subdir=nil)
|
|
247
|
+
# SEQUEL6: Remove
|
|
234
248
|
# Use Kernel.require_relative to work around JRuby 9.0 bug
|
|
249
|
+
# simplecov:disable
|
|
235
250
|
Array(files).each{|f| Kernel.require_relative "#{"#{subdir}/" if subdir}#{f}"}
|
|
251
|
+
# simplecov:enable
|
|
252
|
+
Sequel::Deprecation.deprecate("Sequel.require is deprecated and will be removed in Sequel 6.")
|
|
236
253
|
end
|
|
237
254
|
|
|
238
255
|
# Splits the symbol into three parts, if symbol splitting is enabled (not the default).
|
|
239
256
|
# Each part will either be a string or nil. If symbol splitting
|
|
240
257
|
# is disabled, returns an array with the first and third parts
|
|
241
|
-
# being nil, and the second part
|
|
258
|
+
# being nil, and the second part behind a string version of the symbol.
|
|
242
259
|
#
|
|
243
260
|
# For columns, these parts are the table, column, and alias.
|
|
244
261
|
# For tables, these parts are the schema, table, and alias.
|
|
245
262
|
def split_symbol(sym)
|
|
263
|
+
# SEQUEL6.1: Remove
|
|
246
264
|
unless v = Sequel.synchronize{SPLIT_SYMBOL_CACHE[sym]}
|
|
247
265
|
if split_symbols?
|
|
248
266
|
v = case s = sym.to_s
|
|
@@ -284,7 +302,7 @@ module Sequel
|
|
|
284
302
|
#
|
|
285
303
|
# Disabling symbol splitting will also disable the handling
|
|
286
304
|
# of double underscores in virtual row methods, causing such methods to
|
|
287
|
-
# yield regular
|
|
305
|
+
# yield regular identifiers instead of qualified identifiers:
|
|
288
306
|
#
|
|
289
307
|
# # Sequel.split_symbols = true
|
|
290
308
|
# Sequel.expr{table__column} # table.column
|
|
@@ -294,12 +312,14 @@ module Sequel
|
|
|
294
312
|
# Sequel.expr{table__column} # table__column
|
|
295
313
|
# Sequel.expr{table[:column]} # table.column
|
|
296
314
|
def split_symbols=(v)
|
|
315
|
+
# SEQUEL6: Remove
|
|
297
316
|
Sequel.synchronize{SPLIT_SYMBOL_CACHE.clear}
|
|
298
317
|
@split_symbols = v
|
|
299
318
|
end
|
|
300
319
|
|
|
301
320
|
# Whether Sequel currently splits symbols into qualified/aliased identifiers.
|
|
302
321
|
def split_symbols?
|
|
322
|
+
# SEQUEL6.1: Remove
|
|
303
323
|
@split_symbols
|
|
304
324
|
end
|
|
305
325
|
|
|
@@ -352,11 +372,11 @@ module Sequel
|
|
|
352
372
|
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
353
373
|
end
|
|
354
374
|
else
|
|
355
|
-
# :
|
|
375
|
+
# simplecov:disable
|
|
356
376
|
def start_timer # :nodoc:
|
|
357
377
|
Time.now
|
|
358
378
|
end
|
|
359
|
-
# :
|
|
379
|
+
# simplecov:enable
|
|
360
380
|
end
|
|
361
381
|
|
|
362
382
|
# The elapsed seconds since the given timer object was created. The
|
|
@@ -451,15 +471,15 @@ module Sequel
|
|
|
451
471
|
end
|
|
452
472
|
extend SequelMethods
|
|
453
473
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
474
|
+
require_relative "deprecated"
|
|
475
|
+
require_relative "sql"
|
|
476
|
+
require_relative "connection_pool"
|
|
477
|
+
require_relative "exceptions"
|
|
478
|
+
require_relative "dataset"
|
|
479
|
+
require_relative "database"
|
|
480
|
+
require_relative "timezones"
|
|
481
|
+
require_relative "ast_transformer"
|
|
482
|
+
require_relative "version"
|
|
463
483
|
|
|
464
484
|
class << self
|
|
465
485
|
# Allow nicer syntax for creating Sequel expressions:
|
|
@@ -192,7 +192,7 @@ module Sequel
|
|
|
192
192
|
|
|
193
193
|
# Disconnects all available connections from the connection pool. Any
|
|
194
194
|
# connections currently in use will not be disconnected. Options:
|
|
195
|
-
# :server :: Should be a symbol
|
|
195
|
+
# :server :: Should be a symbol specifying the server to disconnect from,
|
|
196
196
|
# or an array of symbols to specify multiple servers.
|
|
197
197
|
#
|
|
198
198
|
# Example:
|
|
@@ -5,7 +5,7 @@ module Sequel
|
|
|
5
5
|
# ---------------------
|
|
6
6
|
# :section: 9 - Methods that describe what the database supports
|
|
7
7
|
# These methods all return booleans, with most describing whether or not the
|
|
8
|
-
# database
|
|
8
|
+
# database supports a given feature.
|
|
9
9
|
# ---------------------
|
|
10
10
|
|
|
11
11
|
# Whether the database uses a global namespace for the index, true by default. If
|
data/lib/sequel/database/misc.rb
CHANGED
|
@@ -26,9 +26,9 @@ module Sequel
|
|
|
26
26
|
:time=>Sequel::SQLTime, :boolean=>[TrueClass, FalseClass].freeze, :float=>Float, :decimal=>BigDecimal,
|
|
27
27
|
:blob=>Sequel::SQL::Blob}.freeze
|
|
28
28
|
|
|
29
|
-
# :
|
|
29
|
+
# simplecov:disable
|
|
30
30
|
URI_PARSER = defined?(::URI::RFC2396_PARSER) ? ::URI::RFC2396_PARSER : ::URI::DEFAULT_PARSER
|
|
31
|
-
# :
|
|
31
|
+
# simplecov:enable
|
|
32
32
|
private_constant :URI_PARSER
|
|
33
33
|
|
|
34
34
|
# Nested hook Proc; each new hook Proc just wraps the previous one.
|
|
@@ -98,7 +98,7 @@ module Sequel
|
|
|
98
98
|
# The options hash for this database
|
|
99
99
|
attr_reader :opts
|
|
100
100
|
|
|
101
|
-
# Set the timezone to use for this database,
|
|
101
|
+
# Set the timezone to use for this database, overriding <tt>Sequel.database_timezone</tt>.
|
|
102
102
|
attr_writer :timezone
|
|
103
103
|
|
|
104
104
|
# The specific default size of string columns for this Sequel::Database, usually 255 by default.
|
|
@@ -229,12 +229,7 @@ module Sequel
|
|
|
229
229
|
end
|
|
230
230
|
|
|
231
231
|
# Disallow dup/clone for Database instances
|
|
232
|
-
undef_method :dup, :clone, :initialize_copy
|
|
233
|
-
# :nocov:
|
|
234
|
-
if RUBY_VERSION >= '1.9.3'
|
|
235
|
-
# :nocov:
|
|
236
|
-
undef_method :initialize_clone, :initialize_dup
|
|
237
|
-
end
|
|
232
|
+
undef_method :dup, :clone, :initialize_copy, :initialize_clone, :initialize_dup
|
|
238
233
|
|
|
239
234
|
# Cast the given type to a literal type
|
|
240
235
|
#
|
|
@@ -580,7 +575,7 @@ module Sequel
|
|
|
580
575
|
# Typecast a string to a BigDecimal
|
|
581
576
|
alias _typecast_value_string_to_decimal BigDecimal
|
|
582
577
|
else
|
|
583
|
-
# :
|
|
578
|
+
# simplecov:disable
|
|
584
579
|
def _typecast_value_string_to_decimal(value)
|
|
585
580
|
d = BigDecimal(value)
|
|
586
581
|
if d.zero?
|
|
@@ -595,7 +590,7 @@ module Sequel
|
|
|
595
590
|
end
|
|
596
591
|
d
|
|
597
592
|
end
|
|
598
|
-
# :
|
|
593
|
+
# simplecov:enable
|
|
599
594
|
end
|
|
600
595
|
|
|
601
596
|
# Typecast the value to a BigDecimal
|
|
@@ -415,9 +415,9 @@ module Sequel
|
|
|
415
415
|
|
|
416
416
|
# Post process the schema values.
|
|
417
417
|
def schema_post_process(cols)
|
|
418
|
-
# :
|
|
418
|
+
# simplecov:disable
|
|
419
419
|
if RUBY_VERSION >= '2.5'
|
|
420
|
-
# :
|
|
420
|
+
# simplecov:enable
|
|
421
421
|
cols.each do |_, h|
|
|
422
422
|
db_type = h[:db_type]
|
|
423
423
|
if db_type.is_a?(String)
|
|
@@ -13,9 +13,9 @@ module Sequel
|
|
|
13
13
|
def _merge_column_options(defaults, opts)
|
|
14
14
|
defaults.merge!(opts) do |k, defv, v|
|
|
15
15
|
unless defv == v
|
|
16
|
-
# :
|
|
16
|
+
# simplecov:disable
|
|
17
17
|
if RUBY_VERSION >= "3.2"
|
|
18
|
-
# :
|
|
18
|
+
# simplecov:enable
|
|
19
19
|
caller_loc = Thread.each_caller_location do |loc|
|
|
20
20
|
# Skip core library methods implemented in Ruby
|
|
21
21
|
path = loc.path
|
|
@@ -152,7 +152,7 @@ module Sequel
|
|
|
152
152
|
# :not_null :: Similar to setting <tt>null: false</tt>, but you can provide a hash value
|
|
153
153
|
# to specify options for the NOT NULL constraint on PostgreSQL 18+:
|
|
154
154
|
# :name :: The name of the NOT NULL constraint
|
|
155
|
-
# :no_inherit :: Set NO INHERIT on the constraint, so it will not
|
|
155
|
+
# :no_inherit :: Set NO INHERIT on the constraint, so it will not propagate to
|
|
156
156
|
# child tables.
|
|
157
157
|
# :null :: Mark the column as allowing NULL values (if true),
|
|
158
158
|
# or not allowing NULL values (if false). The default is to allow NULL values.
|
|
@@ -227,7 +227,7 @@ module Sequel
|
|
|
227
227
|
# :deferrable :: Whether the CHECK constraint should be marked DEFERRABLE.
|
|
228
228
|
#
|
|
229
229
|
# PostgreSQL specific options:
|
|
230
|
-
# :no_inherit :: Set NO INHERIT on the constraint, so it will not
|
|
230
|
+
# :no_inherit :: Set NO INHERIT on the constraint, so it will not propagate to
|
|
231
231
|
# child tables.
|
|
232
232
|
# :not_enforced :: Whether the CHECK constraint should be marked NOT ENFORCED.
|
|
233
233
|
# :not_valid :: Whether the CHECK constraint should be marked NOT VALID.
|
|
@@ -984,7 +984,7 @@ module Sequel
|
|
|
984
984
|
on_delete_clause(action)
|
|
985
985
|
end
|
|
986
986
|
|
|
987
|
-
# Add fragment for primary key specification, separated for easier
|
|
987
|
+
# Add fragment for primary key specification, separated for easier overriding.
|
|
988
988
|
def primary_key_constraint_sql_fragment(_)
|
|
989
989
|
'PRIMARY KEY'
|
|
990
990
|
end
|
|
@@ -1144,7 +1144,7 @@ module Sequel
|
|
|
1144
1144
|
"#{type}#{literal(Array(elements)) if elements}#{' UNSIGNED' if column[:unsigned]}"
|
|
1145
1145
|
end
|
|
1146
1146
|
|
|
1147
|
-
# Add fragment for unique specification, separated for easier
|
|
1147
|
+
# Add fragment for unique specification, separated for easier overriding.
|
|
1148
1148
|
def unique_constraint_sql_fragment(_)
|
|
1149
1149
|
'UNIQUE'
|
|
1150
1150
|
end
|