sequel 5.55.0 → 5.58.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +24 -0
- data/README.rdoc +25 -0
- data/doc/cheat_sheet.rdoc +8 -0
- data/doc/opening_databases.rdoc +6 -1
- data/doc/release_notes/5.56.0.txt +51 -0
- data/doc/release_notes/5.57.0.txt +23 -0
- data/doc/release_notes/5.58.0.txt +31 -0
- data/doc/testing.rdoc +1 -1
- data/lib/sequel/adapters/jdbc/derby.rb +5 -0
- data/lib/sequel/adapters/jdbc/h2.rb +5 -0
- data/lib/sequel/adapters/jdbc/hsqldb.rb +6 -0
- data/lib/sequel/adapters/shared/db2.rb +28 -0
- data/lib/sequel/adapters/shared/mssql.rb +34 -0
- data/lib/sequel/adapters/shared/mysql.rb +12 -0
- data/lib/sequel/adapters/shared/oracle.rb +69 -0
- data/lib/sequel/adapters/shared/postgres.rb +60 -3
- data/lib/sequel/adapters/shared/sqlite.rb +6 -0
- data/lib/sequel/database/schema_generator.rb +9 -5
- data/lib/sequel/database/schema_methods.rb +9 -0
- data/lib/sequel/dataset/actions.rb +49 -0
- data/lib/sequel/dataset/features.rb +5 -0
- data/lib/sequel/dataset/query.rb +62 -0
- data/lib/sequel/dataset/sql.rb +112 -25
- data/lib/sequel/extensions/is_distinct_from.rb +139 -0
- data/lib/sequel/extensions/pg_hstore.rb +1 -1
- data/lib/sequel/extensions/pg_json_ops.rb +2 -1
- data/lib/sequel/extensions/schema_dumper.rb +2 -2
- data/lib/sequel/extensions/sqlite_json_ops.rb +255 -0
- data/lib/sequel/plugins/insert_conflict.rb +4 -0
- data/lib/sequel/plugins/instance_specific_default.rb +1 -1
- data/lib/sequel/version.rb +1 -1
- metadata +13 -19
@@ -0,0 +1,255 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
#
|
3
|
+
# The sqlite_json_ops extension adds support to Sequel's DSL to make
|
4
|
+
# it easier to call SQLite JSON functions and operators (added
|
5
|
+
# first in SQLite 3.38.0).
|
6
|
+
#
|
7
|
+
# To load the extension:
|
8
|
+
#
|
9
|
+
# Sequel.extension :sqlite_json_ops
|
10
|
+
#
|
11
|
+
# This extension works by calling methods on Sequel::SQLite::JSONOp objects,
|
12
|
+
# which you can create via Sequel.sqlite_json_op:
|
13
|
+
#
|
14
|
+
# j = Sequel.sqlite_json_op(:json_column)
|
15
|
+
#
|
16
|
+
# Also, on most Sequel expression objects, you can call the sqlite_json_op method
|
17
|
+
# to create a Sequel::SQLite::JSONOp object:
|
18
|
+
#
|
19
|
+
# j = Sequel[:json_column].sqlite_json_op
|
20
|
+
#
|
21
|
+
# If you have loaded the {core_extensions extension}[rdoc-ref:doc/core_extensions.rdoc],
|
22
|
+
# or you have loaded the core_refinements extension
|
23
|
+
# and have activated refinements for the file, you can also use Symbol#sqlite_json_op:
|
24
|
+
#
|
25
|
+
# j = :json_column.sqlite_json_op
|
26
|
+
#
|
27
|
+
# The following methods are available for Sequel::SQLite::JSONOp instances:
|
28
|
+
#
|
29
|
+
# j[1] # (json_column ->> 1)
|
30
|
+
# j.get(1) # (json_column ->> 1)
|
31
|
+
# j.get_text(1) # (json_column -> 1)
|
32
|
+
# j.extract('$.a') # json_extract(json_column, '$.a')
|
33
|
+
#
|
34
|
+
# j.array_length # json_array_length(json_column)
|
35
|
+
# j.type # json_type(json_column)
|
36
|
+
# j.valid # json_valid(json_column)
|
37
|
+
# j.json # json(json_column)
|
38
|
+
#
|
39
|
+
# j.insert('$.a', 1) # json_insert(json_column, '$.a', 1)
|
40
|
+
# j.set('$.a', 1) # json_set(json_column, '$.a', 1)
|
41
|
+
# j.replace('$.a', 1) # json_replace(json_column, '$.a', 1)
|
42
|
+
# j.remove('$.a') # json_remove(json_column, '$.a')
|
43
|
+
# j.patch('{"a":2}') # json_patch(json_column, '{"a":2}')
|
44
|
+
#
|
45
|
+
# j.each # json_each(json_column)
|
46
|
+
# j.tree # json_tree(json_column)
|
47
|
+
#
|
48
|
+
# Related modules: Sequel::SQLite::JSONOp
|
49
|
+
|
50
|
+
#
|
51
|
+
module Sequel
|
52
|
+
module SQLite
|
53
|
+
# The JSONOp class is a simple container for a single object that
|
54
|
+
# defines methods that yield Sequel expression objects representing
|
55
|
+
# SQLite json operators and functions.
|
56
|
+
#
|
57
|
+
# In the method documentation examples, assume that:
|
58
|
+
#
|
59
|
+
# json_op = Sequel.sqlite_json_op(:json)
|
60
|
+
class JSONOp < Sequel::SQL::Wrapper
|
61
|
+
GET = ["(".freeze, " ->> ".freeze, ")".freeze].freeze
|
62
|
+
private_constant :GET
|
63
|
+
|
64
|
+
GET_JSON = ["(".freeze, " -> ".freeze, ")".freeze].freeze
|
65
|
+
private_constant :GET_JSON
|
66
|
+
|
67
|
+
# Returns an expression for getting the JSON array element or object field
|
68
|
+
# at the specified path as a SQLite value.
|
69
|
+
#
|
70
|
+
# json_op[1] # (json ->> 1)
|
71
|
+
# json_op['a'] # (json ->> 'a')
|
72
|
+
# json_op['$.a.b'] # (json ->> '$.a.b')
|
73
|
+
# json_op['$[1][2]'] # (json ->> '$[1][2]')
|
74
|
+
def [](key)
|
75
|
+
json_op(GET, key)
|
76
|
+
end
|
77
|
+
alias get []
|
78
|
+
|
79
|
+
# Returns an expression for the length of the JSON array, or the JSON array at
|
80
|
+
# the given path.
|
81
|
+
#
|
82
|
+
# json_op.array_length # json_array_length(json)
|
83
|
+
# json_op.array_length('$[1]') # json_array_length(json, '$[1]')
|
84
|
+
def array_length(*args)
|
85
|
+
Sequel::SQL::NumericExpression.new(:NOOP, function(:array_length, *args))
|
86
|
+
end
|
87
|
+
|
88
|
+
# Returns an expression for a set of information extracted from the top-level
|
89
|
+
# members of the JSON array or object, or the top-level members of the JSON array
|
90
|
+
# or object at the given path.
|
91
|
+
#
|
92
|
+
# json_op.each # json_each(json)
|
93
|
+
# json_op.each('$.a') # json_each(json, '$.a')
|
94
|
+
def each(*args)
|
95
|
+
function(:each, *args)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Returns an expression for the JSON array element or object field at the specified
|
99
|
+
# path as a SQLite value, but only accept paths as arguments, and allow the use of
|
100
|
+
# multiple paths.
|
101
|
+
#
|
102
|
+
# json_op.extract('$.a') # json_extract(json, '$.a')
|
103
|
+
# json_op.extract('$.a', '$.b') # json_extract(json, '$.a', '$.b')
|
104
|
+
def extract(*a)
|
105
|
+
function(:extract, *a)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Returns an expression for getting the JSON array element or object field at the
|
109
|
+
# specified path as a JSON value.
|
110
|
+
#
|
111
|
+
# json_op.get_json(1) # (json -> 1)
|
112
|
+
# json_op.get_json('a') # (json -> 'a')
|
113
|
+
# json_op.get_json('$.a.b') # (json -> '$.a.b')
|
114
|
+
# json_op.get_json('$[1][2]') # (json -> '$[1][2]')
|
115
|
+
def get_json(key)
|
116
|
+
self.class.new(json_op(GET_JSON, key))
|
117
|
+
end
|
118
|
+
|
119
|
+
# Returns an expression for creating new entries at the given paths in the JSON array
|
120
|
+
# or object, but not overwriting existing entries.
|
121
|
+
#
|
122
|
+
# json_op.insert('$.a', 1) # json_insert(json, '$.a', 1)
|
123
|
+
# json_op.insert('$.a', 1, '$.b', 2) # json_insert(json, '$.a', 1, '$.b', 2)
|
124
|
+
def insert(path, value, *args)
|
125
|
+
wrapped_function(:insert, path, value, *args)
|
126
|
+
end
|
127
|
+
|
128
|
+
# Returns an expression for a minified version of the JSON.
|
129
|
+
#
|
130
|
+
# json_op.json # json(json)
|
131
|
+
def json
|
132
|
+
self.class.new(SQL::Function.new(:json, self))
|
133
|
+
end
|
134
|
+
alias minify json
|
135
|
+
|
136
|
+
# Returns an expression for updating the JSON object using the RFC 7396 MergePatch algorithm
|
137
|
+
#
|
138
|
+
# json_op.patch('{"a": 1, "b": null}') # json_patch(json, '{"a": 1, "b": null}')
|
139
|
+
def patch(json_patch)
|
140
|
+
wrapped_function(:patch, json_patch)
|
141
|
+
end
|
142
|
+
|
143
|
+
# Returns an expression for removing entries at the given paths from the JSON array or object.
|
144
|
+
#
|
145
|
+
# json_op.remove('$.a') # json_remove(json, '$.a')
|
146
|
+
# json_op.remove('$.a', '$.b') # json_remove(json, '$.a', '$.b')
|
147
|
+
def remove(path, *paths)
|
148
|
+
wrapped_function(:remove, path, *paths)
|
149
|
+
end
|
150
|
+
|
151
|
+
# Returns an expression for replacing entries at the given paths in the JSON array or object,
|
152
|
+
# but not creating new entries.
|
153
|
+
#
|
154
|
+
# json_op.replace('$.a', 1) # json_replace(json, '$.a', 1)
|
155
|
+
# json_op.replace('$.a', 1, '$.b', 2) # json_replace(json, '$.a', 1, '$.b', 2)
|
156
|
+
def replace(path, value, *args)
|
157
|
+
wrapped_function(:replace, path, value, *args)
|
158
|
+
end
|
159
|
+
|
160
|
+
# Returns an expression for creating or replacing entries at the given paths in the
|
161
|
+
# JSON array or object.
|
162
|
+
#
|
163
|
+
# json_op.set('$.a', 1) # json_set(json, '$.a', 1)
|
164
|
+
# json_op.set('$.a', 1, '$.b', 2) # json_set(json, '$.a', 1, '$.b', 2)
|
165
|
+
def set(path, value, *args)
|
166
|
+
wrapped_function(:set, path, value, *args)
|
167
|
+
end
|
168
|
+
|
169
|
+
# Returns an expression for a set of information extracted from the JSON array or object, or
|
170
|
+
# the JSON array or object at the given path.
|
171
|
+
#
|
172
|
+
# json_op.tree # json_tree(json)
|
173
|
+
# json_op.tree('$.a') # json_tree(json, '$.a')
|
174
|
+
def tree(*args)
|
175
|
+
function(:tree, *args)
|
176
|
+
end
|
177
|
+
|
178
|
+
# Returns an expression for the type of the JSON value or the JSON value at the given path.
|
179
|
+
#
|
180
|
+
# json_op.type # json_type(json)
|
181
|
+
# json_op.type('$[1]') # json_type(json, '$[1]')
|
182
|
+
def type(*args)
|
183
|
+
Sequel::SQL::StringExpression.new(:NOOP, function(:type, *args))
|
184
|
+
end
|
185
|
+
alias typeof type
|
186
|
+
|
187
|
+
# Returns a boolean expression for whether the JSON is valid or not.
|
188
|
+
def valid
|
189
|
+
Sequel::SQL::BooleanExpression.new(:NOOP, function(:valid))
|
190
|
+
end
|
191
|
+
|
192
|
+
private
|
193
|
+
|
194
|
+
# Internals of the [], get, get_json methods, using a placeholder literal string.
|
195
|
+
def json_op(str, args)
|
196
|
+
self.class.new(Sequel::SQL::PlaceholderLiteralString.new(str, [self, args]))
|
197
|
+
end
|
198
|
+
|
199
|
+
# Internals of the methods that return functions prefixed with +json_+.
|
200
|
+
def function(name, *args)
|
201
|
+
SQL::Function.new("json_#{name}", self, *args)
|
202
|
+
end
|
203
|
+
|
204
|
+
# Internals of the methods that return functions prefixed with +json_+, that
|
205
|
+
# return JSON values.
|
206
|
+
def wrapped_function(*args)
|
207
|
+
self.class.new(function(*args))
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
module JSONOpMethods
|
212
|
+
# Wrap the receiver in an JSONOp so you can easily use the SQLite
|
213
|
+
# json functions and operators with it.
|
214
|
+
def sqlite_json_op
|
215
|
+
JSONOp.new(self)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
module SQL::Builders
|
221
|
+
# Return the object wrapped in an SQLite::JSONOp.
|
222
|
+
def sqlite_json_op(v)
|
223
|
+
case v
|
224
|
+
when SQLite::JSONOp
|
225
|
+
v
|
226
|
+
else
|
227
|
+
SQLite::JSONOp.new(v)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
class SQL::GenericExpression
|
233
|
+
include Sequel::SQLite::JSONOpMethods
|
234
|
+
end
|
235
|
+
|
236
|
+
class LiteralString
|
237
|
+
include Sequel::SQLite::JSONOpMethods
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
# :nocov:
|
242
|
+
if Sequel.core_extensions?
|
243
|
+
class Symbol
|
244
|
+
include Sequel::SQLite::JSONOpMethods
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
if defined?(Sequel::CoreRefinements)
|
249
|
+
module Sequel::CoreRefinements
|
250
|
+
refine Symbol do
|
251
|
+
send INCLUDE_METH, Sequel::SQLite::JSONOpMethods
|
252
|
+
end
|
253
|
+
end
|
254
|
+
end
|
255
|
+
# :nocov:
|
@@ -22,6 +22,10 @@ module Sequel
|
|
22
22
|
# for that album. See the PostgreSQL and SQLite adapter documention for
|
23
23
|
# the options you can pass to the insert_conflict method.
|
24
24
|
#
|
25
|
+
# You should not attempt to use this plugin to ignore conflicts when
|
26
|
+
# inserting, you should only use it to turn insert conflicts into updates.
|
27
|
+
# Any usage to ignore conflicts is not recommended or supported.
|
28
|
+
#
|
25
29
|
# Usage:
|
26
30
|
#
|
27
31
|
# # Make all model subclasses support insert_conflict
|
@@ -29,7 +29,7 @@ module Sequel
|
|
29
29
|
# end
|
30
30
|
#
|
31
31
|
# +first_track+ is not instance specific, but +last_track+ and +recent_tracks+ are.
|
32
|
-
# +
|
32
|
+
# +last_track+ is because the +num_tracks+ call in the block is calling
|
33
33
|
# <tt>Album#num_tracks</tt>. +recent_tracks+ is because the value will change over
|
34
34
|
# time. This plugin allows you to find these cases, and set the :instance_specific
|
35
35
|
# option appropriately for them:
|
data/lib/sequel/version.rb
CHANGED
@@ -6,7 +6,7 @@ module Sequel
|
|
6
6
|
|
7
7
|
# The minor version of Sequel. Bumped for every non-patch level
|
8
8
|
# release, generally around once a month.
|
9
|
-
MINOR =
|
9
|
+
MINOR = 58
|
10
10
|
|
11
11
|
# The tiny version of Sequel. Usually 0, only bumped for bugfix
|
12
12
|
# releases that fix regressions from previous versions.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.58.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: minitest-shared_description
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: tzinfo
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -200,6 +186,9 @@ extra_rdoc_files:
|
|
200
186
|
- doc/release_notes/5.53.0.txt
|
201
187
|
- doc/release_notes/5.54.0.txt
|
202
188
|
- doc/release_notes/5.55.0.txt
|
189
|
+
- doc/release_notes/5.56.0.txt
|
190
|
+
- doc/release_notes/5.57.0.txt
|
191
|
+
- doc/release_notes/5.58.0.txt
|
203
192
|
- doc/release_notes/5.6.0.txt
|
204
193
|
- doc/release_notes/5.7.0.txt
|
205
194
|
- doc/release_notes/5.8.0.txt
|
@@ -283,6 +272,9 @@ files:
|
|
283
272
|
- doc/release_notes/5.53.0.txt
|
284
273
|
- doc/release_notes/5.54.0.txt
|
285
274
|
- doc/release_notes/5.55.0.txt
|
275
|
+
- doc/release_notes/5.56.0.txt
|
276
|
+
- doc/release_notes/5.57.0.txt
|
277
|
+
- doc/release_notes/5.58.0.txt
|
286
278
|
- doc/release_notes/5.6.0.txt
|
287
279
|
- doc/release_notes/5.7.0.txt
|
288
280
|
- doc/release_notes/5.8.0.txt
|
@@ -412,6 +404,7 @@ files:
|
|
412
404
|
- lib/sequel/extensions/index_caching.rb
|
413
405
|
- lib/sequel/extensions/inflector.rb
|
414
406
|
- lib/sequel/extensions/integer64.rb
|
407
|
+
- lib/sequel/extensions/is_distinct_from.rb
|
415
408
|
- lib/sequel/extensions/looser_typecasting.rb
|
416
409
|
- lib/sequel/extensions/migration.rb
|
417
410
|
- lib/sequel/extensions/mssql_emulate_lateral_with_apply.rb
|
@@ -453,6 +446,7 @@ files:
|
|
453
446
|
- lib/sequel/extensions/sql_comments.rb
|
454
447
|
- lib/sequel/extensions/sql_expr.rb
|
455
448
|
- lib/sequel/extensions/sql_log_normalizer.rb
|
449
|
+
- lib/sequel/extensions/sqlite_json_ops.rb
|
456
450
|
- lib/sequel/extensions/string_agg.rb
|
457
451
|
- lib/sequel/extensions/string_date_time.rb
|
458
452
|
- lib/sequel/extensions/symbol_aref.rb
|
@@ -569,13 +563,13 @@ files:
|
|
569
563
|
- lib/sequel/sql.rb
|
570
564
|
- lib/sequel/timezones.rb
|
571
565
|
- lib/sequel/version.rb
|
572
|
-
homepage:
|
566
|
+
homepage: https://sequel.jeremyevans.net
|
573
567
|
licenses:
|
574
568
|
- MIT
|
575
569
|
metadata:
|
576
570
|
bug_tracker_uri: https://github.com/jeremyevans/sequel/issues
|
577
|
-
changelog_uri:
|
578
|
-
documentation_uri:
|
571
|
+
changelog_uri: https://sequel.jeremyevans.net/rdoc/files/CHANGELOG.html
|
572
|
+
documentation_uri: https://sequel.jeremyevans.net/documentation.html
|
579
573
|
mailing_list_uri: https://github.com/jeremyevans/sequel/discussions
|
580
574
|
source_code_uri: https://github.com/jeremyevans/sequel
|
581
575
|
post_install_message:
|