sequel 5.77.0 → 5.81.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +35 -1
- data/README.rdoc +5 -3
- data/doc/code_order.rdoc +5 -3
- data/doc/dataset_basics.rdoc +1 -1
- data/doc/opening_databases.rdoc +2 -0
- data/doc/querying.rdoc +6 -1
- data/doc/release_notes/5.78.0.txt +67 -0
- data/doc/release_notes/5.79.0.txt +28 -0
- data/doc/release_notes/5.80.0.txt +40 -0
- data/doc/release_notes/5.81.0.txt +31 -0
- data/doc/schema_modification.rdoc +2 -2
- data/lib/sequel/adapters/shared/mssql.rb +29 -1
- data/lib/sequel/adapters/shared/mysql.rb +37 -2
- data/lib/sequel/adapters/shared/postgres.rb +37 -2
- data/lib/sequel/database/misc.rb +1 -0
- data/lib/sequel/database/schema_methods.rb +2 -2
- data/lib/sequel/dataset/dataset_module.rb +1 -1
- data/lib/sequel/dataset/graph.rb +1 -0
- data/lib/sequel/dataset/query.rb +58 -9
- data/lib/sequel/exceptions.rb +5 -0
- data/lib/sequel/extensions/async_thread_pool.rb +7 -0
- data/lib/sequel/extensions/caller_logging.rb +4 -1
- data/lib/sequel/extensions/migration.rb +12 -1
- data/lib/sequel/extensions/provenance.rb +110 -0
- data/lib/sequel/extensions/sqlite_json_ops.rb +76 -18
- data/lib/sequel/extensions/temporarily_release_connection.rb +178 -0
- data/lib/sequel/model/base.rb +1 -1
- data/lib/sequel/plugins/column_encryption.rb +1 -1
- data/lib/sequel/plugins/input_transformer.rb +1 -1
- data/lib/sequel/version.rb +1 -1
- metadata +13 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a23afa1510b7bd1ba6918319eedce156450672520ab4798e6de56461a59660e1
|
4
|
+
data.tar.gz: bb6bbfbf0f1f82fe117fa8c725e9cf4fde49644a74b463ab8682018744a8a1de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e26620f8f1df2715205e9019c2012ec2e9f392d14ed427d66c76f488bccc3e5d3f27e4d626a47d54903d611695db0487f987d99191602024a1864d6c10f7bde
|
7
|
+
data.tar.gz: cd070d8c35960949039d226b5eaf8c90ebec8d0cef3f09b5dae533551bb35170ca6e2503d88f1b1512110b6617ff9c03d9cb2afb62395c4d953314aa5a5ca87c
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,37 @@
|
|
1
|
+
=== 5.81.0 (2024-06-01)
|
2
|
+
|
3
|
+
* Fix ignored block warnings in a couple plugin apply methods on Ruby 3.4 (jeremyevans)
|
4
|
+
|
5
|
+
* Skip Ruby internal caller locations when searching for caller locations in caller_logging and provenance extensions (jeremyevans)
|
6
|
+
|
7
|
+
* Add temporarily_release_connection Database extension for multithreaded transactional testing (jeremyevans)
|
8
|
+
|
9
|
+
=== 5.80.0 (2024-05-01)
|
10
|
+
|
11
|
+
* Support Dataset#skip_locked on MariaDB 10.6+ (simi) (#2150)
|
12
|
+
|
13
|
+
* Avoid allocating datasets in cases where the returned dataset would be the same as the receiver (jeremyevans)
|
14
|
+
|
15
|
+
* Add provenance dataset extension, which includes comments in queries showing how and where the dataset was built (jeremyevans)
|
16
|
+
|
17
|
+
=== 5.79.0 (2024-04-01)
|
18
|
+
|
19
|
+
* Support create_or_replace_view with :materialized option on PostgreSQL (nashby) (#2144)
|
20
|
+
|
21
|
+
* Support :unlogged_tables_default Database option on Postgres for making created tables unlogged by default (jeremyevans) (#2134)
|
22
|
+
|
23
|
+
* Add Dataset#select_prepend for prepending to the current selected columns (jeremyevans) (#2139)
|
24
|
+
|
25
|
+
=== 5.78.0 (2024-03-01)
|
26
|
+
|
27
|
+
* Support SQLite 3.45+ jsonb functions in the sqlite_json_ops extension (jeremyevans) (#2133)
|
28
|
+
|
29
|
+
* Support compounds (e.g. UNION) in conjunction with Database#values on PostgreSQL (jeremyevans) (#2137)
|
30
|
+
|
31
|
+
* Support :use_advisory_lock option to Migrator.run to use advisory locks when running migrations (jeremyevans) (#2089)
|
32
|
+
|
33
|
+
* Support Database#with_advisory_lock on PostgreSQL, MySQL, and Microsoft SQL Server (jeremyevans) (#2089)
|
34
|
+
|
1
35
|
=== 5.77.0 (2024-02-01)
|
2
36
|
|
3
37
|
* Support create_table :without_rowid option on SQLite (loranger32) (#2126)
|
@@ -16,7 +50,7 @@
|
|
16
50
|
|
17
51
|
* Support on_duplicate_columns={raise,warn} parameter in connection URL when using duplicate_columns_handler extension (jeremyevans)
|
18
52
|
|
19
|
-
* Add transaction_connection_validator extension for retrying transactions on new connection if
|
53
|
+
* Add transaction_connection_validator extension for retrying transactions on new connection if there is a disconnect error when starting transaction (jeremyevans)
|
20
54
|
|
21
55
|
=== 5.76.0 (2024-01-01)
|
22
56
|
|
data/README.rdoc
CHANGED
@@ -22,10 +22,10 @@ RDoc Documentation :: https://sequel.jeremyevans.net/rdoc
|
|
22
22
|
Source Code :: https://github.com/jeremyevans/sequel
|
23
23
|
Bug tracking (GitHub Issues) :: https://github.com/jeremyevans/sequel/issues
|
24
24
|
Discussion Forum (GitHub Discussions) :: https://github.com/jeremyevans/sequel/discussions
|
25
|
-
|
25
|
+
Archived Discussion Forum (sequel-talk Google Group) :: https://www.mail-archive.com/sequel-talk@googlegroups.com/
|
26
26
|
|
27
27
|
If you have questions about how to use Sequel, please ask on
|
28
|
-
GitHub Discussions
|
28
|
+
GitHub Discussions.
|
29
29
|
Only use the the bug tracker to report
|
30
30
|
bugs in Sequel, not to ask for help on using Sequel.
|
31
31
|
|
@@ -368,10 +368,12 @@ Like +order+, +select+ overrides an existing selection:
|
|
368
368
|
posts.select(:stamp).select(:name)
|
369
369
|
# SELECT name FROM posts
|
370
370
|
|
371
|
-
As you might expect, there
|
371
|
+
As you might expect, there are +order_append+ and +order_prepend+ equivalents for +select+ called +select_append+ and +select_prepend+:
|
372
372
|
|
373
373
|
posts.select(:stamp).select_append(:name)
|
374
374
|
# SELECT stamp, name FROM posts
|
375
|
+
posts.select(:stamp).select_prepend(:name)
|
376
|
+
# SELECT name, stamp FROM posts
|
375
377
|
|
376
378
|
=== Deleting Records
|
377
379
|
|
data/doc/code_order.rdoc
CHANGED
@@ -91,9 +91,11 @@ unsafe runtime modification of the configuration:
|
|
91
91
|
model_classes.each(&:freeze)
|
92
92
|
DB.freeze
|
93
93
|
|
94
|
-
|
95
|
-
|
96
|
-
|
94
|
+
`model_classes` is not a Sequel method, it indicates an array of model
|
95
|
+
classes you defined. Instead of listing them manually, the `subclasses`
|
96
|
+
plugin can be used to keep track of all model classes that have been
|
97
|
+
setup in your application. Finalizing their associations and freezing
|
98
|
+
them can easily be achieved through the plugin:
|
97
99
|
|
98
100
|
# Register the plugin before setting up the models
|
99
101
|
Sequel::Model.plugin :subclasses
|
data/doc/dataset_basics.rdoc
CHANGED
@@ -65,7 +65,7 @@ Most Dataset methods that users will use can be broken down into two types:
|
|
65
65
|
|
66
66
|
Most dataset methods fall into this category, which can be further broken down by the clause they affect:
|
67
67
|
|
68
|
-
SELECT:: select, select_all, select_append, select_group, select_more
|
68
|
+
SELECT:: select, select_all, select_append, select_group, select_more, select_prepend
|
69
69
|
FROM:: from, from_self
|
70
70
|
JOIN:: join, left_join, right_join, full_join, natural_join, natural_left_join, natural_right_join, natural_full_join, cross_join, inner_join, left_outer_join, right_outer_join, full_outer_join, join_table
|
71
71
|
WHERE:: where, filter, exclude, or, grep, invert, unfiltered
|
data/doc/opening_databases.rdoc
CHANGED
@@ -346,6 +346,8 @@ The following additional options are supported:
|
|
346
346
|
separated by commas (for use via a URL: <tt>postgres:///?search_path=schema1,schema2</tt>), or it
|
347
347
|
can be an array of strings (for use via an option:
|
348
348
|
<tt>Sequel.postgres(search_path: ['schema1', 'schema2'])</tt>).
|
349
|
+
:unlogged_tables_default :: Set to true to use UNLOGGED by default for created tables, for potentially better performance
|
350
|
+
when data integrity is not important.
|
349
351
|
:use_iso_date_format :: This can be set to false to not force the ISO date format. Sequel forces
|
350
352
|
it by default to allow for an optimization.
|
351
353
|
|
data/doc/querying.rdoc
CHANGED
@@ -624,11 +624,16 @@ Like +order+, +select+ replaces the existing selected columns:
|
|
624
624
|
Artist.select(:id).select(:name)
|
625
625
|
# SELECT name FROM artists
|
626
626
|
|
627
|
-
To
|
627
|
+
To append to the existing selected columns, use +select_append+:
|
628
628
|
|
629
629
|
Artist.select(:id).select_append(:name)
|
630
630
|
# SELECT id, name FROM artists
|
631
631
|
|
632
|
+
To prepend to the existing selected columns, use +select_prepend+:
|
633
|
+
|
634
|
+
Artist.select(:id).select_prepend(:name)
|
635
|
+
# SELECT name, id FROM artists
|
636
|
+
|
632
637
|
To remove specifically selected columns, and default back to all
|
633
638
|
columns, use +select_all+:
|
634
639
|
|
@@ -0,0 +1,67 @@
|
|
1
|
+
= New Features
|
2
|
+
|
3
|
+
* SQLite 3.45+ jsonb functions are now supported in the sqlite_json_ops
|
4
|
+
extension. Similar to the postgres_json_ops extension, there are
|
5
|
+
now separate methods for dealing with json and jsonb types:
|
6
|
+
|
7
|
+
Sequel.sqlite_json_op(:column) # json
|
8
|
+
Sequel.sqlite_jsonb_op(:column) # jsonb
|
9
|
+
|
10
|
+
Some methods that use json_* functions for json ops use jsonb_*
|
11
|
+
functions for jsonb ops:
|
12
|
+
|
13
|
+
jb = Sequel.sqlite_jsonb_op(:column)
|
14
|
+
jb.extract('$.a') # jsonb_extract(column, '$.a')
|
15
|
+
jb.insert('$.a', 1) # jsonb_insert(column, '$.a', 1)
|
16
|
+
jb.set('$.a', 1) # jsonb_set(column, '$.a', 1)
|
17
|
+
jb.replace('$.a', 1) # jsonb_replace(column, '$.a', 1)
|
18
|
+
jb.remove('$.a') # jsonb_remove(column, '$.a')
|
19
|
+
jb.patch('{"a":2}') # jsonb_patch(column, '{"a":2}')
|
20
|
+
|
21
|
+
You can use the json and jsonb methods to convert jsonb to json
|
22
|
+
and json to jsonb, respectively.
|
23
|
+
|
24
|
+
jb.json # json(column)
|
25
|
+
|
26
|
+
Use of the json method on jsonb types is important, because if you
|
27
|
+
want to be able to deal with the values in Ruby, you must convert
|
28
|
+
the jsonb value to json in the database before the database returns
|
29
|
+
the value. Unlike PostgreSQL, SQLite will not convert the value
|
30
|
+
from jsonb to json on retrieval, and direct use of SQLite's jsonb
|
31
|
+
format is unsupported by SQLite as it is subject to change.
|
32
|
+
|
33
|
+
* Database#with_advisory_lock is now supported on PostgreSQL, MySQL,
|
34
|
+
and Microsoft SQL Server. This supports advisory (explicit)
|
35
|
+
locking, using the database-specific APIs. To work on all three
|
36
|
+
servers, lock ids should be integers in the signed 64-bit range.
|
37
|
+
|
38
|
+
DB.with_advisory_lock(1234) do
|
39
|
+
# do something
|
40
|
+
end
|
41
|
+
|
42
|
+
By default, an AdvisoryLockError is raised if the lock cannot be
|
43
|
+
immediately acquired. You can use the :wait option to wait until
|
44
|
+
the lock can be acquired, instead of raising.
|
45
|
+
|
46
|
+
DB.with_advisory_lock(1234, wait: true) do
|
47
|
+
# do something
|
48
|
+
end
|
49
|
+
|
50
|
+
* Migrator.run now supports a :use_advisory_lock option to use
|
51
|
+
advisory locks when running migrations, so that it does not
|
52
|
+
attempt to run the same migration more than once in the case
|
53
|
+
where multiple processes are running the migrator simultaneously.
|
54
|
+
It's probably best to avoid running the migrator in multiple
|
55
|
+
processes simultaneously instead of relying on this option.
|
56
|
+
|
57
|
+
= Other Improvements
|
58
|
+
|
59
|
+
* Database#values now supports chaining with compounds on
|
60
|
+
PostgreSQL.
|
61
|
+
|
62
|
+
DB.values([[1, 2]]).union(DB.values([[3, 4]]))
|
63
|
+
# SELECT * FROM (VALUES (1, 2) UNION (VALUES (3, 4))) AS t1
|
64
|
+
|
65
|
+
* The internal hash used to store transaction metadata now uses
|
66
|
+
compare_by_identity, which is faster and avoids potential
|
67
|
+
issues if a driver implements connection object equality.
|
@@ -0,0 +1,28 @@
|
|
1
|
+
= New Features
|
2
|
+
|
3
|
+
* Dataset#select_prepend has been added for prepending to the
|
4
|
+
currently selected columns:
|
5
|
+
|
6
|
+
DB[:table].select_prepend(:column)
|
7
|
+
# SELECT column, table.*
|
8
|
+
|
9
|
+
As not all databases support "SELECT column, *", select_prepend
|
10
|
+
qualifies wildcard selections to all tables referenced in the
|
11
|
+
query.
|
12
|
+
|
13
|
+
The only reason to use select_prepend is if you want the hashes
|
14
|
+
returned by Sequel to be in a specific order. Otherwise, it is
|
15
|
+
better to use select_append.
|
16
|
+
|
17
|
+
* On PostgreSQL, Sequel now supports an :unlogged_tables_default
|
18
|
+
Database option, which will default created tables to be UNLOGGED.
|
19
|
+
This can be useful to speedup testing in some cases, but it should
|
20
|
+
never be used in cases where data integrity is important.
|
21
|
+
|
22
|
+
= Other Improvements
|
23
|
+
|
24
|
+
* On PostgreSQL, Database#create_or_replace_view now supports the
|
25
|
+
:materialized option. This allows for dropping an existing
|
26
|
+
materialized view and creating a new one with the same name
|
27
|
+
(PostgreSQL does not have native support for replacing materialized
|
28
|
+
views).
|
@@ -0,0 +1,40 @@
|
|
1
|
+
= New Features
|
2
|
+
|
3
|
+
* A provenance dataset extension has been added. This extension makes
|
4
|
+
SQL queries include a comment describing how the dataset was built.
|
5
|
+
This can make debugging complex cases significantly easier. Here's
|
6
|
+
a simple example:
|
7
|
+
|
8
|
+
DB.extension :provenance
|
9
|
+
|
10
|
+
DB[:table].
|
11
|
+
select(:a).
|
12
|
+
where{b > 10}.
|
13
|
+
order(:c).
|
14
|
+
limit(10)
|
15
|
+
# SQL:
|
16
|
+
# SELECT a FROM table WHERE (b > 10) ORDER BY c LIMIT 10 --
|
17
|
+
# -- Dataset Provenance
|
18
|
+
# -- Keys:[:from] Source:(eval at bin/sequel:257):2:in `<main>'
|
19
|
+
# -- Keys:[:select] Source:(eval at bin/sequel:257):3:in `<main>'
|
20
|
+
# -- Keys:[:where] Source:(eval at bin/sequel:257):4:in `<main>'
|
21
|
+
# -- Keys:[:order] Source:(eval at bin/sequel:257):5:in `<main>'
|
22
|
+
# -- Keys:[:limit] Source:(eval at bin/sequel:257):6:in `<main>'
|
23
|
+
|
24
|
+
With the above example, it's obvious how the dataset is created, but
|
25
|
+
but in real applications, where datasets can be built from multiple
|
26
|
+
files, seeing where each dataset clone was made can be helpful.
|
27
|
+
|
28
|
+
The source listed will skip locations in the Ruby standard library
|
29
|
+
as well as Sequel itself. Other locations can be skipped by
|
30
|
+
providing a Database :provenance_caller_ignore Regexp option:
|
31
|
+
|
32
|
+
DB.opts[:provenance_caller_ignore] = /\/gems\/library_name-/
|
33
|
+
|
34
|
+
= Other Improvements
|
35
|
+
|
36
|
+
* For dataset methods where Sequel can determine that the return
|
37
|
+
value would be equivalent to the receiver, Sequel now returns the
|
38
|
+
receiver. This reduces the number of dataset allocations.
|
39
|
+
|
40
|
+
* Sequel now supports Dataset#skip_locked on MariaDB 10.6+.
|
@@ -0,0 +1,31 @@
|
|
1
|
+
= New Features
|
2
|
+
|
3
|
+
* A temporarily_release_connection Database extension has been added,
|
4
|
+
designed for multithreaded transactional testing.
|
5
|
+
|
6
|
+
This allows one thread to start a transaction, and then release
|
7
|
+
the connection back for usage by the connection pool, so that
|
8
|
+
other threads can operate on the connection object safely inside
|
9
|
+
the transaction. This requires the connection pool be limited
|
10
|
+
to a single connection, to ensure that the released connection
|
11
|
+
can be reacquired. It's not perfect, because if the connection
|
12
|
+
is disconnected and removed from the pool while temporarily
|
13
|
+
released, there is no way to handle that situation correctly.
|
14
|
+
Example:
|
15
|
+
|
16
|
+
DB.transaction(rollback: :always, auto_savepoint: true) do |conn|
|
17
|
+
DB.temporarily_release_connection(conn) do
|
18
|
+
# Other threads can operate on connection safely inside
|
19
|
+
# the transaction
|
20
|
+
yield
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
= Other Improvements
|
25
|
+
|
26
|
+
* In the caller_logging and provenance extensions, Ruby internal
|
27
|
+
caller locations are skipped when trying to locate the appropriate
|
28
|
+
caller line to include.
|
29
|
+
|
30
|
+
* A couple ignored block warnings in plugin apply methods have been
|
31
|
+
fixed on Ruby 3.4.
|
@@ -81,8 +81,8 @@ appropriate 64-bit integer type for the database you are using.
|
|
81
81
|
|
82
82
|
=== Column options
|
83
83
|
|
84
|
-
When using the type name as method, the
|
85
|
-
method, the
|
84
|
+
When using the type name as method, the second argument is an options hash, and when using the +column+
|
85
|
+
method, the third argument is the options hash. The following options are supported:
|
86
86
|
|
87
87
|
:default :: The default value for the column.
|
88
88
|
:index :: Create an index on this column. If given a hash, use the hash as the
|
@@ -32,7 +32,7 @@ module Sequel
|
|
32
32
|
#
|
33
33
|
# Options:
|
34
34
|
# :args :: Arguments to stored procedure. For named arguments, this should be a
|
35
|
-
# hash keyed by argument
|
35
|
+
# hash keyed by argument name. For unnamed arguments, this should be an
|
36
36
|
# array. Output parameters to the function are specified using :output.
|
37
37
|
# You can also name output parameters and provide a type by using an
|
38
38
|
# array containing :output, the type name, and the parameter name.
|
@@ -246,6 +246,34 @@ module Sequel
|
|
246
246
|
information_schema_tables('VIEW', opts)
|
247
247
|
end
|
248
248
|
|
249
|
+
# Attempt to acquire an exclusive advisory lock with the given lock_id (which will
|
250
|
+
# be converted to a string). If successful, yield to the block, then release the advisory lock
|
251
|
+
# when the block exits. If unsuccessful, raise a Sequel::AdvisoryLockError.
|
252
|
+
#
|
253
|
+
# Options:
|
254
|
+
# :wait :: Do not raise an error, instead, wait until the advisory lock can be acquired.
|
255
|
+
def with_advisory_lock(lock_id, opts=OPTS)
|
256
|
+
lock_id = lock_id.to_s
|
257
|
+
timeout = opts[:wait] ? -1 : 0
|
258
|
+
server = opts[:server]
|
259
|
+
|
260
|
+
synchronize(server) do
|
261
|
+
begin
|
262
|
+
res = call_mssql_sproc(:sp_getapplock, :server=>server, :args=>{'Resource'=>lock_id, 'LockTimeout'=>timeout, 'LockMode'=>'Exclusive', 'LockOwner'=>'Session'})
|
263
|
+
|
264
|
+
unless locked = res[:result] >= 0
|
265
|
+
raise AdvisoryLockError, "unable to acquire advisory lock #{lock_id.inspect}"
|
266
|
+
end
|
267
|
+
|
268
|
+
yield
|
269
|
+
ensure
|
270
|
+
if locked
|
271
|
+
call_mssql_sproc(:sp_releaseapplock, :server=>server, :args=>{'Resource'=>lock_id, 'LockOwner'=>'Session'})
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
249
277
|
private
|
250
278
|
|
251
279
|
# Add CLUSTERED or NONCLUSTERED as needed
|
@@ -197,6 +197,41 @@ module Sequel
|
|
197
197
|
renames.each{|from,| remove_cached_schema(from)}
|
198
198
|
end
|
199
199
|
|
200
|
+
# Attempt to acquire an exclusive advisory lock with the given lock_id (which will be
|
201
|
+
# converted to a string). If successful, yield to the block, then release the advisory lock
|
202
|
+
# when the block exits. If unsuccessful, raise a Sequel::AdvisoryLockError.
|
203
|
+
#
|
204
|
+
# DB.with_advisory_lock(1357){DB.get(1)}
|
205
|
+
# # SELECT GET_LOCK('1357', 0) LIMIT 1
|
206
|
+
# # SELECT 1 AS v LIMIT 1
|
207
|
+
# # SELECT RELEASE_LOCK('1357') LIMIT 1
|
208
|
+
#
|
209
|
+
# Options:
|
210
|
+
# :wait :: Do not raise an error, instead, wait until the advisory lock can be acquired.
|
211
|
+
def with_advisory_lock(lock_id, opts=OPTS)
|
212
|
+
lock_id = lock_id.to_s
|
213
|
+
ds = dataset
|
214
|
+
if server = opts[:server]
|
215
|
+
ds = ds.server(server)
|
216
|
+
end
|
217
|
+
|
218
|
+
# MariaDB doesn't support negative values for infinite wait. A wait of 34 years
|
219
|
+
# should be reasonably similar to infinity for this case.
|
220
|
+
timeout = opts[:wait] ? 1073741823 : 0
|
221
|
+
|
222
|
+
synchronize(server) do |c|
|
223
|
+
begin
|
224
|
+
unless locked = ds.get{GET_LOCK(lock_id, timeout)} == 1
|
225
|
+
raise AdvisoryLockError, "unable to acquire advisory lock #{lock_id.inspect}"
|
226
|
+
end
|
227
|
+
|
228
|
+
yield
|
229
|
+
ensure
|
230
|
+
ds.get{RELEASE_LOCK(lock_id)} if locked
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
200
235
|
private
|
201
236
|
|
202
237
|
def alter_table_add_column_sql(table, op)
|
@@ -891,9 +926,9 @@ module Sequel
|
|
891
926
|
(type == :insert && db.mariadb? && db.adapter_scheme != :jdbc) ? (db.server_version >= 100500) : false
|
892
927
|
end
|
893
928
|
|
894
|
-
# MySQL 8+
|
929
|
+
# MySQL 8+ and MariaDB 10.6+ support SKIP LOCKED.
|
895
930
|
def supports_skip_locked?
|
896
|
-
|
931
|
+
db.server_version >= (db.mariadb? ? 100600 : 80000)
|
897
932
|
end
|
898
933
|
|
899
934
|
# Check the database setting for whether fractional timestamps
|
@@ -859,6 +859,41 @@ module Sequel
|
|
859
859
|
pg_class_relname(relkind, opts)
|
860
860
|
end
|
861
861
|
|
862
|
+
# Attempt to acquire an exclusive advisory lock with the given lock_id (which should be
|
863
|
+
# a 64-bit integer). If successful, yield to the block, then release the advisory lock
|
864
|
+
# when the block exits. If unsuccessful, raise a Sequel::AdvisoryLockError.
|
865
|
+
#
|
866
|
+
# DB.with_advisory_lock(1347){DB.get(1)}
|
867
|
+
# # SELECT pg_try_advisory_lock(1357) LIMIT 1
|
868
|
+
# # SELECT 1 AS v LIMIT 1
|
869
|
+
# # SELECT pg_advisory_unlock(1357) LIMIT 1
|
870
|
+
#
|
871
|
+
# Options:
|
872
|
+
# :wait :: Do not raise an error, instead, wait until the advisory lock can be acquired.
|
873
|
+
def with_advisory_lock(lock_id, opts=OPTS)
|
874
|
+
ds = dataset
|
875
|
+
if server = opts[:server]
|
876
|
+
ds = ds.server(server)
|
877
|
+
end
|
878
|
+
|
879
|
+
synchronize(server) do |c|
|
880
|
+
begin
|
881
|
+
if opts[:wait]
|
882
|
+
ds.get{pg_advisory_lock(lock_id)}
|
883
|
+
locked = true
|
884
|
+
else
|
885
|
+
unless locked = ds.get{pg_try_advisory_lock(lock_id)}
|
886
|
+
raise AdvisoryLockError, "unable to acquire advisory lock #{lock_id.inspect}"
|
887
|
+
end
|
888
|
+
end
|
889
|
+
|
890
|
+
yield
|
891
|
+
ensure
|
892
|
+
ds.get{pg_advisory_unlock(lock_id)} if locked
|
893
|
+
end
|
894
|
+
end
|
895
|
+
end
|
896
|
+
|
862
897
|
private
|
863
898
|
|
864
899
|
# Dataset used to retrieve CHECK constraint information
|
@@ -1390,7 +1425,7 @@ module Sequel
|
|
1390
1425
|
elsif options[:foreign]
|
1391
1426
|
raise(Error, "can't provide both :foreign and :unlogged to create_table") if options[:unlogged]
|
1392
1427
|
'FOREIGN '
|
1393
|
-
elsif options[:
|
1428
|
+
elsif options.fetch(:unlogged){typecast_value_boolean(@opts[:unlogged_tables_default])}
|
1394
1429
|
'UNLOGGED '
|
1395
1430
|
end
|
1396
1431
|
|
@@ -1785,7 +1820,7 @@ module Sequel
|
|
1785
1820
|
|
1786
1821
|
Dataset.def_sql_method(self, :delete, [['if server_version >= 90100', %w'with delete from using where returning'], ['else', %w'delete from using where returning']])
|
1787
1822
|
Dataset.def_sql_method(self, :insert, [['if server_version >= 90500', %w'with insert into columns override values conflict returning'], ['elsif server_version >= 90100', %w'with insert into columns values returning'], ['else', %w'insert into columns values returning']])
|
1788
|
-
Dataset.def_sql_method(self, :select, [['if opts[:values]', %w'values order limit'], ['elsif server_version >= 80400', %w'with select distinct columns from join where group having window compounds order limit lock'], ['else', %w'select distinct columns from join where group having compounds order limit lock']])
|
1823
|
+
Dataset.def_sql_method(self, :select, [['if opts[:values]', %w'values compounds order limit'], ['elsif server_version >= 80400', %w'with select distinct columns from join where group having window compounds order limit lock'], ['else', %w'select distinct columns from join where group having compounds order limit lock']])
|
1789
1824
|
Dataset.def_sql_method(self, :update, [['if server_version >= 90100', %w'with update table set from where returning'], ['else', %w'update table set from where returning']])
|
1790
1825
|
|
1791
1826
|
# Return the results of an EXPLAIN ANALYZE query as a string
|
data/lib/sequel/database/misc.rb
CHANGED
@@ -252,10 +252,10 @@ module Sequel
|
|
252
252
|
# For databases where replacing a view is not natively supported, support
|
253
253
|
# is emulated by dropping a view with the same name before creating the view.
|
254
254
|
def create_or_replace_view(name, source, options = OPTS)
|
255
|
-
if supports_create_or_replace_view?
|
255
|
+
if supports_create_or_replace_view? && !options[:materialized]
|
256
256
|
options = options.merge(:replace=>true)
|
257
257
|
else
|
258
|
-
swallow_database_error{drop_view(name)}
|
258
|
+
swallow_database_error{drop_view(name, options)}
|
259
259
|
end
|
260
260
|
|
261
261
|
create_view(name, source, options)
|
@@ -21,7 +21,7 @@ module Sequel
|
|
21
21
|
where exclude exclude_having having
|
22
22
|
distinct grep group group_and_count group_append
|
23
23
|
limit offset order order_append order_prepend reverse
|
24
|
-
select select_all select_append select_group server
|
24
|
+
select select_all select_append select_group select_prepend server
|
25
25
|
METHS
|
26
26
|
|
27
27
|
# Define a method in the module
|
data/lib/sequel/dataset/graph.rb
CHANGED