rom-sql 3.7.0 → 4.0.0.alpha1
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/CHANGELOG.md +11 -65
- data/LICENSE +1 -1
- data/README.md +3 -2
- data/lib/rom/plugins/relation/sql/auto_restrictions.rb +10 -12
- data/lib/rom/plugins/relation/sql/default_views.rb +75 -0
- data/lib/rom/plugins/relation/sql/instrumentation.rb +8 -17
- data/lib/rom/plugins/relation/sql/postgres/explain.rb +5 -5
- data/lib/rom/plugins/relation/sql/postgres/full_text_search.rb +20 -37
- data/lib/rom/plugins/relation/sql/postgres/streaming.rb +17 -14
- data/lib/rom/sql/associations/many_to_many.rb +4 -7
- data/lib/rom/sql/associations/many_to_one.rb +3 -6
- data/lib/rom/sql/associations/one_to_many.rb +3 -3
- data/lib/rom/sql/associations/one_to_one.rb +1 -1
- data/lib/rom/sql/associations/one_to_one_through.rb +1 -1
- data/lib/rom/sql/associations/self_ref.rb +1 -1
- data/lib/rom/sql/associations.rb +5 -5
- data/lib/rom/sql/attribute.rb +17 -31
- data/lib/rom/sql/attribute_aliasing.rb +4 -6
- data/lib/rom/sql/commands/create.rb +5 -5
- data/lib/rom/sql/commands/delete.rb +2 -2
- data/lib/rom/sql/commands/update.rb +5 -5
- data/lib/rom/sql/commands.rb +4 -4
- data/lib/rom/sql/dsl.rb +4 -6
- data/lib/rom/sql/errors.rb +3 -3
- data/lib/rom/sql/extensions/active_support_notifications.rb +3 -3
- data/lib/rom/sql/extensions/mysql/type_builder.rb +5 -5
- data/lib/rom/sql/extensions/mysql.rb +1 -1
- data/lib/rom/sql/extensions/postgres/commands.rb +13 -31
- data/lib/rom/sql/extensions/postgres/type_builder.rb +28 -31
- data/lib/rom/sql/extensions/postgres/type_serializer.rb +24 -25
- data/lib/rom/sql/extensions/postgres/types/array.rb +4 -4
- data/lib/rom/sql/extensions/postgres/types/array_types.rb +1 -1
- data/lib/rom/sql/extensions/postgres/types/geometric.rb +19 -19
- data/lib/rom/sql/extensions/postgres/types/json.rb +12 -18
- data/lib/rom/sql/extensions/postgres/types/ltree.rb +54 -97
- data/lib/rom/sql/extensions/postgres/types/network.rb +4 -17
- data/lib/rom/sql/extensions/postgres/types/range.rb +30 -30
- data/lib/rom/sql/extensions/postgres/types.rb +14 -14
- data/lib/rom/sql/extensions/postgres.rb +6 -6
- data/lib/rom/sql/extensions/rails_log_subscriber.rb +6 -21
- data/lib/rom/sql/extensions/sqlite/types.rb +1 -1
- data/lib/rom/sql/extensions/sqlite.rb +2 -2
- data/lib/rom/sql/extensions.rb +6 -6
- data/lib/rom/sql/foreign_key.rb +3 -1
- data/lib/rom/sql/function.rb +19 -42
- data/lib/rom/sql/gateway.rb +41 -15
- data/lib/rom/sql/group_dsl.rb +3 -8
- data/lib/rom/sql/index.rb +2 -0
- data/lib/rom/sql/join_dsl.rb +1 -1
- data/lib/rom/sql/mapper_compiler.rb +2 -2
- data/lib/rom/sql/migration/inline_runner.rb +2 -8
- data/lib/rom/sql/migration/migrator.rb +12 -12
- data/lib/rom/sql/migration/recorder.rb +4 -10
- data/lib/rom/sql/migration/runner.rb +4 -5
- data/lib/rom/sql/migration/schema_diff.rb +4 -10
- data/lib/rom/sql/migration/writer.rb +7 -7
- data/lib/rom/sql/migration.rb +9 -13
- data/lib/rom/sql/order_dsl.rb +3 -7
- data/lib/rom/sql/plugin/associates.rb +45 -21
- data/lib/rom/sql/plugin/pagination.rb +3 -1
- data/lib/rom/sql/plugin/schema_indexes.rb +35 -0
- data/lib/rom/sql/plugins.rb +9 -6
- data/lib/rom/sql/projection_dsl.rb +5 -5
- data/lib/rom/sql/rake_task.rb +2 -2
- data/lib/rom/sql/relation/reading.rb +78 -83
- data/lib/rom/sql/relation/writing.rb +4 -9
- data/lib/rom/sql/relation.rb +58 -136
- data/lib/rom/sql/restriction_dsl.rb +4 -8
- data/lib/rom/sql/schema/attributes_inferrer.rb +2 -2
- data/lib/rom/sql/schema/dsl.rb +6 -4
- data/lib/rom/sql/schema/index_dsl.rb +6 -7
- data/lib/rom/sql/schema/inferrer.rb +22 -24
- data/lib/rom/sql/schema/type_builder.rb +4 -20
- data/lib/rom/sql/schema.rb +17 -29
- data/lib/rom/sql/spec/support.rb +5 -5
- data/lib/rom/sql/tasks/migration_tasks.rake +14 -21
- data/lib/rom/sql/transaction.rb +4 -3
- data/lib/rom/sql/type_dsl.rb +3 -7
- data/lib/rom/sql/type_extensions.rb +6 -4
- data/lib/rom/sql/type_serializer.rb +9 -9
- data/lib/rom/sql/types.rb +6 -6
- data/lib/rom/sql/version.rb +1 -1
- data/lib/rom/sql/wrap.rb +1 -1
- data/lib/rom/sql.rb +13 -12
- data/lib/rom/types/values.rb +5 -3
- data/lib/rom-sql.rb +1 -1
- metadata +17 -12
data/lib/rom/sql/attribute.rb
CHANGED
@@ -1,22 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "sequel/core"
|
4
|
+
require "dry/core/cache"
|
5
5
|
|
6
|
-
require
|
6
|
+
require "rom/attribute"
|
7
7
|
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
8
|
+
require "rom/sql/type_extensions"
|
9
|
+
require "rom/sql/projection_dsl"
|
10
|
+
require "rom/sql/attribute_wrapping"
|
11
|
+
require "rom/sql/attribute_aliasing"
|
12
12
|
|
13
13
|
module ROM
|
14
14
|
module SQL
|
15
15
|
# Extended schema attributes tailored for SQL databases
|
16
16
|
#
|
17
17
|
# @api public
|
18
|
-
#
|
19
|
-
# rubocop:disable Metrics/ClassLength
|
20
18
|
class Attribute < ROM::Attribute
|
21
19
|
include AttributeWrapping
|
22
20
|
include AttributeAliasing
|
@@ -61,9 +59,7 @@ module ROM
|
|
61
59
|
return meta(qualified: false) unless qualifiable?
|
62
60
|
|
63
61
|
case sql_expr
|
64
|
-
when
|
65
|
-
::Sequel::SQL::Identifier,
|
66
|
-
::Sequel::SQL::QualifiedIdentifier
|
62
|
+
when Sequel::SQL::AliasedExpression, Sequel::SQL::Identifier, Sequel::SQL::QualifiedIdentifier
|
67
63
|
attr = meta(qualified: table_alias || true)
|
68
64
|
attr.meta(sql_expr: attr.to_sql_name)
|
69
65
|
else
|
@@ -267,8 +263,8 @@ module ROM
|
|
267
263
|
# @return [SQL::Function]
|
268
264
|
#
|
269
265
|
# @api public
|
270
|
-
def func(&)
|
271
|
-
ProjectionDSL.new(name => self).call(&).first
|
266
|
+
def func(&block)
|
267
|
+
ProjectionDSL.new(name => self).call(&block).first
|
272
268
|
end
|
273
269
|
|
274
270
|
# Create a CONCAT function from the attribute
|
@@ -284,7 +280,7 @@ module ROM
|
|
284
280
|
# @return [SQL::Function]
|
285
281
|
#
|
286
282
|
# @api public
|
287
|
-
def concat(other, sep =
|
283
|
+
def concat(other, sep = " ")
|
288
284
|
Function.new(type).concat(self, sep, other)
|
289
285
|
end
|
290
286
|
|
@@ -338,7 +334,7 @@ module ROM
|
|
338
334
|
#
|
339
335
|
# @api private
|
340
336
|
def unwrap
|
341
|
-
cleaned_meta = meta.
|
337
|
+
cleaned_meta = meta.reject { |k, _| META_KEYS.include?(k) }
|
342
338
|
type = optional? ? right : self.type
|
343
339
|
|
344
340
|
self.class.new(type.with(meta: cleaned_meta), **options)
|
@@ -370,7 +366,7 @@ module ROM
|
|
370
366
|
def case(mapping)
|
371
367
|
mapping = mapping.dup
|
372
368
|
otherwise = mapping.delete(:else) do
|
373
|
-
raise ArgumentError,
|
369
|
+
raise ArgumentError, "provide the default case using the :else keyword"
|
374
370
|
end
|
375
371
|
|
376
372
|
type = mapping.values[0].type
|
@@ -384,28 +380,19 @@ module ROM
|
|
384
380
|
#
|
385
381
|
# @api private
|
386
382
|
def sql_expr
|
387
|
-
@sql_expr ||= meta[:sql_expr] || to_sql_name
|
388
|
-
end
|
389
|
-
|
390
|
-
# @api private
|
391
|
-
def respond_to_missing?(meth, _include_private = false)
|
392
|
-
if OPERATORS.include?(meth) || extensions.key?(meth) || sql_expr.respond_to?(meth)
|
393
|
-
true
|
394
|
-
else
|
395
|
-
super
|
396
|
-
end
|
383
|
+
@sql_expr ||= (meta[:sql_expr] || to_sql_name)
|
397
384
|
end
|
398
385
|
|
399
386
|
# Delegate to sql expression if it responds to a given method
|
400
387
|
#
|
401
388
|
# @api private
|
402
|
-
def method_missing(meth, *args, &)
|
389
|
+
def method_missing(meth, *args, &block)
|
403
390
|
if OPERATORS.include?(meth)
|
404
391
|
__cmp__(meth, args[0])
|
405
392
|
elsif extensions.key?(meth)
|
406
|
-
extensions[meth].(type, sql_expr, *args, &)
|
393
|
+
extensions[meth].(type, sql_expr, *args, &block)
|
407
394
|
elsif sql_expr.respond_to?(meth)
|
408
|
-
meta(sql_expr: sql_expr.__send__(meth, *args, &))
|
395
|
+
meta(sql_expr: sql_expr.__send__(meth, *args, &block))
|
409
396
|
else
|
410
397
|
super
|
411
398
|
end
|
@@ -449,6 +436,5 @@ module ROM
|
|
449
436
|
|
450
437
|
memoize :joined, :to_sql_name, :table_name, :canonical
|
451
438
|
end
|
452
|
-
# rubocop:enable Metrics/ClassLength
|
453
439
|
end
|
454
440
|
end
|
@@ -45,7 +45,7 @@ module ROM
|
|
45
45
|
#
|
46
46
|
# @api private
|
47
47
|
def aliased_projection?
|
48
|
-
meta[:sql_expr].is_a?(
|
48
|
+
meta[:sql_expr].is_a?(Sequel::SQL::AliasedExpression)
|
49
49
|
end
|
50
50
|
|
51
51
|
private
|
@@ -53,10 +53,8 @@ module ROM
|
|
53
53
|
# @api private
|
54
54
|
def alias_sql_expr(sql_expr, new_alias)
|
55
55
|
case sql_expr
|
56
|
-
when
|
57
|
-
|
58
|
-
sql_expr.expression, new_alias, sql_expr.columns
|
59
|
-
)
|
56
|
+
when Sequel::SQL::AliasedExpression
|
57
|
+
Sequel::SQL::AliasedExpression.new(sql_expr.expression, new_alias, sql_expr.columns)
|
60
58
|
else
|
61
59
|
sql_expr.as(new_alias)
|
62
60
|
end
|
@@ -71,7 +69,7 @@ module ROM
|
|
71
69
|
# attribute in a way that will map the the requested alias name.
|
72
70
|
# Without this, the attribute will silently ignore the requested alias
|
73
71
|
# name and default to the pre-existing name.
|
74
|
-
new_name =
|
72
|
+
new_name = "#{meta[:wrapped]}_#{options[:alias]}".to_sym
|
75
73
|
|
76
74
|
# Essentially, this makes it so "wrapped" attributes aren't true
|
77
75
|
# aliases, in that we actually alias the wrapped attribute, we use
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "rom/sql/commands/error_wrapper"
|
4
4
|
|
5
5
|
module ROM
|
6
6
|
module SQL
|
@@ -9,7 +9,7 @@ module ROM
|
|
9
9
|
#
|
10
10
|
# @api public
|
11
11
|
class Create < ROM::Commands::Create
|
12
|
-
adapter :sql
|
12
|
+
config.component.adapter = :sql
|
13
13
|
|
14
14
|
include ErrorWrapper
|
15
15
|
|
@@ -60,11 +60,11 @@ module ROM
|
|
60
60
|
# Yields tuples for insertion or return an enumerator
|
61
61
|
#
|
62
62
|
# @api private
|
63
|
-
def with_input_tuples(tuples, &)
|
64
|
-
input_tuples = [tuples].flatten(1).map
|
63
|
+
def with_input_tuples(tuples, &block)
|
64
|
+
input_tuples = Array([tuples]).flatten(1).map
|
65
65
|
return input_tuples unless block_given?
|
66
66
|
|
67
|
-
input_tuples.each(&)
|
67
|
+
input_tuples.each(&block)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "rom/sql/commands/error_wrapper"
|
4
4
|
|
5
5
|
module ROM
|
6
6
|
module SQL
|
@@ -9,7 +9,7 @@ module ROM
|
|
9
9
|
#
|
10
10
|
# @api public
|
11
11
|
class Delete < ROM::Commands::Delete
|
12
|
-
adapter :sql
|
12
|
+
config.component.adapter = :sql
|
13
13
|
|
14
14
|
include ErrorWrapper
|
15
15
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "rom/sql/commands/error_wrapper"
|
4
4
|
|
5
5
|
module ROM
|
6
6
|
module SQL
|
@@ -9,7 +9,7 @@ module ROM
|
|
9
9
|
#
|
10
10
|
# @api public
|
11
11
|
class Update < ROM::Commands::Update
|
12
|
-
adapter :sql
|
12
|
+
config.component.adapter = :sql
|
13
13
|
|
14
14
|
include ErrorWrapper
|
15
15
|
|
@@ -52,11 +52,11 @@ module ROM
|
|
52
52
|
# Yields tuples for insertion or return an enumerator
|
53
53
|
#
|
54
54
|
# @api private
|
55
|
-
def with_input_tuples(tuples, &)
|
56
|
-
input_tuples = [tuples].flatten(1).map
|
55
|
+
def with_input_tuples(tuples, &block)
|
56
|
+
input_tuples = Array([tuples]).flatten(1).map
|
57
57
|
return input_tuples unless block_given?
|
58
58
|
|
59
|
-
input_tuples.each(&)
|
59
|
+
input_tuples.each(&block)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
data/lib/rom/sql/commands.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "rom/commands"
|
4
4
|
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
5
|
+
require "rom/sql/commands/create"
|
6
|
+
require "rom/sql/commands/update"
|
7
|
+
require "rom/sql/commands/delete"
|
data/lib/rom/sql/dsl.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "concurrent/map"
|
4
|
+
require "rom/support/inflector"
|
5
|
+
require "rom/constants"
|
6
6
|
|
7
7
|
module ROM
|
8
8
|
module SQL
|
@@ -59,9 +59,7 @@ module ROM
|
|
59
59
|
#
|
60
60
|
# @example
|
61
61
|
# users.where { exists(users.where(name: 'John')) }
|
62
|
-
# users.select_append { |r|
|
63
|
-
# exists(r[:posts].where(r[:posts][:user_id] => id)).as(:has_posts)
|
64
|
-
# }
|
62
|
+
# users.select_append { |r| exists(r[:posts].where(r[:posts][:user_id] => id)).as(:has_posts) }
|
65
63
|
#
|
66
64
|
# @api public
|
67
65
|
def exists(relation)
|
data/lib/rom/sql/errors.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "sequel/database/logging"
|
4
|
+
require "active_support/notifications"
|
5
5
|
|
6
6
|
module ROM
|
7
7
|
module SQL
|
8
8
|
module ActiveSupportInstrumentation
|
9
9
|
def log_connection_yield(sql, _conn, args = nil)
|
10
10
|
ActiveSupport::Notifications.instrument(
|
11
|
-
|
11
|
+
"sql.rom",
|
12
12
|
sql: sql,
|
13
13
|
name: instrumentation_name,
|
14
14
|
binds: args
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "rom/sql/schema/attributes_inferrer"
|
4
4
|
|
5
5
|
module ROM
|
6
6
|
module SQL
|
@@ -9,10 +9,10 @@ module ROM
|
|
9
9
|
defines :db_type_mapping
|
10
10
|
|
11
11
|
db_type_mapping(
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
"tinytext" => Types::String,
|
13
|
+
"text" => Types::String,
|
14
|
+
"mediumtext" => Types::String,
|
15
|
+
"longtext" => Types::String
|
16
16
|
).freeze
|
17
17
|
|
18
18
|
def map_type(ruby_type, db_type, **_)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "rom/sql/commands/create"
|
4
|
+
require "rom/sql/commands/update"
|
5
5
|
|
6
6
|
module ROM
|
7
7
|
module SQL
|
@@ -83,29 +83,33 @@ module ROM
|
|
83
83
|
#
|
84
84
|
# @api public
|
85
85
|
class Upsert < SQL::Commands::Create
|
86
|
-
adapter :sql
|
86
|
+
config.component.adapter = :sql
|
87
87
|
|
88
|
-
|
88
|
+
setting :constraint
|
89
|
+
setting :conflict_target
|
90
|
+
setting :conflict_where
|
91
|
+
setting :update_statement
|
92
|
+
setting :update_where
|
89
93
|
|
90
94
|
# @!attribute [r] constraint
|
91
95
|
# @return [Symbol] the name of the constraint expected to be violated
|
92
|
-
option :constraint, default: -> {
|
96
|
+
option :constraint, default: -> { config.constraint }
|
93
97
|
|
94
98
|
# @!attribute [r] conflict_target
|
95
99
|
# @return [Object] the column or expression to handle a violation on
|
96
|
-
option :conflict_target, default: -> {
|
100
|
+
option :conflict_target, default: -> { config.conflict_target }
|
97
101
|
|
98
102
|
# @!attribute [r] conflict_where
|
99
103
|
# @return [Object] the index filter, when using a partial index to determine uniqueness
|
100
|
-
option :conflict_where, default: -> {
|
104
|
+
option :conflict_where, default: -> { config.conflict_where }
|
101
105
|
|
102
106
|
# @!attribute [r] update_statement
|
103
107
|
# @return [Object] the update statement which will be executed in case of a violation
|
104
|
-
option :update_statement, default: -> {
|
108
|
+
option :update_statement, default: -> { config.update_statement }
|
105
109
|
|
106
110
|
# @!attribute [r] update_where
|
107
111
|
# @return [Object] the WHERE clause to be added to the update
|
108
|
-
option :update_where, default: -> {
|
112
|
+
option :update_where, default: -> { config.update_where }
|
109
113
|
|
110
114
|
# Tries to insert provided tuples and do an update (or nothing)
|
111
115
|
# when the inserted record violates a unique constraint and hence
|
@@ -137,27 +141,5 @@ module ROM
|
|
137
141
|
end
|
138
142
|
|
139
143
|
Commands::Postgres = Postgres::Commands
|
140
|
-
|
141
|
-
Gateway.subscribe('configuration.commands.class.before_build') do |event|
|
142
|
-
klass = event[:command]
|
143
|
-
|
144
|
-
# TODO: remove this conditional in favor of `adapter: :sql` in subscribe
|
145
|
-
# this is here for backward compatibilty with rom-core 4.x
|
146
|
-
if klass.adapter == :sql
|
147
|
-
dataset = event[:dataset]
|
148
|
-
type = dataset.db.database_type
|
149
|
-
|
150
|
-
if type == :postgres
|
151
|
-
ext =
|
152
|
-
if klass < Commands::Create
|
153
|
-
Postgres::Commands::Create
|
154
|
-
elsif klass < Commands::Update
|
155
|
-
Postgres::Commands::Update
|
156
|
-
end
|
157
|
-
|
158
|
-
klass.include(ext) if ext
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
144
|
end
|
163
145
|
end
|
@@ -6,40 +6,37 @@ module ROM
|
|
6
6
|
class TypeBuilder < Schema::TypeBuilder
|
7
7
|
defines :db_numeric_types, :db_type_mapping, :db_array_type_matcher
|
8
8
|
|
9
|
-
db_numeric_types [
|
10
|
-
|
11
|
-
'decimal', 'numeric', 'real',
|
12
|
-
'double precision', 'serial', 'bigserial'
|
13
|
-
].to_set.freeze
|
9
|
+
db_numeric_types ["smallint", "integer", "bigint", "decimal", "numeric", "real",
|
10
|
+
"double precision", "serial", "bigserial"].to_set.freeze
|
14
11
|
|
15
12
|
db_type_mapping(
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
13
|
+
"uuid" => Types::UUID,
|
14
|
+
"money" => Types::Money,
|
15
|
+
"bytea" => Types::Bytea,
|
16
|
+
"json" => Types::JSON,
|
17
|
+
"jsonb" => Types::JSONB,
|
18
|
+
"xml" => Types::XML,
|
19
|
+
"inet" => Types::IPAddress,
|
20
|
+
"cidr" => Types::IPAddress,
|
21
|
+
"macaddr" => SQL::Types::String,
|
22
|
+
"point" => Types::Point,
|
23
|
+
"hstore" => Types::HStore,
|
24
|
+
"line" => Types::Line,
|
25
|
+
"circle" => Types::Circle,
|
26
|
+
"box" => Types::Box,
|
27
|
+
"lseg" => Types::LineSegment,
|
28
|
+
"polygon" => Types::Polygon,
|
29
|
+
"path" => Types::Path,
|
30
|
+
"int4range" => Types::Int4Range,
|
31
|
+
"int8range" => Types::Int8Range,
|
32
|
+
"numrange" => Types::NumRange,
|
33
|
+
"tsrange" => Types::TsRange,
|
34
|
+
"tstzrange" => Types::TsTzRange,
|
35
|
+
"daterange" => Types::DateRange,
|
36
|
+
"ltree" => Types::LTree
|
40
37
|
).freeze
|
41
38
|
|
42
|
-
db_array_type_matcher
|
39
|
+
db_array_type_matcher "[]"
|
43
40
|
|
44
41
|
def map_pk_type(type, db_type, **options)
|
45
42
|
if numeric?(type, db_type)
|
@@ -66,7 +63,7 @@ module ROM
|
|
66
63
|
|
67
64
|
def map_db_type(db_type)
|
68
65
|
self.class.db_type_mapping[db_type] ||
|
69
|
-
(db_type.start_with?(
|
66
|
+
(db_type.start_with?("timestamp") ? SQL::Types::Time : nil)
|
70
67
|
end
|
71
68
|
|
72
69
|
def numeric?(ruby_type, db_type)
|
@@ -7,36 +7,35 @@ module ROM
|
|
7
7
|
class TypeSerializer < ROM::SQL::TypeSerializer
|
8
8
|
mapping(
|
9
9
|
mapping.merge(
|
10
|
-
SQL::Types::String =>
|
11
|
-
Types::UUID =>
|
12
|
-
Types::XML =>
|
13
|
-
Types::Money =>
|
14
|
-
Types::Bytea =>
|
15
|
-
Types::JSON =>
|
16
|
-
Types::JSONB =>
|
17
|
-
Types::HStore =>
|
18
|
-
Types::IPAddress =>
|
19
|
-
Types::
|
20
|
-
Types::
|
21
|
-
Types::
|
22
|
-
Types::
|
23
|
-
Types::
|
24
|
-
Types::
|
25
|
-
Types::
|
26
|
-
Types::
|
27
|
-
Types::
|
28
|
-
Types::
|
29
|
-
Types::
|
30
|
-
Types::
|
31
|
-
Types::
|
32
|
-
Types::
|
33
|
-
Types::LTree => 'ltree'
|
10
|
+
SQL::Types::String => "text",
|
11
|
+
Types::UUID => "uuid",
|
12
|
+
Types::XML => "xml",
|
13
|
+
Types::Money => "money",
|
14
|
+
Types::Bytea => "bytea",
|
15
|
+
Types::JSON => "json",
|
16
|
+
Types::JSONB => "jsonb",
|
17
|
+
Types::HStore => "hstore",
|
18
|
+
Types::IPAddress => "inet",
|
19
|
+
Types::Point => "point",
|
20
|
+
Types::Line => "line",
|
21
|
+
Types::Circle => "circle",
|
22
|
+
Types::Box => "box",
|
23
|
+
Types::LineSegment => "lseg",
|
24
|
+
Types::Polygon => "polygon",
|
25
|
+
Types::Path => "path",
|
26
|
+
Types::Int4Range => "int4range",
|
27
|
+
Types::Int8Range => "int8range",
|
28
|
+
Types::NumRange => "numrange",
|
29
|
+
Types::TsRange => "tsrange",
|
30
|
+
Types::TsTzRange => "tstzrange",
|
31
|
+
Types::DateRange => "daterange",
|
32
|
+
Types::LTree => "ltree"
|
34
33
|
)
|
35
34
|
)
|
36
35
|
|
37
36
|
def call(type)
|
38
37
|
super do
|
39
|
-
if type.respond_to?(:primitive) && type.primitive.equal?(
|
38
|
+
if type.respond_to?(:primitive) && type.primitive.equal?(Array)
|
40
39
|
"#{type.meta[:type]}[]"
|
41
40
|
end
|
42
41
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "sequel/core"
|
4
4
|
|
5
5
|
Sequel.extension(:pg_array, :pg_array_ops)
|
6
6
|
|
7
|
-
require
|
7
|
+
require "rom/sql/extensions/postgres/types/array_types"
|
8
8
|
|
9
9
|
module ROM
|
10
10
|
module SQL
|
@@ -123,7 +123,7 @@ module ROM
|
|
123
123
|
end
|
124
124
|
|
125
125
|
def any(_type, expr, value)
|
126
|
-
Attribute[SQL::Types::Bool].meta(sql_expr: {
|
126
|
+
Attribute[SQL::Types::Bool].meta(sql_expr: {value => expr.pg_array.any})
|
127
127
|
end
|
128
128
|
|
129
129
|
def contained_by(type, expr, other)
|
@@ -142,7 +142,7 @@ module ROM
|
|
142
142
|
Attribute[type].meta(sql_expr: expr.pg_array.remove(cast(type, value)))
|
143
143
|
end
|
144
144
|
|
145
|
-
def join(_type, expr, delimiter =
|
145
|
+
def join(_type, expr, delimiter = "", null = nil)
|
146
146
|
Attribute[SQL::Types::String].meta(sql_expr: expr.pg_array.join(delimiter, null))
|
147
147
|
end
|
148
148
|
|