rom-sql 3.5.0 → 4.0.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -3
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/lib/rom/plugins/relation/sql/auto_restrictions.rb +11 -10
- data/lib/rom/plugins/relation/sql/default_views.rb +75 -0
- data/lib/rom/plugins/relation/sql/instrumentation.rb +11 -10
- data/lib/rom/plugins/relation/sql/postgres/explain.rb +4 -4
- data/lib/rom/plugins/relation/sql/postgres/full_text_search.rb +18 -16
- data/lib/rom/plugins/relation/sql/postgres/streaming.rb +12 -9
- data/lib/rom/sql/associations/many_to_many.rb +7 -7
- data/lib/rom/sql/associations/many_to_one.rb +3 -3
- 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 +9 -9
- data/lib/rom/sql/attribute_aliasing.rb +2 -3
- data/lib/rom/sql/commands/create.rb +5 -4
- data/lib/rom/sql/commands/delete.rb +2 -2
- data/lib/rom/sql/commands/update.rb +5 -4
- data/lib/rom/sql/commands.rb +4 -4
- data/lib/rom/sql/dsl.rb +3 -3
- data/lib/rom/sql/errors.rb +3 -3
- data/lib/rom/sql/extensions/active_support_notifications.rb +4 -4
- 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 -24
- 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 +27 -27
- data/lib/rom/sql/extensions/postgres/types/json.rb +9 -9
- data/lib/rom/sql/extensions/postgres/types/ltree.rb +61 -34
- data/lib/rom/sql/extensions/postgres/types/network.rb +2 -2
- data/lib/rom/sql/extensions/postgres/types/range.rb +25 -25
- 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 +3 -3
- 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 +17 -16
- data/lib/rom/sql/gateway.rb +44 -17
- data/lib/rom/sql/group_dsl.rb +1 -1
- 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/migrator.rb +11 -11
- data/lib/rom/sql/migration/runner.rb +3 -3
- data/lib/rom/sql/migration/schema_diff.rb +7 -8
- data/lib/rom/sql/migration/writer.rb +12 -12
- data/lib/rom/sql/migration.rb +4 -8
- data/lib/rom/sql/order_dsl.rb +1 -1
- data/lib/rom/sql/plugin/associates.rb +49 -11
- data/lib/rom/sql/plugin/pagination.rb +5 -3
- 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 +2 -2
- data/lib/rom/sql/rake_task.rb +2 -2
- data/lib/rom/sql/relation/reading.rb +34 -27
- data/lib/rom/sql/relation/writing.rb +11 -10
- data/lib/rom/sql/relation.rb +57 -89
- data/lib/rom/sql/restriction_dsl.rb +1 -1
- data/lib/rom/sql/schema/attributes_inferrer.rb +3 -3
- data/lib/rom/sql/schema/dsl.rb +4 -2
- data/lib/rom/sql/schema/index_dsl.rb +3 -5
- data/lib/rom/sql/schema/inferrer.rb +25 -23
- data/lib/rom/sql/schema/type_builder.rb +2 -2
- data/lib/rom/sql/schema.rb +9 -21
- data/lib/rom/sql/spec/support.rb +5 -5
- data/lib/rom/sql/tasks/migration_tasks.rake +12 -12
- data/lib/rom/sql/transaction.rb +4 -2
- data/lib/rom/sql/type_extensions.rb +3 -1
- data/lib/rom/sql/type_serializer.rb +10 -10
- data/lib/rom/sql/types.rb +4 -4
- data/lib/rom/sql/version.rb +1 -1
- data/lib/rom/sql/wrap.rb +1 -1
- data/lib/rom/sql.rb +13 -14
- data/lib/rom/types/values.rb +2 -2
- data/lib/rom-sql.rb +1 -1
- metadata +14 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6a932fc53433b38ce71cb363a4e29e4fef4f949849f47d2b4f2bb2bc8e6cf35
|
4
|
+
data.tar.gz: da89ced65458c9facaffe74e365eb8bf81f0ee18718aba6b2e92da0717ef0f5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6648c04e92f83b529942d6b46587e577523b27aba2bfd0cdacfd37c69a8594ca0bf63df564d8f13ec288dece1e837e9163eab96eeb068b455dab00567b9fe44
|
7
|
+
data.tar.gz: ef78eaaacc3810bc7accf3e3fa5fc38df951f20b4df0ed57dd333adba2a90d450aebf84318d81541b2770731f1b4af21289ad66040c3d822ba4e240dd0bfb056
|
data/CHANGELOG.md
CHANGED
@@ -1,16 +1,30 @@
|
|
1
1
|
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
2
|
|
3
|
-
##
|
3
|
+
## 4.0.0.alpha1 2022-04-15
|
4
4
|
|
5
|
+
See [rom 6.0 upgrade guide](https://github.com/rom-rb/rom/wiki/6.0-Upgrade-Guide).
|
5
6
|
|
6
|
-
###
|
7
|
+
### Changed
|
8
|
+
|
9
|
+
- [internal] all plugins have been ported to the new API (via #402) (@solnic)
|
10
|
+
- [internal] `:default_views` plugin was added and it's enabled by default (via #402) (@solnic)
|
11
|
+
- [internal] `indexes` schema DSL is now a plugin called `:schema_indexes` (via #402) (@solnic)
|
12
|
+
- [internal] `Gateway#command` is now used to instantiate sql-specific commands (via #402) (@solnic)
|
13
|
+
|
14
|
+
[Compare v3.5.0...v4.0.0.alpha1](https://github.com/rom-rb/rom-sql/compare/v3.5.0...v4.0.0.alpha1)
|
15
|
+
|
16
|
+
## 3.5.0 2021-03-26
|
7
17
|
|
8
|
-
- Restored the fix for #390 that was lost by an accident in 3.3.3 and 3.4.0 (@solnic)
|
9
18
|
|
10
19
|
### Added
|
11
20
|
|
12
21
|
- Support for using partial indixes in PG upsert commands (issue #394 fixed via #395) (@smaximov)
|
13
22
|
|
23
|
+
### Fixed
|
24
|
+
|
25
|
+
- Restore the fix for #390 that was lost by an accident in 3.3.3 and 3.4.0 (@solnic)
|
26
|
+
|
27
|
+
|
14
28
|
[Compare v3.4.0...v3.5.0](https://github.com/rom-rb/rom-sql/compare/v3.4.0...v3.5.0)
|
15
29
|
|
16
30
|
## 3.4.0 2021-03-19
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
[![CI Status](https://github.com/rom-rb/rom-sql/workflows/ci/badge.svg)][actions]
|
11
11
|
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/8e2cbaf78af44185876c8fa41540d7ea)][codacy]
|
12
12
|
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/8e2cbaf78af44185876c8fa41540d7ea)][codacy]
|
13
|
-
[![Inline docs](http://inch-ci.org/github/rom-rb/rom-sql.svg?branch=
|
13
|
+
[![Inline docs](http://inch-ci.org/github/rom-rb/rom-sql.svg?branch=main)][inchpages]
|
14
14
|
|
15
15
|
## Links
|
16
16
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "dry/effects"
|
4
4
|
|
5
5
|
module ROM
|
6
6
|
module Plugins
|
@@ -27,15 +27,16 @@ module ROM
|
|
27
27
|
#
|
28
28
|
# @api public
|
29
29
|
module AutoRestrictions
|
30
|
-
extend
|
30
|
+
extend Dry::Effects.Reader(:registry)
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
# @api private
|
33
|
+
def self.apply(target, **)
|
34
|
+
methods, mod = AutoRestrictions.restriction_methods(registry.schemas.canonical(target))
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
target.class_eval do
|
37
|
+
include(mod)
|
38
|
+
methods.each { |meth| auto_curry(meth) }
|
39
|
+
end
|
39
40
|
end
|
40
41
|
|
41
42
|
# @api private
|
@@ -46,7 +47,7 @@ module ROM
|
|
46
47
|
next if index.partial?
|
47
48
|
|
48
49
|
attributes = index.to_a
|
49
|
-
meth_name = :"by_#{
|
50
|
+
meth_name = :"by_#{attributes.map(&:name).join("_and_")}"
|
50
51
|
|
51
52
|
next if generated.include?(meth_name)
|
52
53
|
|
@@ -78,7 +79,7 @@ module ROM
|
|
78
79
|
end
|
79
80
|
|
80
81
|
ROM.plugins do
|
81
|
-
adapter
|
82
|
+
adapter(:sql) do
|
82
83
|
register :auto_restrictions, ROM::Plugins::Relation::SQL::AutoRestrictions, type: :relation
|
83
84
|
end
|
84
85
|
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry/effects"
|
4
|
+
|
5
|
+
module ROM
|
6
|
+
module Plugins
|
7
|
+
module Relation
|
8
|
+
module SQL
|
9
|
+
# @api private
|
10
|
+
module DefaultViews
|
11
|
+
extend Dry::Effects.Reader(:registry)
|
12
|
+
|
13
|
+
# @api private
|
14
|
+
def self.apply(target, **)
|
15
|
+
define_default_views!(target, registry.schemas.canonical(target))
|
16
|
+
end
|
17
|
+
|
18
|
+
# @api private
|
19
|
+
def self.define_default_views!(target, schema)
|
20
|
+
if schema.primary_key.size > 1
|
21
|
+
# @!method by_pk(val1, val2)
|
22
|
+
# Return a relation restricted by its composite primary key
|
23
|
+
#
|
24
|
+
# @param [Array] args A list with composite pk values
|
25
|
+
#
|
26
|
+
# @return [SQL::Relation]
|
27
|
+
#
|
28
|
+
# @api public
|
29
|
+
target.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
30
|
+
undef :by_pk if method_defined?(:by_pk)
|
31
|
+
|
32
|
+
def by_pk(#{schema.primary_key.map(&:name).join(", ")})
|
33
|
+
where(#{schema.primary_key.map { |attr| "schema.canonical[:#{attr.name}] => #{attr.name}" }.join(", ")})
|
34
|
+
end
|
35
|
+
RUBY
|
36
|
+
else
|
37
|
+
# @!method by_pk(pk)
|
38
|
+
# Return a relation restricted by its primary key
|
39
|
+
#
|
40
|
+
# @param [Object] pk The primary key value
|
41
|
+
#
|
42
|
+
# @return [SQL::Relation]
|
43
|
+
#
|
44
|
+
# @api public
|
45
|
+
target.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
46
|
+
undef :by_pk if method_defined?(:by_pk)
|
47
|
+
|
48
|
+
def by_pk(pk)
|
49
|
+
if primary_key.nil?
|
50
|
+
raise MissingPrimaryKeyError.new(
|
51
|
+
"Missing primary key for :\#{schema.name}"
|
52
|
+
)
|
53
|
+
end
|
54
|
+
where(schema.canonical[schema.canonical.primary_key_name].qualified => pk)
|
55
|
+
end
|
56
|
+
RUBY
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# @api private
|
61
|
+
def self.primary_key_columns(db, table)
|
62
|
+
names = db.respond_to?(:primary_key) ? Array(db.primary_key(table)) : [:id]
|
63
|
+
names.map { |col| :"#{table}__#{col}" }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
ROM.plugins do
|
72
|
+
adapter(:sql) do
|
73
|
+
register :default_views, ROM::Plugins::Relation::SQL::DefaultViews, type: :relation
|
74
|
+
end
|
75
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "dry/effects"
|
4
|
+
|
3
5
|
module ROM
|
4
6
|
module Plugins
|
5
7
|
module Relation
|
@@ -26,18 +28,14 @@ module ROM
|
|
26
28
|
#
|
27
29
|
# @api public
|
28
30
|
module Instrumentation
|
29
|
-
extend
|
31
|
+
extend Dry::Effects.Reader(:registry)
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
+
def self.apply(target, notifications:, **)
|
34
|
+
db = registry.gateways[target.config.component.gateway].connection
|
33
35
|
|
34
|
-
|
35
|
-
db_notifications = relations.values.map { |r| [r.dataset.db, r.notifications] }.uniq.to_h
|
36
|
+
return if db.respond_to?(:rom_instrumentation?)
|
36
37
|
|
37
|
-
|
38
|
-
instrumenter = Instrumenter.new(db.database_type, notifications)
|
39
|
-
db.extend(instrumenter)
|
40
|
-
end
|
38
|
+
db.extend(Instrumenter.new(db.database_type, notifications))
|
41
39
|
end
|
42
40
|
|
43
41
|
# This stateful module is used to extend database connection objects
|
@@ -56,6 +54,7 @@ module ROM
|
|
56
54
|
|
57
55
|
# @api private
|
58
56
|
def initialize(name, notifications)
|
57
|
+
super()
|
59
58
|
@name = name
|
60
59
|
@notifications = notifications
|
61
60
|
define_log_connection_yield
|
@@ -68,6 +67,8 @@ module ROM
|
|
68
67
|
name = self.name
|
69
68
|
notifications = self.notifications
|
70
69
|
|
70
|
+
define_method(:rom_instrumentation?) { true }
|
71
|
+
|
71
72
|
define_method(:log_connection_yield) do |*args, &block|
|
72
73
|
notifications.instrument(:sql, name: name, query: args[0]) do
|
73
74
|
super(*args, &block)
|
@@ -90,7 +91,7 @@ module ROM
|
|
90
91
|
end
|
91
92
|
|
92
93
|
ROM.plugins do
|
93
|
-
adapter
|
94
|
+
adapter(:sql) do
|
94
95
|
register :instrumentation, ROM::Plugins::Relation::SQL::Instrumentation, type: :relation
|
95
96
|
end
|
96
97
|
end
|
@@ -28,15 +28,15 @@ module ROM
|
|
28
28
|
def explain(format: :text, **options)
|
29
29
|
bool_options = options.map { |opt, value| "#{opt.to_s.upcase} #{!!value}" }
|
30
30
|
format_option = "FORMAT #{format.to_s.upcase}"
|
31
|
-
explain_value = [format_option, *bool_options].join(
|
31
|
+
explain_value = [format_option, *bool_options].join(", ")
|
32
32
|
|
33
33
|
query = "EXPLAIN (#{explain_value}) #{dataset.sql}"
|
34
34
|
|
35
|
-
rows = dataset.with_sql(query).map(:
|
35
|
+
rows = dataset.with_sql(query).map(:"QUERY PLAN")
|
36
36
|
|
37
37
|
case format
|
38
38
|
when :json
|
39
|
-
rows[0][0][
|
39
|
+
rows[0][0]["Plan"]
|
40
40
|
else
|
41
41
|
rows.join("\n")
|
42
42
|
end
|
@@ -49,7 +49,7 @@ module ROM
|
|
49
49
|
end
|
50
50
|
|
51
51
|
ROM.plugins do
|
52
|
-
adapter
|
52
|
+
adapter(:sql) do
|
53
53
|
register :pg_explain, ROM::Plugins::Relation::SQL::Postgres::Explain, type: :relation
|
54
54
|
end
|
55
55
|
end
|
@@ -13,23 +13,24 @@ module ROM
|
|
13
13
|
# By default, searching for the inclusion of any of the terms in any of the cols.
|
14
14
|
#
|
15
15
|
# @example
|
16
|
-
#
|
17
|
-
#
|
18
|
-
# @option :headline [String] Append a expression to the selected columns aliased to headline that contains an extract of the matched text.
|
16
|
+
# # => Relation which match the 'apples' phrase
|
17
|
+
# posts.full_text_search([:title, :content], 'apples', language: 'english')
|
19
18
|
#
|
19
|
+
# @option :headline [String] Append a expression to the selected columns aliased to headline that contains
|
20
|
+
# an extract of the matched text.
|
20
21
|
# @option :language [String] The language to use for the search (default: 'simple')
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
# @option :phrase [Boolean] Similar to :plain, but also adding an ILIKE filter to ensure that returned rows
|
25
|
-
#
|
22
|
+
# @option :plain [Boolean] Whether a plain search should be used (default: false). In this case, terms
|
23
|
+
# should be a single string, and it will do a search where cols contains all of the words in terms.
|
24
|
+
# This ignores search operators in terms.
|
25
|
+
# @option :phrase [Boolean] Similar to :plain, but also adding an ILIKE filter to ensure that returned rows
|
26
|
+
# also include the exact phrase used.
|
26
27
|
# @option :rank [Boolean] Set to true to order by the rank, so that closer matches are returned first.
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
28
|
+
# @option :to_tsquery [Symbol] Can be set to :plain or :phrase to specify the function to use to convert
|
29
|
+
# the terms to a ts_query.
|
30
|
+
# @option :tsquery [Boolean] Specifies the terms argument is already a valid SQL expression returning
|
31
|
+
# a tsquery, and can be used directly in the query.
|
32
|
+
# @option :tsvector [Boolean] Specifies the cols argument is already a valid SQL expression returning
|
33
|
+
# a tsvector, and can be used directly in the query.
|
33
34
|
#
|
34
35
|
# @return [Relation]
|
35
36
|
#
|
@@ -47,7 +48,8 @@ module ROM
|
|
47
48
|
end
|
48
49
|
|
49
50
|
ROM.plugins do
|
50
|
-
adapter
|
51
|
-
register :pg_full_text_search, ROM::Plugins::Relation::SQL::Postgres::FullTextSearch,
|
51
|
+
adapter(:sql) do
|
52
|
+
register :pg_full_text_search, ROM::Plugins::Relation::SQL::Postgres::FullTextSearch,
|
53
|
+
type: :relation
|
52
54
|
end
|
53
55
|
end
|
@@ -9,16 +9,16 @@ module ROM
|
|
9
9
|
#
|
10
10
|
# @api public
|
11
11
|
module Streaming
|
12
|
-
extend
|
12
|
+
extend Dry::Effects.Reader(:registry)
|
13
13
|
|
14
14
|
class StreamingNotSupportedError < StandardError; end
|
15
15
|
|
16
|
-
|
17
|
-
conn =
|
16
|
+
def self.apply(target, **_opts)
|
17
|
+
conn = registry.gateways[target.config.component.gateway].connection
|
18
18
|
|
19
|
-
|
19
|
+
return unless conn.database_type.to_sym == :postgres
|
20
20
|
|
21
|
-
|
21
|
+
return if defined?(JRUBY_VERSION)
|
22
22
|
|
23
23
|
begin
|
24
24
|
require "sequel_pg"
|
@@ -31,8 +31,11 @@ module ROM
|
|
31
31
|
end
|
32
32
|
|
33
33
|
conn.extension(:pg_streaming)
|
34
|
+
|
35
|
+
target.include(Streaming)
|
34
36
|
end
|
35
37
|
|
38
|
+
# @api private
|
36
39
|
def self.included(klass)
|
37
40
|
super
|
38
41
|
ROM::Relation::Graph.include(Combined)
|
@@ -46,11 +49,11 @@ module ROM
|
|
46
49
|
# @see https://github.com/jeremyevans/sequel_pg#streaming- sequel_pg docs
|
47
50
|
#
|
48
51
|
# @example
|
49
|
-
# posts.
|
52
|
+
# posts.stream_each { |post| puts CSV.generate_line(post) }
|
50
53
|
#
|
51
54
|
# @return [Relation]
|
52
55
|
#
|
53
|
-
# @api
|
56
|
+
# @api public
|
54
57
|
def stream_each
|
55
58
|
raise StreamingNotSupportedError, "not supported on jruby"
|
56
59
|
end
|
@@ -61,7 +64,7 @@ module ROM
|
|
61
64
|
# @see https://github.com/jeremyevans/sequel_pg#streaming- sequel_pg docs
|
62
65
|
#
|
63
66
|
# @example
|
64
|
-
# posts.
|
67
|
+
# posts.stream_each { |post| puts CSV.generate_line(post) }
|
65
68
|
#
|
66
69
|
# @return [Relation]
|
67
70
|
#
|
@@ -102,7 +105,7 @@ module ROM
|
|
102
105
|
end
|
103
106
|
|
104
107
|
ROM.plugins do
|
105
|
-
adapter
|
108
|
+
adapter(:sql) do
|
106
109
|
register :pg_streaming, ROM::Plugins::Relation::SQL::Postgres::Streaming, type: :relation
|
107
110
|
end
|
108
111
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "rom/associations/many_to_many"
|
4
|
+
require "rom/sql/associations/core"
|
5
|
+
require "rom/sql/associations/self_ref"
|
6
6
|
|
7
7
|
module ROM
|
8
8
|
module SQL
|
@@ -17,10 +17,10 @@ module ROM
|
|
17
17
|
|
18
18
|
schema =
|
19
19
|
if left.schema.key?(foreign_key)
|
20
|
-
if target
|
21
|
-
target.schema.merge(join_schema)
|
22
|
-
else
|
20
|
+
if target == self.target
|
23
21
|
left.schema.uniq.project(*columns)
|
22
|
+
else
|
23
|
+
target.schema.merge(join_schema)
|
24
24
|
end
|
25
25
|
else
|
26
26
|
target_schema
|
@@ -50,7 +50,7 @@ module ROM
|
|
50
50
|
|
51
51
|
# @api public
|
52
52
|
def join_keys
|
53
|
-
{
|
53
|
+
{source_attr => target_attr}
|
54
54
|
end
|
55
55
|
|
56
56
|
# @api public
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "rom/associations/many_to_one"
|
4
|
+
require "rom/sql/associations/core"
|
5
|
+
require "rom/sql/associations/self_ref"
|
6
6
|
|
7
7
|
module ROM
|
8
8
|
module SQL
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "rom/associations/one_to_many"
|
4
|
+
require "rom/sql/associations/core"
|
5
|
+
require "rom/sql/associations/self_ref"
|
6
6
|
|
7
7
|
module ROM
|
8
8
|
module SQL
|
data/lib/rom/sql/associations.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
3
|
+
require "rom/sql/associations/many_to_many"
|
4
|
+
require "rom/sql/associations/many_to_one"
|
5
|
+
require "rom/sql/associations/one_to_many"
|
6
|
+
require "rom/sql/associations/one_to_one"
|
7
|
+
require "rom/sql/associations/one_to_one_through"
|
data/lib/rom/sql/attribute.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
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
|
@@ -280,7 +280,7 @@ module ROM
|
|
280
280
|
# @return [SQL::Function]
|
281
281
|
#
|
282
282
|
# @api public
|
283
|
-
def concat(other, sep =
|
283
|
+
def concat(other, sep = " ")
|
284
284
|
Function.new(type).concat(self, sep, other)
|
285
285
|
end
|
286
286
|
|
@@ -366,7 +366,7 @@ module ROM
|
|
366
366
|
def case(mapping)
|
367
367
|
mapping = mapping.dup
|
368
368
|
otherwise = mapping.delete(:else) do
|
369
|
-
raise ArgumentError,
|
369
|
+
raise ArgumentError, "provide the default case using the :else keyword"
|
370
370
|
end
|
371
371
|
|
372
372
|
type = mapping.values[0].type
|
@@ -19,8 +19,7 @@ module ROM
|
|
19
19
|
sql_expr: alias_sql_expr(sql_expr, new_alias_name)
|
20
20
|
)
|
21
21
|
end
|
22
|
-
|
23
|
-
|
22
|
+
alias_method :as, :aliased
|
24
23
|
|
25
24
|
# Return true if this attribute is an aliased projection
|
26
25
|
#
|
@@ -46,7 +45,7 @@ module ROM
|
|
46
45
|
#
|
47
46
|
# @api private
|
48
47
|
def aliased_projection?
|
49
|
-
|
48
|
+
meta[:sql_expr].is_a?(Sequel::SQL::AliasedExpression)
|
50
49
|
end
|
51
50
|
|
52
51
|
private
|
@@ -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,10 +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)
|
63
|
+
def with_input_tuples(tuples, &block)
|
64
64
|
input_tuples = Array([tuples]).flatten(1).map
|
65
65
|
return input_tuples unless block_given?
|
66
|
-
|
66
|
+
|
67
|
+
input_tuples.each(&block)
|
67
68
|
end
|
68
69
|
end
|
69
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,10 +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)
|
55
|
+
def with_input_tuples(tuples, &block)
|
56
56
|
input_tuples = Array([tuples]).flatten(1).map
|
57
57
|
return input_tuples unless block_given?
|
58
|
-
|
58
|
+
|
59
|
+
input_tuples.each(&block)
|
59
60
|
end
|
60
61
|
end
|
61
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