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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1b112ea9690e7cc6292907784ff4a1fa4b5104156b49f15ce7aa8e5b0f7ffac
|
4
|
+
data.tar.gz: 2812251110ba0677d9187564f199a6d28e0f61b198f36f4c241455132e789123
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72d567632369f93fed528c8bc469532f14d564054f85ef24f8a9a5dc23c57979f12345e54e3a44b2a2ef2db33d6a468489fa9d65ca006532b1c4ca04354ac545
|
7
|
+
data.tar.gz: 35703da2994cd323a3af2980ca624b2fdced01593f0a06aa78cafc0b9d8670e8c11129d38894b3df4d65063e1d62b4fdc5a7515e9ee4281e483d86acdda4a73c
|
data/CHANGELOG.md
CHANGED
data/lib/rom-sql.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ROM
|
2
4
|
module Plugins
|
3
5
|
module Relation
|
@@ -24,14 +26,11 @@ module ROM
|
|
24
26
|
#
|
25
27
|
# @api public
|
26
28
|
def explain(format: :text, **options)
|
27
|
-
bool_options = options.map { |opt, value| "#{
|
28
|
-
format_option = "FORMAT #{
|
29
|
+
bool_options = options.map { |opt, value| "#{opt.to_s.upcase} #{!!value}" }
|
30
|
+
format_option = "FORMAT #{format.to_s.upcase}"
|
31
|
+
explain_value = [format_option, *bool_options].join(', ')
|
29
32
|
|
30
|
-
query =
|
31
|
-
"EXPLAIN (" <<
|
32
|
-
[format_option, *bool_options].join(', ') <<
|
33
|
-
") " <<
|
34
|
-
dataset.sql
|
33
|
+
query = "EXPLAIN (#{explain_value}) #{dataset.sql}"
|
35
34
|
|
36
35
|
rows = dataset.with_sql(query).map(:'QUERY PLAN')
|
37
36
|
|
data/lib/rom/sql.rb
CHANGED
data/lib/rom/sql/associations.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ROM
|
2
4
|
module SQL
|
3
5
|
module Associations
|
@@ -19,7 +21,7 @@ module ROM
|
|
19
21
|
def wrapped
|
20
22
|
new_target = view ? target.send(view) : target
|
21
23
|
to_wrap = self.class.allocate
|
22
|
-
to_wrap.send(:initialize, definition, options
|
24
|
+
to_wrap.send(:initialize, definition, **options, target: new_target)
|
23
25
|
to_wrap.wrap
|
24
26
|
end
|
25
27
|
end
|
data/lib/rom/sql/attribute.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'sequel/core'
|
2
4
|
require 'dry/core/cache'
|
3
5
|
|
@@ -19,16 +21,18 @@ module ROM
|
|
19
21
|
|
20
22
|
OPERATORS = %i[>= <= > <].freeze
|
21
23
|
NONSTANDARD_EQUALITY_VALUES = [true, false, nil].freeze
|
22
|
-
META_KEYS = %i
|
24
|
+
META_KEYS = %i[index foreign_key target sql_expr qualified].freeze
|
23
25
|
|
24
26
|
# Error raised when an attribute cannot be qualified
|
25
27
|
QualifyError = Class.new(StandardError)
|
26
28
|
|
27
29
|
extend Dry::Core::Cache
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
class << self
|
32
|
+
# @api private
|
33
|
+
def [](type, options = EMPTY_HASH)
|
34
|
+
fetch_or_store([type, options]) { new(type, **options) }
|
35
|
+
end
|
32
36
|
end
|
33
37
|
|
34
38
|
# Return a new attribute in its canonical form
|
@@ -318,7 +322,7 @@ module ROM
|
|
318
322
|
cleaned_meta = meta.reject { |k, _| META_KEYS.include?(k) }
|
319
323
|
type = optional? ? right : self.type
|
320
324
|
|
321
|
-
self.class.new(type.with(meta: cleaned_meta), options)
|
325
|
+
self.class.new(type.with(meta: cleaned_meta), **options)
|
322
326
|
end
|
323
327
|
|
324
328
|
# Wrap a value with the type, it allows using attribute and type specific methods
|
data/lib/rom/sql/commands.rb
CHANGED
data/lib/rom/sql/dsl.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'concurrent/map'
|
2
4
|
require 'rom/support/inflector'
|
3
5
|
require 'rom/constants'
|
@@ -27,7 +29,13 @@ module ROM
|
|
27
29
|
|
28
30
|
# @api private
|
29
31
|
def call(&block)
|
30
|
-
|
32
|
+
arg, kwargs = select_relations(block.parameters)
|
33
|
+
|
34
|
+
if kwargs.nil?
|
35
|
+
result = instance_exec(arg, &block)
|
36
|
+
else
|
37
|
+
result = instance_exec(**kwargs, &block)
|
38
|
+
end
|
31
39
|
|
32
40
|
if result.is_a?(::Array)
|
33
41
|
result
|
@@ -82,9 +90,9 @@ module ROM
|
|
82
90
|
keys = parameters.select { |type, _| type == :keyreq }
|
83
91
|
|
84
92
|
if keys.empty?
|
85
|
-
relations
|
93
|
+
[relations, nil]
|
86
94
|
else
|
87
|
-
keys.each_with_object({}) { |(_, k), rs| rs[k] = relations[k] }
|
95
|
+
[nil, keys.each_with_object({}) { |(_, k), rs| rs[k] = relations[k] }]
|
88
96
|
end
|
89
97
|
end
|
90
98
|
end
|
data/lib/rom/sql/error.rb
CHANGED
data/lib/rom/sql/errors.rb
CHANGED
data/lib/rom/sql/extensions.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ROM
|
2
4
|
module SQL
|
3
5
|
module Postgres
|
4
6
|
class TypeBuilder < Schema::TypeBuilder
|
5
7
|
defines :db_numeric_types, :db_type_mapping, :db_array_type_matcher
|
6
8
|
|
7
|
-
db_numeric_types %w
|
9
|
+
db_numeric_types %w[
|
8
10
|
smallint integer bigint
|
9
11
|
decimal numeric real
|
10
12
|
double\ precision serial bigserial
|
11
|
-
|
13
|
+
].to_set.freeze
|
12
14
|
|
13
15
|
db_type_mapping(
|
14
16
|
'uuid' => Types::UUID,
|
@@ -39,11 +41,11 @@ module ROM
|
|
39
41
|
|
40
42
|
db_array_type_matcher '[]'.freeze
|
41
43
|
|
42
|
-
def map_pk_type(type, db_type, options
|
44
|
+
def map_pk_type(type, db_type, **options)
|
43
45
|
if numeric?(type, db_type)
|
44
46
|
type = self.class.numeric_pk_type
|
45
47
|
else
|
46
|
-
type = map_type(type, db_type, options)
|
48
|
+
type = map_type(type, db_type, **options)
|
47
49
|
end
|
48
50
|
|
49
51
|
type.meta(primary_key: true)
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'sequel/core'
|
2
4
|
|
3
|
-
Sequel.extension(
|
5
|
+
Sequel.extension(:pg_array, :pg_array_ops)
|
4
6
|
|
5
7
|
require 'rom/sql/extensions/postgres/types/array_types'
|
6
8
|
|
@@ -120,7 +122,7 @@ module ROM
|
|
120
122
|
Attribute[type].meta(sql_expr: expr.pg_array[idx])
|
121
123
|
end
|
122
124
|
|
123
|
-
def any(
|
125
|
+
def any(_type, expr, value)
|
124
126
|
Attribute[SQL::Types::Bool].meta(sql_expr: { value => expr.pg_array.any })
|
125
127
|
end
|
126
128
|
|
@@ -128,7 +130,7 @@ module ROM
|
|
128
130
|
Attribute[SQL::Types::Bool].meta(sql_expr: expr.pg_array.contained_by(type[other]))
|
129
131
|
end
|
130
132
|
|
131
|
-
def length(
|
133
|
+
def length(_type, expr)
|
132
134
|
Attribute[SQL::Types::Integer].meta(sql_expr: expr.pg_array.length)
|
133
135
|
end
|
134
136
|
|
@@ -140,7 +142,7 @@ module ROM
|
|
140
142
|
Attribute[type].meta(sql_expr: expr.pg_array.remove(cast(type, value)))
|
141
143
|
end
|
142
144
|
|
143
|
-
def join(
|
145
|
+
def join(_type, expr, delimiter = '', null = nil)
|
144
146
|
Attribute[SQL::Types::String].meta(sql_expr: expr.pg_array.join(delimiter, null))
|
145
147
|
end
|
146
148
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rom/sql/type_extensions'
|
2
4
|
|
3
5
|
module ROM
|
@@ -52,7 +54,7 @@ module ROM
|
|
52
54
|
end
|
53
55
|
end
|
54
56
|
|
55
|
-
def build_read_type(
|
57
|
+
def build_read_type(_db_type, member_type)
|
56
58
|
if member_type && member_type.meta[:read]
|
57
59
|
base_read_type.of(member_type.meta[:read])
|
58
60
|
else
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'sequel/core'
|
2
4
|
require 'singleton'
|
3
5
|
|
4
|
-
Sequel.extension(
|
6
|
+
Sequel.extension(:pg_json, :pg_json_ops)
|
5
7
|
|
6
8
|
module ROM
|
7
9
|
module SQL
|
@@ -228,11 +230,11 @@ module ROM
|
|
228
230
|
end
|
229
231
|
end
|
230
232
|
|
231
|
-
def get(
|
233
|
+
def get(_type, expr, *path)
|
232
234
|
Attribute[json_type].meta(sql_expr: wrap(expr)[path_args(path)])
|
233
235
|
end
|
234
236
|
|
235
|
-
def get_text(
|
237
|
+
def get_text(_type, expr, *path)
|
236
238
|
Attribute[SQL::Types::String].meta(sql_expr: wrap(expr).get_text(path_args(path)))
|
237
239
|
end
|
238
240
|
|
@@ -240,7 +242,7 @@ module ROM
|
|
240
242
|
|
241
243
|
def path_args(path)
|
242
244
|
case path.size
|
243
|
-
when 0 then raise ArgumentError,
|
245
|
+
when 0 then raise ArgumentError, 'wrong number of arguments (given 0, expected 1+)'
|
244
246
|
when 1 then path[0]
|
245
247
|
else path
|
246
248
|
end
|
@@ -254,32 +256,32 @@ module ROM
|
|
254
256
|
TypeExtensions.register(JSONB) do
|
255
257
|
include JSONMethods[JSONB, :pg_jsonb.to_proc]
|
256
258
|
|
257
|
-
def contain(
|
259
|
+
def contain(_type, expr, value)
|
258
260
|
Attribute[SQL::Types::Bool].meta(sql_expr: wrap(expr).contains(value))
|
259
261
|
end
|
260
262
|
|
261
|
-
def contained_by(
|
263
|
+
def contained_by(_type, expr, value)
|
262
264
|
Attribute[SQL::Types::Bool].meta(sql_expr: wrap(expr).contained_by(value))
|
263
265
|
end
|
264
266
|
|
265
|
-
def has_key(
|
267
|
+
def has_key(_type, expr, key)
|
266
268
|
Attribute[SQL::Types::Bool].meta(sql_expr: wrap(expr).has_key?(key))
|
267
269
|
end
|
268
270
|
|
269
|
-
def has_any_key(
|
271
|
+
def has_any_key(_type, expr, *keys)
|
270
272
|
Attribute[SQL::Types::Bool].meta(sql_expr: wrap(expr).contain_any(keys))
|
271
273
|
end
|
272
274
|
|
273
|
-
def has_all_keys(
|
275
|
+
def has_all_keys(_type, expr, *keys)
|
274
276
|
Attribute[SQL::Types::Bool].meta(sql_expr: wrap(expr).contain_all(keys))
|
275
277
|
end
|
276
278
|
|
277
|
-
def merge(
|
279
|
+
def merge(_type, expr, value)
|
278
280
|
Attribute[JSONB].meta(sql_expr: wrap(expr).concat(value))
|
279
281
|
end
|
280
282
|
alias_method :+, :merge
|
281
283
|
|
282
|
-
def delete(
|
284
|
+
def delete(_type, expr, *path)
|
283
285
|
sql_expr = path.size == 1 ? wrap(expr) - path : wrap(expr).delete_path(path)
|
284
286
|
Attribute[JSONB].meta(sql_expr: sql_expr)
|
285
287
|
end
|