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
|
@@ -77,6 +77,7 @@ module Sequel
|
|
|
77
77
|
# Represents a PostgreSQL array column value.
|
|
78
78
|
class PGArray < DelegateClass(Array)
|
|
79
79
|
include Sequel::SQL::AliasMethods
|
|
80
|
+
include Sequel::SQL::CastMethods
|
|
80
81
|
|
|
81
82
|
module DatabaseMethods
|
|
82
83
|
BLOB_RANGE = 1...-1
|
|
@@ -362,18 +363,18 @@ module Sequel
|
|
|
362
363
|
raise Sequel::Error, "invalid array, empty string" if eos?
|
|
363
364
|
raise Sequel::Error, "invalid array, doesn't start with {" unless scan(/((\[\d+:\d+\])+=)?\{/)
|
|
364
365
|
|
|
365
|
-
# :
|
|
366
|
+
# simplecov:disable
|
|
366
367
|
while !eos?
|
|
367
|
-
# :
|
|
368
|
+
# simplecov:enable
|
|
368
369
|
char = scan(/[{}",]|[^{}",]+/)
|
|
369
370
|
if char == ','
|
|
370
371
|
# Comma outside quoted string indicates end of current entry
|
|
371
372
|
new_entry
|
|
372
373
|
elsif char == '"'
|
|
373
374
|
raise Sequel::Error, "invalid array, opening quote with existing recorded data" unless @recorded.empty?
|
|
374
|
-
# :
|
|
375
|
+
# simplecov:disable
|
|
375
376
|
while true
|
|
376
|
-
# :
|
|
377
|
+
# simplecov:enable
|
|
377
378
|
char = scan(/["\\]|[^"\\]+/)
|
|
378
379
|
if char == '\\'
|
|
379
380
|
@recorded << getch
|
|
@@ -389,6 +390,7 @@ module Sequel
|
|
|
389
390
|
elsif char == '{'
|
|
390
391
|
raise Sequel::Error, "invalid array, opening brace with existing recorded data" unless @recorded.empty?
|
|
391
392
|
|
|
393
|
+
raise Sequel::Error, "cannot parse array with more than 6 dimensions" if @stack.length >= 6
|
|
392
394
|
# Start of new array, add it to the stack
|
|
393
395
|
new = []
|
|
394
396
|
@stack.last << new
|
|
@@ -434,12 +436,12 @@ module Sequel
|
|
|
434
436
|
end
|
|
435
437
|
|
|
436
438
|
if Sequel::Postgres.respond_to?(:parse_pg_array)
|
|
437
|
-
# :
|
|
439
|
+
# simplecov:disable
|
|
438
440
|
# Use sequel_pg's C-based parser if it has already been defined.
|
|
439
441
|
def call(string)
|
|
440
442
|
PGArray.new(Sequel::Postgres.parse_pg_array(string, @converter), @type)
|
|
441
443
|
end
|
|
442
|
-
# :
|
|
444
|
+
# simplecov:enable
|
|
443
445
|
else
|
|
444
446
|
# Parse the string using Parser with the appropriate
|
|
445
447
|
# converter, and return a PGArray with the appropriate database
|
|
@@ -531,7 +533,7 @@ module Sequel
|
|
|
531
533
|
Database.register_extension(:pg_array, Postgres::PGArray::DatabaseMethods)
|
|
532
534
|
end
|
|
533
535
|
|
|
534
|
-
# :
|
|
536
|
+
# simplecov:disable
|
|
535
537
|
if Sequel.core_extensions?
|
|
536
538
|
class Array
|
|
537
539
|
# Return a PGArray proxy to the receiver, using a
|
|
@@ -553,4 +555,4 @@ if defined?(Sequel::CoreRefinements)
|
|
|
553
555
|
end
|
|
554
556
|
end
|
|
555
557
|
end
|
|
556
|
-
# :
|
|
558
|
+
# simplecov:enable
|
|
@@ -54,15 +54,20 @@
|
|
|
54
54
|
# ia.join # array_to_string(int_array_column, '')
|
|
55
55
|
# ia.join(':') # array_to_string(int_array_column, ':')
|
|
56
56
|
# ia.join(':', ' ') # array_to_string(int_array_column, ':', ' ')
|
|
57
|
-
# ia.
|
|
58
|
-
# ia.
|
|
59
|
-
#
|
|
60
|
-
#
|
|
61
|
-
#
|
|
57
|
+
# ia.ndims # array_ndims(int_array_column)
|
|
58
|
+
# ia.position(3) # array_position(int_array_column, 3, 1)
|
|
59
|
+
# ia.position(3, 2) # array_position(int_array_column, 3, 2)
|
|
60
|
+
# ia.positions(3) # array_positions(int_array_column, 3)
|
|
61
|
+
# ia.prepend(3) # array_prepend(3, int_array_column)
|
|
62
|
+
# ia.reverse # array_reverse(int_array_column)
|
|
63
|
+
# ia.sample(3) # array_sample(int_array_column, 3)
|
|
64
|
+
# ia.shuffle # array_shuffle(int_array_column)
|
|
62
65
|
# ia.sort # array_sort(int_array_column)
|
|
63
66
|
# ia.sort(desc: true) # array_sort(int_array_column, true)
|
|
64
67
|
# ia.sort(nulls: :first) # array_sort(int_array_column, false, true)
|
|
65
|
-
# ia.
|
|
68
|
+
# ia.trim(1) # trim_array(int_array_column, 1)
|
|
69
|
+
# ia.unnest # unnest(int_array_column)
|
|
70
|
+
# ia.unnest(:b) # unnest(int_array_column, b)
|
|
66
71
|
#
|
|
67
72
|
# See the PostgreSQL array function and operator documentation for more
|
|
68
73
|
# details on what these functions and operators do.
|
|
@@ -153,6 +158,13 @@ module Sequel
|
|
|
153
158
|
function(:array_dims)
|
|
154
159
|
end
|
|
155
160
|
|
|
161
|
+
# Call the array_ndims method:
|
|
162
|
+
#
|
|
163
|
+
# array_op.ndims # array_ndims(array)
|
|
164
|
+
def ndims
|
|
165
|
+
function(:array_ndims)
|
|
166
|
+
end
|
|
167
|
+
|
|
156
168
|
# Convert the array into an hstore using the hstore function.
|
|
157
169
|
# If given an argument, use the two array form:
|
|
158
170
|
#
|
|
@@ -164,9 +176,9 @@ module Sequel
|
|
|
164
176
|
else
|
|
165
177
|
Sequel.function(:hstore, self, wrap_array(arg))
|
|
166
178
|
end
|
|
167
|
-
# :
|
|
179
|
+
# simplecov:disable
|
|
168
180
|
if Sequel.respond_to?(:hstore_op)
|
|
169
|
-
# :
|
|
181
|
+
# simplecov:enable
|
|
170
182
|
v = Sequel.hstore_op(v)
|
|
171
183
|
end
|
|
172
184
|
v
|
|
@@ -188,6 +200,28 @@ module Sequel
|
|
|
188
200
|
function(:array_lower, dimension)
|
|
189
201
|
end
|
|
190
202
|
|
|
203
|
+
# Call the array_position method:
|
|
204
|
+
#
|
|
205
|
+
# array_op.position(1) # array_position(array, 1, 1)
|
|
206
|
+
# array_op.position(1, 2) # array_position(array, 1, 2)
|
|
207
|
+
def position(element, offset = 1)
|
|
208
|
+
function(:array_position, element, offset)
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
# Call the array_positions method:
|
|
212
|
+
#
|
|
213
|
+
# array_op.positions(1) # array_positions(array, 1)
|
|
214
|
+
def positions(element)
|
|
215
|
+
function(:array_positions, element)
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
# Call the array_prepend method:
|
|
219
|
+
#
|
|
220
|
+
# array_op.prepend(1) # array_prepend(1, array)
|
|
221
|
+
def prepend(element)
|
|
222
|
+
SQL::Function.new(:array_prepend, element, self)
|
|
223
|
+
end
|
|
224
|
+
|
|
191
225
|
# Use the overlaps (&&) operator:
|
|
192
226
|
#
|
|
193
227
|
# array_op.overlaps(:a) # (array && a)
|
|
@@ -195,7 +229,7 @@ module Sequel
|
|
|
195
229
|
bool_op(OVERLAPS, wrap_array(other))
|
|
196
230
|
end
|
|
197
231
|
|
|
198
|
-
# Use the
|
|
232
|
+
# Use the concatenation (||) operator:
|
|
199
233
|
#
|
|
200
234
|
# array_op.push(:a) # (array || a)
|
|
201
235
|
# array_op.concat(:a) # (array || a)
|
|
@@ -231,6 +265,20 @@ module Sequel
|
|
|
231
265
|
function(:array_reverse)
|
|
232
266
|
end
|
|
233
267
|
|
|
268
|
+
# Call the array_sample method:
|
|
269
|
+
#
|
|
270
|
+
# array_op.sample(1) # array_sample(array, 1)
|
|
271
|
+
def sample(element)
|
|
272
|
+
function(:array_sample, element)
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
# Call the array_shuffle method:
|
|
276
|
+
#
|
|
277
|
+
# array_op.shuffle # array_shuffle
|
|
278
|
+
def shuffle
|
|
279
|
+
function(:array_shuffle)
|
|
280
|
+
end
|
|
281
|
+
|
|
234
282
|
# Call the array_sort method. Options:
|
|
235
283
|
#
|
|
236
284
|
# :desc :: Sort in descending order instead of ascending order.
|
|
@@ -273,6 +321,13 @@ module Sequel
|
|
|
273
321
|
end
|
|
274
322
|
alias join to_string
|
|
275
323
|
|
|
324
|
+
# Call the trim_array method:
|
|
325
|
+
#
|
|
326
|
+
# array_op.trim(1) # array_trim(array, 1)
|
|
327
|
+
def trim(number)
|
|
328
|
+
function(:trim_array, number)
|
|
329
|
+
end
|
|
330
|
+
|
|
276
331
|
# Call the unnest method:
|
|
277
332
|
#
|
|
278
333
|
# array_op.unnest # unnest(array)
|
|
@@ -280,7 +335,7 @@ module Sequel
|
|
|
280
335
|
function(:unnest, *args.map{|a| wrap_array(a)})
|
|
281
336
|
end
|
|
282
337
|
|
|
283
|
-
# Use the
|
|
338
|
+
# Use the concatenation (||) operator, reversing the order:
|
|
284
339
|
#
|
|
285
340
|
# array_op.unshift(:a) # (a || array)
|
|
286
341
|
def unshift(other)
|
|
@@ -326,9 +381,9 @@ module Sequel
|
|
|
326
381
|
end
|
|
327
382
|
end
|
|
328
383
|
|
|
329
|
-
# :
|
|
384
|
+
# simplecov:disable
|
|
330
385
|
if defined?(PGArray)
|
|
331
|
-
# :
|
|
386
|
+
# simplecov:enable
|
|
332
387
|
class PGArray
|
|
333
388
|
# Wrap the PGArray instance in an ArrayOp, allowing you to easily use
|
|
334
389
|
# the PostgreSQL array functions and operators with literal arrays.
|
|
@@ -360,7 +415,7 @@ module Sequel
|
|
|
360
415
|
end
|
|
361
416
|
end
|
|
362
417
|
|
|
363
|
-
# :
|
|
418
|
+
# simplecov:disable
|
|
364
419
|
if Sequel.core_extensions?
|
|
365
420
|
class Symbol
|
|
366
421
|
include Sequel::Postgres::ArrayOpMethods
|
|
@@ -374,4 +429,4 @@ if defined?(Sequel::CoreRefinements)
|
|
|
374
429
|
end
|
|
375
430
|
end
|
|
376
431
|
end
|
|
377
|
-
# :
|
|
432
|
+
# simplecov:enable
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
# DB[:t].select{foo('a').as(:f)}.group{foo('a')}
|
|
57
57
|
# # SELECT foo('a') AS "f" FROM "t" GROUP BY foo('a')
|
|
58
58
|
#
|
|
59
|
-
# Will get auto
|
|
59
|
+
# Will get auto parameterized as:
|
|
60
60
|
#
|
|
61
61
|
# # SELECT foo($1) AS "f" FROM "t" GROUP BY foo($2)
|
|
62
62
|
#
|
|
@@ -180,7 +180,7 @@ module Sequel
|
|
|
180
180
|
end
|
|
181
181
|
end
|
|
182
182
|
|
|
183
|
-
#
|
|
183
|
+
# PlaceholderLiteralizer subclass with support for stored auto parameters.
|
|
184
184
|
class PlaceholderLiteralizer < ::Sequel::Dataset::PlaceholderLiteralizer
|
|
185
185
|
def initialize(dataset, fragments, final_sql, arity)
|
|
186
186
|
s = dataset.sql.dup
|
|
@@ -49,7 +49,7 @@ module Sequel
|
|
|
49
49
|
# Enable automatically parameterizing queries.
|
|
50
50
|
module AutoParameterizeInArray
|
|
51
51
|
module TreatStringListAsUntypedArray
|
|
52
|
-
#
|
|
52
|
+
# Sentinel value to use as an auto param type to use auto parameterization
|
|
53
53
|
# of a string array without an explicit type cast.
|
|
54
54
|
NO_EXPLICIT_CAST = Object.new.freeze
|
|
55
55
|
|
|
@@ -64,7 +64,7 @@ module Sequel
|
|
|
64
64
|
|
|
65
65
|
private
|
|
66
66
|
|
|
67
|
-
# Recognize NO_EXPLICIT_CAST
|
|
67
|
+
# Recognize NO_EXPLICIT_CAST sentinel value and use wrapped
|
|
68
68
|
# PGArray that will be parameterized into the query.
|
|
69
69
|
def _convert_array_to_pg_array_with_type(r, type)
|
|
70
70
|
if NO_EXPLICIT_CAST.equal?(type)
|
|
@@ -158,7 +158,7 @@ module Sequel
|
|
|
158
158
|
nil
|
|
159
159
|
end
|
|
160
160
|
|
|
161
|
-
# The
|
|
161
|
+
# The minimum size of array to auto parameterize.
|
|
162
162
|
def pg_auto_parameterize_min_array_size
|
|
163
163
|
2
|
|
164
164
|
end
|
|
@@ -180,9 +180,9 @@ module Sequel
|
|
|
180
180
|
end
|
|
181
181
|
|
|
182
182
|
# support reversible create_enum statements if the migration extension is loaded
|
|
183
|
-
# :
|
|
183
|
+
# simplecov:disable
|
|
184
184
|
if defined?(MigrationReverser)
|
|
185
|
-
# :
|
|
185
|
+
# simplecov:enable
|
|
186
186
|
class MigrationReverser
|
|
187
187
|
private
|
|
188
188
|
def create_enum(name, _)
|
|
@@ -31,7 +31,7 @@ module Sequel
|
|
|
31
31
|
RATIONAL_60 = Rational(60)
|
|
32
32
|
TIME_CAN_PARSE_BC = RUBY_VERSION >= '2.5'
|
|
33
33
|
|
|
34
|
-
# Add dataset methods and update the conversion
|
|
34
|
+
# Add dataset methods and update the conversion process for dates and timestamps.
|
|
35
35
|
def self.extended(db)
|
|
36
36
|
db.extend_datasets(DatasetMethods)
|
|
37
37
|
procs = db.conversion_procs
|
|
@@ -114,10 +114,10 @@ module Sequel
|
|
|
114
114
|
DateTime.parse(value)
|
|
115
115
|
elsif TIME_CAN_PARSE_BC
|
|
116
116
|
Time.parse(value)
|
|
117
|
-
# :
|
|
117
|
+
# simplecov:disable
|
|
118
118
|
else
|
|
119
119
|
DateTime.parse(value).to_time
|
|
120
|
-
# :
|
|
120
|
+
# simplecov:enable
|
|
121
121
|
end
|
|
122
122
|
|
|
123
123
|
Sequel.convert_output_timestamp(dt, Sequel.application_timezone)
|
|
@@ -219,7 +219,7 @@ module Sequel
|
|
|
219
219
|
end
|
|
220
220
|
|
|
221
221
|
if RUBY_ENGINE == 'jruby'
|
|
222
|
-
# :
|
|
222
|
+
# simplecov:disable
|
|
223
223
|
|
|
224
224
|
ExtendedDateSupport::CONVERT_TYPES = [Java::JavaSQL::Types::DATE, Java::JavaSQL::Types::TIMESTAMP]
|
|
225
225
|
|
|
@@ -241,7 +241,7 @@ module Sequel
|
|
|
241
241
|
super
|
|
242
242
|
end
|
|
243
243
|
end
|
|
244
|
-
# :
|
|
244
|
+
# simplecov:enable
|
|
245
245
|
else
|
|
246
246
|
# Handle BC Time objects.
|
|
247
247
|
def literal_time(time)
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
# # => "numeric"
|
|
54
54
|
#
|
|
55
55
|
# The +:raw+ behavior was Sequel's historical behavior, but unless
|
|
56
|
-
# you fully understand the
|
|
56
|
+
# you fully understand the repercussions of PostgreSQL using a
|
|
57
57
|
# numeric type for integer values, you should not use it.
|
|
58
58
|
#
|
|
59
59
|
# To get the current default behavior of raising an exception for
|
|
@@ -326,7 +326,7 @@ module Sequel
|
|
|
326
326
|
Database.register_extension(:pg_hstore, Postgres::HStore::DatabaseMethods)
|
|
327
327
|
end
|
|
328
328
|
|
|
329
|
-
# :
|
|
329
|
+
# simplecov:disable
|
|
330
330
|
if Sequel.core_extensions?
|
|
331
331
|
class Hash
|
|
332
332
|
# Create a new HStore using the receiver as the input
|
|
@@ -350,4 +350,4 @@ if defined?(Sequel::CoreRefinements)
|
|
|
350
350
|
end
|
|
351
351
|
end
|
|
352
352
|
end
|
|
353
|
-
# :
|
|
353
|
+
# simplecov:enable
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
# DB[:tab].update(h: Sequel.hstore_op(:h).delete('k1'))
|
|
64
64
|
#
|
|
65
65
|
# On PostgreSQL 14+, The hstore <tt>[]</tt> method will use subscripts instead of being
|
|
66
|
-
# the same as +get+, if the value being wrapped is an
|
|
66
|
+
# the same as +get+, if the value being wrapped is an identifier:
|
|
67
67
|
#
|
|
68
68
|
# Sequel.hstore_op(:hstore_column)['a'] # hstore_column['a']
|
|
69
69
|
# Sequel.hstore_op(Sequel[:h][:s])['a'] # h.s['a']
|
|
@@ -367,9 +367,9 @@ module Sequel
|
|
|
367
367
|
end
|
|
368
368
|
end
|
|
369
369
|
|
|
370
|
-
# :
|
|
370
|
+
# simplecov:disable
|
|
371
371
|
if defined?(HStore)
|
|
372
|
-
# :
|
|
372
|
+
# simplecov:enable
|
|
373
373
|
class HStore
|
|
374
374
|
# Wrap the receiver in an HStoreOp so you can easily use the PostgreSQL
|
|
375
375
|
# hstore functions and operators with it.
|
|
@@ -401,7 +401,7 @@ module Sequel
|
|
|
401
401
|
end
|
|
402
402
|
end
|
|
403
403
|
|
|
404
|
-
# :
|
|
404
|
+
# simplecov:disable
|
|
405
405
|
if Sequel.core_extensions?
|
|
406
406
|
class Symbol
|
|
407
407
|
include Sequel::Postgres::HStoreOpMethods
|
|
@@ -415,4 +415,4 @@ if defined?(Sequel::CoreRefinements)
|
|
|
415
415
|
end
|
|
416
416
|
end
|
|
417
417
|
end
|
|
418
|
-
# :
|
|
418
|
+
# simplecov:enable
|
|
@@ -41,9 +41,9 @@ module Sequel
|
|
|
41
41
|
db.instance_exec do
|
|
42
42
|
extend_datasets(InetDatasetMethods)
|
|
43
43
|
|
|
44
|
-
# :
|
|
44
|
+
# simplecov:disable
|
|
45
45
|
if !defined?(SEQUEL_PG_VERSION_INTEGER) || SEQUEL_PG_VERSION_INTEGER >= 11300
|
|
46
|
-
# :
|
|
46
|
+
# simplecov:enable
|
|
47
47
|
# sequel_pg 1.13.0+ will use inet/cidr conversion procs, but doing so is
|
|
48
48
|
# slower, so don't add the conversion procs if using sequel_pg 1.13.0+.
|
|
49
49
|
meth = IPAddr.method(:new)
|
|
@@ -187,7 +187,7 @@ module Sequel
|
|
|
187
187
|
end
|
|
188
188
|
end
|
|
189
189
|
|
|
190
|
-
# :
|
|
190
|
+
# simplecov:disable
|
|
191
191
|
if Sequel.core_extensions?
|
|
192
192
|
class Symbol
|
|
193
193
|
include Sequel::Postgres::InetOpMethods
|
|
@@ -201,4 +201,4 @@ if defined?(Sequel::CoreRefinements)
|
|
|
201
201
|
end
|
|
202
202
|
end
|
|
203
203
|
end
|
|
204
|
-
# :
|
|
204
|
+
# simplecov:enable
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
require 'active_support'
|
|
36
36
|
require 'active_support/duration'
|
|
37
37
|
|
|
38
|
-
# :
|
|
38
|
+
# simplecov:disable
|
|
39
39
|
begin
|
|
40
40
|
require 'active_support/version'
|
|
41
41
|
rescue LoadError
|
|
42
42
|
end
|
|
43
|
-
# :
|
|
43
|
+
# simplecov:enable
|
|
44
44
|
|
|
45
45
|
module Sequel
|
|
46
46
|
module Postgres
|
|
@@ -75,11 +75,11 @@ module Sequel
|
|
|
75
75
|
if defined?(ActiveSupport::Duration::SECONDS_PER_MONTH)
|
|
76
76
|
SECONDS_PER_MONTH = ActiveSupport::Duration::SECONDS_PER_MONTH
|
|
77
77
|
SECONDS_PER_YEAR = ActiveSupport::Duration::SECONDS_PER_YEAR
|
|
78
|
-
# :
|
|
78
|
+
# simplecov:disable
|
|
79
79
|
else
|
|
80
80
|
SECONDS_PER_MONTH = 2592000
|
|
81
81
|
SECONDS_PER_YEAR = 31557600
|
|
82
|
-
# :
|
|
82
|
+
# simplecov:enable
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
# Parse the interval input string into an ActiveSupport::Duration instance.
|
|
@@ -125,11 +125,11 @@ module Sequel
|
|
|
125
125
|
parts[:seconds] = seconds
|
|
126
126
|
end
|
|
127
127
|
|
|
128
|
-
# :
|
|
128
|
+
# simplecov:disable
|
|
129
129
|
if USE_PARTS_ARRAY
|
|
130
130
|
parts = parts.to_a
|
|
131
131
|
end
|
|
132
|
-
# :
|
|
132
|
+
# simplecov:enable
|
|
133
133
|
|
|
134
134
|
ActiveSupport::Duration.new(value, parts)
|
|
135
135
|
end
|
|
@@ -206,12 +206,12 @@ module Sequel
|
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
if RUBY_VERSION < '2.4'
|
|
209
|
-
# :
|
|
209
|
+
# simplecov:disable
|
|
210
210
|
JSON_PRIMITIVE_WRAPPER_MAPPING[Fixnum] = JSONInteger
|
|
211
211
|
JSON_PRIMITIVE_WRAPPER_MAPPING[Bignum] = JSONInteger
|
|
212
212
|
JSONB_PRIMITIVE_WRAPPER_MAPPING[Fixnum] = JSONBInteger
|
|
213
213
|
JSONB_PRIMITIVE_WRAPPER_MAPPING[Bignum] = JSONBInteger
|
|
214
|
-
# :
|
|
214
|
+
# simplecov:enable
|
|
215
215
|
end
|
|
216
216
|
|
|
217
217
|
JSON_PRIMITIVE_WRAPPER_MAPPING.freeze
|
|
@@ -583,7 +583,7 @@ module Sequel
|
|
|
583
583
|
Database.register_extension(:pg_json, Postgres::JSONDatabaseMethods)
|
|
584
584
|
end
|
|
585
585
|
|
|
586
|
-
# :
|
|
586
|
+
# simplecov:disable
|
|
587
587
|
if Sequel.core_extensions?
|
|
588
588
|
class Array
|
|
589
589
|
# Return a Sequel::Postgres::JSONArray proxy to the receiver.
|
|
@@ -641,4 +641,4 @@ if defined?(Sequel::CoreRefinements)
|
|
|
641
641
|
end
|
|
642
642
|
end
|
|
643
643
|
end
|
|
644
|
-
# :
|
|
644
|
+
# simplecov:enable
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
# j.path_query_first_tz('$.foo') # jsonb_path_query_first_tz(jsonb_column, '$.foo')
|
|
104
104
|
#
|
|
105
105
|
# On PostgreSQL 14+, The JSONB <tt>[]</tt> method will use subscripts instead of being
|
|
106
|
-
# the same as +get+, if the value being wrapped is an
|
|
106
|
+
# the same as +get+, if the value being wrapped is an identifier:
|
|
107
107
|
#
|
|
108
108
|
# Sequel.pg_jsonb_op(:jsonb_column)[1] # jsonb_column[1]
|
|
109
109
|
# Sequel.pg_jsonb_op(:jsonb_column)[1][2] # jsonb_column[1][2]
|
|
@@ -173,7 +173,7 @@
|
|
|
173
173
|
#
|
|
174
174
|
# If you are also using the pg_json extension, you should load it before
|
|
175
175
|
# loading this extension. Doing so will allow you to use the #op method on
|
|
176
|
-
# JSONHash,
|
|
176
|
+
# JSONHash, JSONArray, JSONBHash, and JSONBArray, allowing you to perform json/jsonb operations
|
|
177
177
|
# on json/jsonb literals.
|
|
178
178
|
#
|
|
179
179
|
# In order to get the automatic conversion from a ruby array to a PostgreSQL array
|
|
@@ -843,9 +843,9 @@ module Sequel
|
|
|
843
843
|
|
|
844
844
|
# Wrap argument in a PGArray if it is an array or a set
|
|
845
845
|
def wrap_input_array(obj)
|
|
846
|
-
# :
|
|
846
|
+
# simplecov:disable
|
|
847
847
|
if Sequel.respond_to?(:pg_array)
|
|
848
|
-
# :
|
|
848
|
+
# simplecov:enable
|
|
849
849
|
case obj
|
|
850
850
|
when Array
|
|
851
851
|
return Sequel.pg_array(obj)
|
|
@@ -984,7 +984,8 @@ module Sequel
|
|
|
984
984
|
comma = true
|
|
985
985
|
end
|
|
986
986
|
ds.literal_append(sql, v)
|
|
987
|
-
sql << " AS "
|
|
987
|
+
sql << " AS "
|
|
988
|
+
ds.send(:identifier_append, sql, k)
|
|
988
989
|
end
|
|
989
990
|
end
|
|
990
991
|
end
|
|
@@ -1074,7 +1075,7 @@ module Sequel
|
|
|
1074
1075
|
end
|
|
1075
1076
|
end
|
|
1076
1077
|
|
|
1077
|
-
# Do not auto
|
|
1078
|
+
# Do not auto parameterize default value, as PostgreSQL doesn't allow it.
|
|
1078
1079
|
def default_literal_append(ds, sql, v)
|
|
1079
1080
|
if sql.respond_to?(:skip_auto_param)
|
|
1080
1081
|
sql.skip_auto_param do
|
|
@@ -1254,7 +1255,8 @@ module Sequel
|
|
|
1254
1255
|
comma = true
|
|
1255
1256
|
end
|
|
1256
1257
|
ds.literal_append(sql, v)
|
|
1257
|
-
sql << " AS "
|
|
1258
|
+
sql << " AS "
|
|
1259
|
+
ds.send(:identifier_append, sql, k)
|
|
1258
1260
|
end
|
|
1259
1261
|
end
|
|
1260
1262
|
|
|
@@ -1341,7 +1343,7 @@ module Sequel
|
|
|
1341
1343
|
end
|
|
1342
1344
|
end
|
|
1343
1345
|
|
|
1344
|
-
# Append path
|
|
1346
|
+
# Append path clause to the SQL
|
|
1345
1347
|
def to_s_append_path(ds, sql, path)
|
|
1346
1348
|
if path
|
|
1347
1349
|
sql << ' PATH '
|
|
@@ -1349,7 +1351,7 @@ module Sequel
|
|
|
1349
1351
|
end
|
|
1350
1352
|
end
|
|
1351
1353
|
|
|
1352
|
-
# Do not auto
|
|
1354
|
+
# Do not auto parameterize default value or path value, as PostgreSQL doesn't allow it.
|
|
1353
1355
|
def default_literal_append(ds, sql, v)
|
|
1354
1356
|
if sql.respond_to?(:skip_auto_param)
|
|
1355
1357
|
sql.skip_auto_param do
|
|
@@ -1375,9 +1377,9 @@ module Sequel
|
|
|
1375
1377
|
end
|
|
1376
1378
|
end
|
|
1377
1379
|
|
|
1378
|
-
# :
|
|
1380
|
+
# simplecov:disable
|
|
1379
1381
|
if defined?(JSONArray)
|
|
1380
|
-
# :
|
|
1382
|
+
# simplecov:enable
|
|
1381
1383
|
class JSONArray
|
|
1382
1384
|
# Wrap the JSONArray instance in an JSONOp, allowing you to easily use
|
|
1383
1385
|
# the PostgreSQL json functions and operators with literal jsons.
|
|
@@ -1443,7 +1445,7 @@ module Sequel
|
|
|
1443
1445
|
end
|
|
1444
1446
|
end
|
|
1445
1447
|
|
|
1446
|
-
# :
|
|
1448
|
+
# simplecov:disable
|
|
1447
1449
|
if Sequel.core_extensions?
|
|
1448
1450
|
class Symbol
|
|
1449
1451
|
include Sequel::Postgres::JSONOpMethods
|
|
@@ -1457,4 +1459,4 @@ if defined?(Sequel::CoreRefinements)
|
|
|
1457
1459
|
end
|
|
1458
1460
|
end
|
|
1459
1461
|
end
|
|
1460
|
-
# :
|
|
1462
|
+
# simplecov:enable
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
#
|
|
3
3
|
# The pg_range extension adds support for the PostgreSQL 9.2+ range
|
|
4
4
|
# types to Sequel. PostgreSQL range types are similar to ruby's
|
|
5
|
-
# Range class,
|
|
5
|
+
# Range class, representing an array of values. However, they
|
|
6
6
|
# are more flexible than ruby's ranges, allowing exclusive beginnings
|
|
7
7
|
# and endings (ruby's range only allows exclusive endings).
|
|
8
8
|
#
|
|
9
|
-
# When PostgreSQL range values are
|
|
9
|
+
# When PostgreSQL range values are retrieved, they are parsed and returned
|
|
10
10
|
# as instances of Sequel::Postgres::PGRange. PGRange mostly acts
|
|
11
11
|
# like a Range, but it's not a Range as not all PostgreSQL range
|
|
12
12
|
# type values would be valid ruby ranges. If the range type value
|
|
@@ -459,10 +459,10 @@ module Sequel
|
|
|
459
459
|
return @range if @range
|
|
460
460
|
raise(Error, "cannot create ruby range for an empty PostgreSQL range") if empty?
|
|
461
461
|
raise(Error, "cannot create ruby range when PostgreSQL range excludes beginning element") if exclude_begin?
|
|
462
|
-
# :
|
|
462
|
+
# simplecov:disable
|
|
463
463
|
raise(Error, "cannot create ruby range when PostgreSQL range has unbounded beginning") if STARTLESS_RANGE_NOT_SUPPORTED && !self.begin
|
|
464
464
|
raise(Error, "cannot create ruby range when PostgreSQL range has unbounded ending") if ENDLESS_RANGE_NOT_SUPPORTED && !self.end
|
|
465
|
-
# :
|
|
465
|
+
# simplecov:enable
|
|
466
466
|
@range = Range.new(self.begin, self.end, exclude_end?)
|
|
467
467
|
end
|
|
468
468
|
|
|
@@ -549,7 +549,7 @@ module Sequel
|
|
|
549
549
|
Database.register_extension(:pg_range, Postgres::PGRange::DatabaseMethods)
|
|
550
550
|
end
|
|
551
551
|
|
|
552
|
-
# :
|
|
552
|
+
# simplecov:disable
|
|
553
553
|
if Sequel.core_extensions?
|
|
554
554
|
class Range
|
|
555
555
|
# Create a new PGRange using the receiver as the input range,
|
|
@@ -569,4 +569,4 @@ if defined?(Sequel::CoreRefinements)
|
|
|
569
569
|
end
|
|
570
570
|
end
|
|
571
571
|
end
|
|
572
|
-
# :
|
|
572
|
+
# simplecov:enable
|
|
@@ -113,7 +113,7 @@ module Sequel
|
|
|
113
113
|
|
|
114
114
|
private
|
|
115
115
|
|
|
116
|
-
# Create a
|
|
116
|
+
# Create a boolean expression for the given type and argument.
|
|
117
117
|
def operator(type, other)
|
|
118
118
|
Sequel::SQL::BooleanExpression.new(:NOOP, Sequel::SQL::PlaceholderLiteralString.new(OPERATORS[type], [value, other]))
|
|
119
119
|
end
|
|
@@ -132,9 +132,9 @@ module Sequel
|
|
|
132
132
|
end
|
|
133
133
|
end
|
|
134
134
|
|
|
135
|
-
# :
|
|
135
|
+
# simplecov:disable
|
|
136
136
|
if defined?(PGRange)
|
|
137
|
-
# :
|
|
137
|
+
# simplecov:enable
|
|
138
138
|
class PGRange
|
|
139
139
|
# Wrap the PGRange instance in an RangeOp, allowing you to easily use
|
|
140
140
|
# the PostgreSQL range functions and operators with literal ranges.
|
|
@@ -144,9 +144,9 @@ module Sequel
|
|
|
144
144
|
end
|
|
145
145
|
end
|
|
146
146
|
|
|
147
|
-
# :
|
|
147
|
+
# simplecov:disable
|
|
148
148
|
if defined?(PGMultiRange)
|
|
149
|
-
# :
|
|
149
|
+
# simplecov:enable
|
|
150
150
|
class PGMultiRange
|
|
151
151
|
# Wrap the PGRange instance in an RangeOp, allowing you to easily use
|
|
152
152
|
# the PostgreSQL range functions and operators with literal ranges.
|
|
@@ -178,7 +178,7 @@ module Sequel
|
|
|
178
178
|
end
|
|
179
179
|
end
|
|
180
180
|
|
|
181
|
-
# :
|
|
181
|
+
# simplecov:disable
|
|
182
182
|
if Sequel.core_extensions?
|
|
183
183
|
class Symbol
|
|
184
184
|
include Sequel::Postgres::RangeOpMethods
|
|
@@ -192,4 +192,4 @@ if defined?(Sequel::CoreRefinements)
|
|
|
192
192
|
end
|
|
193
193
|
end
|
|
194
194
|
end
|
|
195
|
-
# :
|
|
195
|
+
# simplecov:enable
|