rom-sql 3.1.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/rom-sql.rb +2 -0
- data/lib/rom/plugins/relation/sql/auto_restrictions.rb +2 -0
- data/lib/rom/plugins/relation/sql/instrumentation.rb +2 -0
- data/lib/rom/plugins/relation/sql/postgres/explain.rb +6 -7
- data/lib/rom/sql.rb +2 -0
- data/lib/rom/sql/associations.rb +2 -0
- data/lib/rom/sql/associations/core.rb +3 -1
- data/lib/rom/sql/associations/many_to_many.rb +2 -0
- data/lib/rom/sql/associations/many_to_one.rb +2 -0
- data/lib/rom/sql/associations/one_to_many.rb +2 -0
- data/lib/rom/sql/associations/one_to_one.rb +2 -0
- data/lib/rom/sql/associations/one_to_one_through.rb +2 -0
- data/lib/rom/sql/associations/self_ref.rb +2 -0
- data/lib/rom/sql/attribute.rb +9 -5
- data/lib/rom/sql/commands.rb +2 -0
- data/lib/rom/sql/commands/create.rb +2 -0
- data/lib/rom/sql/commands/delete.rb +2 -0
- data/lib/rom/sql/commands/error_wrapper.rb +2 -0
- data/lib/rom/sql/commands/update.rb +2 -0
- data/lib/rom/sql/dsl.rb +11 -3
- data/lib/rom/sql/error.rb +2 -0
- data/lib/rom/sql/errors.rb +2 -0
- data/lib/rom/sql/extensions.rb +2 -0
- data/lib/rom/sql/extensions/active_support_notifications.rb +2 -0
- data/lib/rom/sql/extensions/mysql.rb +2 -0
- data/lib/rom/sql/extensions/mysql/type_builder.rb +2 -0
- data/lib/rom/sql/extensions/postgres.rb +2 -0
- data/lib/rom/sql/extensions/postgres/commands.rb +2 -0
- data/lib/rom/sql/extensions/postgres/type_builder.rb +6 -4
- data/lib/rom/sql/extensions/postgres/type_serializer.rb +2 -0
- data/lib/rom/sql/extensions/postgres/types.rb +2 -0
- data/lib/rom/sql/extensions/postgres/types/array.rb +6 -4
- data/lib/rom/sql/extensions/postgres/types/array_types.rb +3 -1
- data/lib/rom/sql/extensions/postgres/types/geometric.rb +2 -0
- data/lib/rom/sql/extensions/postgres/types/json.rb +13 -11
- data/lib/rom/sql/extensions/postgres/types/ltree.rb +25 -23
- data/lib/rom/sql/extensions/postgres/types/network.rb +2 -0
- data/lib/rom/sql/extensions/postgres/types/range.rb +2 -0
- data/lib/rom/sql/extensions/rails_log_subscriber.rb +2 -0
- data/lib/rom/sql/extensions/sqlite.rb +2 -0
- data/lib/rom/sql/extensions/sqlite/type_builder.rb +2 -0
- data/lib/rom/sql/extensions/sqlite/types.rb +2 -0
- data/lib/rom/sql/foreign_key.rb +3 -1
- data/lib/rom/sql/function.rb +3 -1
- data/lib/rom/sql/gateway.rb +3 -1
- data/lib/rom/sql/group_dsl.rb +2 -0
- data/lib/rom/sql/index.rb +2 -0
- data/lib/rom/sql/join_dsl.rb +2 -0
- data/lib/rom/sql/mapper_compiler.rb +2 -0
- data/lib/rom/sql/migration.rb +5 -3
- data/lib/rom/sql/migration/inline_runner.rb +2 -0
- data/lib/rom/sql/migration/migrator.rb +4 -2
- data/lib/rom/sql/migration/recorder.rb +2 -0
- data/lib/rom/sql/migration/runner.rb +4 -2
- data/lib/rom/sql/migration/schema_diff.rb +2 -0
- data/lib/rom/sql/migration/template.rb +2 -0
- data/lib/rom/sql/migration/writer.rb +12 -4
- data/lib/rom/sql/order_dsl.rb +2 -0
- data/lib/rom/sql/plugin/associates.rb +4 -2
- data/lib/rom/sql/plugin/nullify.rb +2 -0
- data/lib/rom/sql/plugin/pagination.rb +2 -0
- data/lib/rom/sql/plugins.rb +2 -0
- data/lib/rom/sql/projection_dsl.rb +2 -0
- data/lib/rom/sql/rake_task.rb +2 -0
- data/lib/rom/sql/relation.rb +2 -0
- data/lib/rom/sql/relation/reading.rb +5 -3
- data/lib/rom/sql/relation/writing.rb +2 -0
- data/lib/rom/sql/restriction_dsl.rb +9 -1
- data/lib/rom/sql/schema.rb +3 -1
- data/lib/rom/sql/schema/attributes_inferrer.rb +5 -3
- data/lib/rom/sql/schema/dsl.rb +3 -1
- data/lib/rom/sql/schema/index_dsl.rb +5 -2
- data/lib/rom/sql/schema/inferrer.rb +12 -8
- data/lib/rom/sql/schema/type_builder.rb +4 -2
- data/lib/rom/sql/spec/support.rb +5 -3
- data/lib/rom/sql/tasks/migration_tasks.rake +16 -11
- data/lib/rom/sql/transaction.rb +2 -0
- data/lib/rom/sql/type_dsl.rb +2 -0
- data/lib/rom/sql/type_extensions.rb +2 -0
- data/lib/rom/sql/type_serializer.rb +2 -0
- data/lib/rom/sql/types.rb +2 -0
- data/lib/rom/sql/version.rb +3 -1
- data/lib/rom/sql/wrap.rb +2 -0
- data/lib/rom/types/values.rb +2 -0
- metadata +7 -7
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rom/types/values'
|
2
4
|
|
3
5
|
module ROM
|
@@ -222,20 +224,20 @@ module ROM
|
|
222
224
|
#
|
223
225
|
# end
|
224
226
|
module LTreeMethods
|
225
|
-
ASCENDANT = [
|
226
|
-
FIND_ASCENDANT = [
|
227
|
-
DESCENDANT = [
|
228
|
-
FIND_DESCENDANT = [
|
229
|
-
MATCH_ANY = [
|
230
|
-
MATCH_ANY_LQUERY = [
|
231
|
-
MATCH_LTEXTQUERY = [
|
232
|
-
MATCH_ANY_LTEXTQUERY = [
|
227
|
+
ASCENDANT = ['(', ' @> ', ')'].freeze
|
228
|
+
FIND_ASCENDANT = ['(', ' ?@> ', ')'].freeze
|
229
|
+
DESCENDANT = ['(', ' <@ ', ')'].freeze
|
230
|
+
FIND_DESCENDANT = ['(', ' ?<@ ', ')'].freeze
|
231
|
+
MATCH_ANY = ['(', ' ? ', ')'].freeze
|
232
|
+
MATCH_ANY_LQUERY = ['(', ' ?~ ', ')'].freeze
|
233
|
+
MATCH_LTEXTQUERY = ['(', ' @ ', ')'].freeze
|
234
|
+
MATCH_ANY_LTEXTQUERY = ['(', ' ?@ ', ')'].freeze
|
233
235
|
|
234
|
-
def match(
|
236
|
+
def match(_type, expr, query)
|
235
237
|
Attribute[SQL::Types::Bool].meta(sql_expr: Sequel::SQL::BooleanExpression.new(:'~', expr, query))
|
236
238
|
end
|
237
239
|
|
238
|
-
def match_any(
|
240
|
+
def match_any(_type, expr, query)
|
239
241
|
array = build_array_query(query)
|
240
242
|
Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(MATCH_ANY, expr, array))
|
241
243
|
end
|
@@ -259,31 +261,31 @@ module ROM
|
|
259
261
|
TypeExtensions.register(ROM::SQL::Types::PG::Array('ltree', LTree)) do
|
260
262
|
include LTreeMethods
|
261
263
|
|
262
|
-
def contain_any_ltextquery(
|
264
|
+
def contain_any_ltextquery(_type, expr, query)
|
263
265
|
Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::MATCH_LTEXTQUERY, expr, query))
|
264
266
|
end
|
265
267
|
|
266
|
-
def contain_ancestor(
|
268
|
+
def contain_ancestor(_type, expr, query)
|
267
269
|
Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::ASCENDANT, expr, query))
|
268
270
|
end
|
269
271
|
|
270
|
-
def contain_descendant(
|
272
|
+
def contain_descendant(_type, expr, query)
|
271
273
|
Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::DESCENDANT, expr, query))
|
272
274
|
end
|
273
275
|
|
274
|
-
def find_ancestor(
|
276
|
+
def find_ancestor(_type, expr, query)
|
275
277
|
Attribute[LTree].meta(sql_expr: custom_operator_expr(LTreeMethods::FIND_ASCENDANT, expr, query))
|
276
278
|
end
|
277
279
|
|
278
|
-
def find_descendant(
|
280
|
+
def find_descendant(_type, expr, query)
|
279
281
|
Attribute[LTree].meta(sql_expr: custom_operator_expr(LTreeMethods::FIND_DESCENDANT, expr, query))
|
280
282
|
end
|
281
283
|
|
282
|
-
def match_any_lquery(
|
284
|
+
def match_any_lquery(_type, expr, query)
|
283
285
|
Attribute[LTree].meta(sql_expr: custom_operator_expr(LTreeMethods::MATCH_ANY_LQUERY, expr, query))
|
284
286
|
end
|
285
287
|
|
286
|
-
def match_any_ltextquery(
|
288
|
+
def match_any_ltextquery(_type, expr, query)
|
287
289
|
Attribute[LTree].meta(sql_expr: custom_operator_expr(LTreeMethods::MATCH_ANY_LTEXTQUERY, expr, query))
|
288
290
|
end
|
289
291
|
end
|
@@ -291,29 +293,29 @@ module ROM
|
|
291
293
|
TypeExtensions.register(LTree) do
|
292
294
|
include LTreeMethods
|
293
295
|
|
294
|
-
def match_ltextquery(
|
296
|
+
def match_ltextquery(_type, expr, query)
|
295
297
|
Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::MATCH_LTEXTQUERY, expr, query))
|
296
298
|
end
|
297
299
|
|
298
|
-
def contain_descendant(
|
300
|
+
def contain_descendant(_type, expr, query)
|
299
301
|
array = build_array_query(query, 'ltree')
|
300
302
|
Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::DESCENDANT, expr, array))
|
301
303
|
end
|
302
304
|
|
303
|
-
def descendant(
|
305
|
+
def descendant(_type, expr, query)
|
304
306
|
Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::DESCENDANT, expr, query))
|
305
307
|
end
|
306
308
|
|
307
|
-
def contain_ascendant(
|
309
|
+
def contain_ascendant(_type, expr, query)
|
308
310
|
array = build_array_query(query, 'ltree')
|
309
311
|
Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::ASCENDANT, expr, array))
|
310
312
|
end
|
311
313
|
|
312
|
-
def ascendant(
|
314
|
+
def ascendant(_type, expr, query)
|
313
315
|
Attribute[SQL::Types::Bool].meta(sql_expr: custom_operator_expr(LTreeMethods::ASCENDANT, expr, query))
|
314
316
|
end
|
315
317
|
|
316
|
-
def +(
|
318
|
+
def +(_type, expr, other)
|
317
319
|
other_value = case other
|
318
320
|
when ROM::Types::Values::TreePath
|
319
321
|
other
|
data/lib/rom/sql/foreign_key.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ROM
|
2
4
|
module SQL
|
3
5
|
# @api private
|
@@ -5,7 +7,7 @@ module ROM
|
|
5
7
|
extend Initializer
|
6
8
|
include Dry::Equalizer(:attributes, :parent_table, :options)
|
7
9
|
|
8
|
-
DEFAULT_PARENT_KEYS = %i
|
10
|
+
DEFAULT_PARENT_KEYS = %i[id].freeze
|
9
11
|
|
10
12
|
param :attributes
|
11
13
|
|
data/lib/rom/sql/function.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rom/attribute'
|
2
4
|
require 'rom/sql/attribute_wrapping'
|
3
5
|
|
@@ -79,7 +81,7 @@ module ROM
|
|
79
81
|
# @see Attribute#qualified?
|
80
82
|
#
|
81
83
|
# @api private
|
82
|
-
def qualified?(
|
84
|
+
def qualified?(_table_alias = nil)
|
83
85
|
meta[:func].args.all?(&:qualified?)
|
84
86
|
end
|
85
87
|
|
data/lib/rom/sql/gateway.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'logger'
|
2
4
|
require 'sequel/core'
|
3
5
|
|
@@ -21,7 +23,7 @@ module ROM
|
|
21
23
|
adapter :sql
|
22
24
|
|
23
25
|
CONNECTION_EXTENSIONS = {
|
24
|
-
postgres: %i
|
26
|
+
postgres: %i[pg_array pg_json pg_enum]
|
25
27
|
}.freeze
|
26
28
|
|
27
29
|
# @!attribute [r] logger
|
data/lib/rom/sql/group_dsl.rb
CHANGED
data/lib/rom/sql/index.rb
CHANGED
data/lib/rom/sql/join_dsl.rb
CHANGED
data/lib/rom/sql/migration.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rom/sql/migration/migrator'
|
2
4
|
require 'rom/sql/migration/schema_diff'
|
3
5
|
|
@@ -97,7 +99,7 @@ module ROM
|
|
97
99
|
attr_reader :migrator
|
98
100
|
|
99
101
|
# @api private
|
100
|
-
def initialize(
|
102
|
+
def initialize(_uri, options = EMPTY_HASH)
|
101
103
|
@migrator = create_migrator(options[:migrator])
|
102
104
|
|
103
105
|
self.class.instance ||= self
|
@@ -139,7 +141,7 @@ module ROM
|
|
139
141
|
end
|
140
142
|
|
141
143
|
# @api public
|
142
|
-
def auto_migrate!(conf, options = EMPTY_HASH
|
144
|
+
def auto_migrate!(conf, options = EMPTY_HASH)
|
143
145
|
schemas = conf.relation_classes(self).map do |klass|
|
144
146
|
klass.schema_proc.call.finalize_attributes!(gateway: self)
|
145
147
|
end
|
@@ -156,7 +158,7 @@ module ROM
|
|
156
158
|
return Migrator.new(connection) unless migrator_option
|
157
159
|
|
158
160
|
if migrator_option.is_a?(Hash)
|
159
|
-
Migrator.new(connection, migrator_option)
|
161
|
+
Migrator.new(connection, **migrator_option)
|
160
162
|
else
|
161
163
|
migrator_option
|
162
164
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'pathname'
|
2
4
|
|
3
5
|
require 'rom/types'
|
@@ -65,12 +67,12 @@ module ROM
|
|
65
67
|
end
|
66
68
|
|
67
69
|
# @api private
|
68
|
-
def auto_migrate!(gateway, schemas, options = EMPTY_HASH
|
70
|
+
def auto_migrate!(gateway, schemas, options = EMPTY_HASH)
|
69
71
|
diff_finder = SchemaDiff.new(gateway.database_type)
|
70
72
|
|
71
73
|
changes = schemas.map { |target|
|
72
74
|
empty = SQL::Schema.define(target.name)
|
73
|
-
current = target.with(inferrer.(empty, gateway))
|
75
|
+
current = target.with(**inferrer.(empty, gateway))
|
74
76
|
|
75
77
|
diff_finder.(current, target)
|
76
78
|
}.reject(&:empty?)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ROM
|
2
4
|
module SQL
|
3
5
|
module Migration
|
@@ -67,8 +69,8 @@ module ROM
|
|
67
69
|
if attribute.type_changed?
|
68
70
|
from, to = attribute.current.unwrap, attribute.target.unwrap
|
69
71
|
raise UnsupportedConversion.new(
|
70
|
-
|
71
|
-
|
72
|
+
"Don't know how to convert #{from.inspect} to #{to.inspect}"
|
73
|
+
)
|
72
74
|
end
|
73
75
|
|
74
76
|
if attribute.nullability_changed?
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rom/sql/migration/recorder'
|
2
4
|
|
3
5
|
module ROM
|
@@ -32,7 +34,7 @@ module ROM
|
|
32
34
|
operations.each do |operation|
|
33
35
|
op, args, nested = operation
|
34
36
|
buffer << indent << op.to_s << ' '
|
35
|
-
write_arguments(buffer,
|
37
|
+
write_arguments(buffer, args)
|
36
38
|
|
37
39
|
if !nested.empty?
|
38
40
|
buffer << ' do'
|
@@ -42,9 +44,15 @@ module ROM
|
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
45
|
-
def write_arguments(buffer,
|
47
|
+
def write_arguments(buffer, args)
|
48
|
+
if args.last.is_a?(::Hash)
|
49
|
+
args, options = args[0...-1], args.last
|
50
|
+
else
|
51
|
+
options = EMPTY_HASH
|
52
|
+
end
|
53
|
+
|
46
54
|
buffer << args.map(&:inspect).join(', ')
|
47
|
-
|
55
|
+
options.each do |key, value|
|
48
56
|
buffer << ', ' << key.to_s << ': ' << value.inspect
|
49
57
|
end
|
50
58
|
end
|
@@ -53,7 +61,7 @@ module ROM
|
|
53
61
|
create_or_alter, args = op
|
54
62
|
table_name = args[0]
|
55
63
|
|
56
|
-
"#{
|
64
|
+
"#{create_or_alter.to_s.sub('_table', '')}_#{table_name}"
|
57
65
|
end
|
58
66
|
end
|
59
67
|
end
|
data/lib/rom/sql/order_dsl.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rom/sql/associations'
|
2
4
|
|
3
5
|
module ROM
|
@@ -48,7 +50,7 @@ module ROM
|
|
48
50
|
# @see ROM::Command::ClassInterface.build
|
49
51
|
#
|
50
52
|
# @api public
|
51
|
-
def build(relation, options
|
53
|
+
def build(relation, **options)
|
52
54
|
command = super
|
53
55
|
|
54
56
|
configured_assocs = command.configured_associations
|
@@ -146,7 +148,7 @@ module ROM
|
|
146
148
|
def with_association(name, opts = EMPTY_HASH)
|
147
149
|
self.class.build(
|
148
150
|
relation,
|
149
|
-
|
151
|
+
**options, associations: associations.merge(name => opts)
|
150
152
|
)
|
151
153
|
end
|
152
154
|
end
|
data/lib/rom/sql/plugins.rb
CHANGED
data/lib/rom/sql/rake_task.rb
CHANGED
data/lib/rom/sql/relation.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rom/support/inflector'
|
2
4
|
require 'rom/sql/join_dsl'
|
3
5
|
|
@@ -891,8 +893,8 @@ module ROM
|
|
891
893
|
# @yieldparam relation [Array]
|
892
894
|
#
|
893
895
|
# @api public
|
894
|
-
def lock(options
|
895
|
-
clause = lock_clause(options)
|
896
|
+
def lock(**options, &block)
|
897
|
+
clause = lock_clause(**options)
|
896
898
|
|
897
899
|
if block
|
898
900
|
transaction do
|
@@ -1036,7 +1038,7 @@ module ROM
|
|
1036
1038
|
stmt << ' OF ' << Array(of).join(', ') if of
|
1037
1039
|
|
1038
1040
|
if skip_locked
|
1039
|
-
raise ArgumentError,
|
1041
|
+
raise ArgumentError, 'SKIP LOCKED cannot be used with (NO)WAIT clause' if !wait.nil?
|
1040
1042
|
|
1041
1043
|
stmt << ' SKIP LOCKED'
|
1042
1044
|
else
|