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
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,83 +1,29 @@
|
|
1
1
|
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
2
|
|
3
|
-
##
|
4
|
-
|
5
|
-
### Changed
|
6
|
-
|
7
|
-
- Minimum Ruby version is now 3.1 (@flash-gordon)
|
8
|
-
|
9
|
-
[Compare v3.6.5...v3.7.0](https://github.com/rom-rb/rom-sql/compare/v3.6.5...v3.7.0)
|
10
|
-
|
11
|
-
## 3.6.5 2024-12-25
|
12
|
-
|
13
|
-
|
14
|
-
### Fixed
|
15
|
-
|
16
|
-
- Fix syntax error under Ruby 3.4 (@flash-gordon)
|
17
|
-
|
18
|
-
[Compare v3.6.4...v3.6.5](https://github.com/rom-rb/rom-sql/compare/v3.6.4...v3.6.5)
|
19
|
-
|
20
|
-
## 3.6.4 2024-07-01
|
21
|
-
|
22
|
-
|
23
|
-
### Fixed
|
24
|
-
|
25
|
-
- Excessive logging when same gateway is shared between multiple containers (@flash-gordon)
|
26
|
-
- Warning about using color option from active-support log subscriber (@flash-gordon + @bendangelo)
|
27
|
-
|
28
|
-
|
29
|
-
[Compare v3.6.3...v3.6.4](https://github.com/rom-rb/rom-sql/compare/v3.6.3...v3.6.4)
|
30
|
-
|
31
|
-
## 3.6.3 2024-05-06
|
32
|
-
|
33
|
-
|
34
|
-
### Fixed
|
35
|
-
|
36
|
-
- Fix using `.filter` with a block for aggregate functions (@flash-gordon)
|
3
|
+
## 4.0.0.alpha1 2022-04-15
|
37
4
|
|
5
|
+
See [rom 6.0 upgrade guide](https://github.com/rom-rb/rom/wiki/6.0-Upgrade-Guide).
|
38
6
|
|
39
|
-
|
40
|
-
|
41
|
-
## 3.6.2 2024-01-09
|
42
|
-
|
43
|
-
|
44
|
-
### Fixed
|
45
|
-
|
46
|
-
- Fix Hash.new warning in Ruby 3.3 (@flash-gordon)
|
47
|
-
|
48
|
-
|
49
|
-
[Compare v3.6.1...v3.6.2](https://github.com/rom-rb/rom-sql/compare/v3.6.1...v3.6.2)
|
7
|
+
### Changed
|
50
8
|
|
51
|
-
|
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)
|
52
13
|
|
53
|
-
|
14
|
+
[Compare v3.5.0...v4.0.0.alpha1](https://github.com/rom-rb/rom-sql/compare/v3.5.0...v4.0.0.alpha1)
|
54
15
|
|
55
|
-
|
56
|
-
|
57
|
-
[Compare v3.6.0...v3.6.1](https://github.com/rom-rb/rom-sql/compare/v3.6.0...v3.6.1)
|
16
|
+
## 3.5.0 2021-03-26
|
58
17
|
|
59
|
-
## 3.6.0 2022-11-11
|
60
18
|
|
61
19
|
### Added
|
62
20
|
|
63
|
-
-
|
64
|
-
|
65
|
-
### Changed
|
66
|
-
|
67
|
-
- Upgraded to the latest versions of dry-rb dependencies, compatible with rom 5.3 (@flash-gordon)
|
68
|
-
|
69
|
-
[Compare v3.5.0...v3.6.0](https://github.com/rom-rb/rom-sql/compare/v3.5.0...v3.6.0)
|
70
|
-
|
71
|
-
## 3.5.0 2021-03-26
|
72
|
-
|
21
|
+
- Support for using partial indixes in PG upsert commands (issue #394 fixed via #395) (@smaximov)
|
73
22
|
|
74
23
|
### Fixed
|
75
24
|
|
76
|
-
-
|
25
|
+
- Restore the fix for #390 that was lost by an accident in 3.3.3 and 3.4.0 (@solnic)
|
77
26
|
|
78
|
-
### Added
|
79
|
-
|
80
|
-
- Support for using partial indixes in PG upsert commands (issue #394 fixed via #395) (@smaximov)
|
81
27
|
|
82
28
|
[Compare v3.4.0...v3.5.0](https://github.com/rom-rb/rom-sql/compare/v3.4.0...v3.5.0)
|
83
29
|
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
[][actions]
|
11
11
|
[][codacy]
|
12
12
|
[][codacy]
|
13
|
-
[][inchpages]
|
14
14
|
|
15
15
|
## Links
|
16
16
|
|
@@ -21,7 +21,8 @@
|
|
21
21
|
|
22
22
|
This library officially supports the following Ruby versions:
|
23
23
|
|
24
|
-
* MRI >= `
|
24
|
+
* MRI >= `2.5`
|
25
|
+
* jruby >= `9.2`
|
25
26
|
|
26
27
|
## License
|
27
28
|
|
@@ -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,20 +27,19 @@ 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
|
42
|
-
#
|
43
|
-
# rubocop:disable Metrics/AbcSize
|
44
43
|
def self.restriction_methods(schema)
|
45
44
|
mod = Module.new
|
46
45
|
|
@@ -74,14 +73,13 @@ module ROM
|
|
74
73
|
[methods, mod]
|
75
74
|
end
|
76
75
|
end
|
77
|
-
# rubocop:enable Metrics/AbcSize
|
78
76
|
end
|
79
77
|
end
|
80
78
|
end
|
81
79
|
end
|
82
80
|
|
83
81
|
ROM.plugins do
|
84
|
-
adapter
|
82
|
+
adapter(:sql) do
|
85
83
|
register :auto_restrictions, ROM::Plugins::Relation::SQL::AutoRestrictions, type: :relation
|
86
84
|
end
|
87
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,24 +28,14 @@ module ROM
|
|
26
28
|
#
|
27
29
|
# @api public
|
28
30
|
module Instrumentation
|
29
|
-
extend
|
30
|
-
|
31
|
-
subscribe('configuration.relations.registry.created') do |event|
|
32
|
-
registry = event[:registry]
|
31
|
+
extend Dry::Effects.Reader(:registry)
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
}.to_h
|
37
|
-
db_notifications = relations.values.map { |r|
|
38
|
-
[r.dataset.db, r.notifications]
|
39
|
-
}.uniq.to_h
|
33
|
+
def self.apply(target, notifications:, **)
|
34
|
+
db = registry.gateways[target.config.component.gateway].connection
|
40
35
|
|
41
|
-
|
42
|
-
next if db.respond_to?(:rom_instrumentation?)
|
36
|
+
return if db.respond_to?(:rom_instrumentation?)
|
43
37
|
|
44
|
-
|
45
|
-
db.extend(instrumenter)
|
46
|
-
end
|
38
|
+
db.extend(Instrumenter.new(db.database_type, notifications))
|
47
39
|
end
|
48
40
|
|
49
41
|
# This stateful module is used to extend database connection objects
|
@@ -63,7 +55,6 @@ module ROM
|
|
63
55
|
# @api private
|
64
56
|
def initialize(name, notifications)
|
65
57
|
super()
|
66
|
-
|
67
58
|
@name = name
|
68
59
|
@notifications = notifications
|
69
60
|
define_log_connection_yield
|
@@ -100,7 +91,7 @@ module ROM
|
|
100
91
|
end
|
101
92
|
|
102
93
|
ROM.plugins do
|
103
|
-
adapter
|
94
|
+
adapter(:sql) do
|
104
95
|
register :instrumentation, ROM::Plugins::Relation::SQL::Instrumentation, type: :relation
|
105
96
|
end
|
106
97
|
end
|
@@ -26,17 +26,17 @@ module ROM
|
|
26
26
|
#
|
27
27
|
# @api public
|
28
28
|
def explain(format: :text, **options)
|
29
|
-
bool_options = options.map { "#{
|
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,48 +13,32 @@ 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
|
-
# posts.full_text_search([:title, :content], 'apples', language: 'english')
|
17
16
|
# # => Relation which match the 'apples' phrase
|
17
|
+
# posts.full_text_search([:title, :content], 'apples', language: 'english')
|
18
18
|
#
|
19
|
-
# @option :headline [String]
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
# The language to use for the search (default: 'simple')
|
25
|
-
#
|
26
|
-
# @option :plain [Boolean]
|
27
|
-
# Whether a plain search should be used (default: false).
|
28
|
-
# In this case, terms should be a single string, and it will do a search
|
29
|
-
# where cols contains all of the words in terms.
|
19
|
+
# @option :headline [String] Append a expression to the selected columns aliased to headline that contains
|
20
|
+
# an extract of the matched text.
|
21
|
+
# @option :language [String] The language to use for the search (default: 'simple')
|
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.
|
30
24
|
# This ignores search operators in terms.
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
# @option :
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
# Can be set to :plain or :phrase to specify the function to use
|
41
|
-
# to convert the terms to a ts_query.
|
42
|
-
#
|
43
|
-
# @option :tsquery [Boolean]
|
44
|
-
# Specifies the terms argument is already a valid SQL expression returning a tsquery,
|
45
|
-
# and can be used directly in the query.
|
46
|
-
#
|
47
|
-
# @option :tsvector [Boolean]
|
48
|
-
# Specifies the cols argument is already a valid SQL expression returning a tsvector,
|
49
|
-
# and can be used directly in the query.
|
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.
|
27
|
+
# @option :rank [Boolean] Set to true to order by the rank, so that closer matches are returned first.
|
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.
|
50
34
|
#
|
51
35
|
# @return [Relation]
|
52
36
|
#
|
53
37
|
# @see https://www.postgresql.org/docs/current/textsearch.html PostgreSQL docs
|
54
38
|
#
|
55
39
|
# @api public
|
56
|
-
def full_text_search(
|
57
|
-
new dataset.__send__(__method__,
|
40
|
+
def full_text_search(*args, &block)
|
41
|
+
new dataset.__send__(__method__, *args, &block)
|
58
42
|
end
|
59
43
|
end
|
60
44
|
end
|
@@ -64,9 +48,8 @@ module ROM
|
|
64
48
|
end
|
65
49
|
|
66
50
|
ROM.plugins do
|
67
|
-
adapter
|
68
|
-
register :pg_full_text_search,
|
69
|
-
|
70
|
-
type: :relation
|
51
|
+
adapter(:sql) do
|
52
|
+
register :pg_full_text_search, ROM::Plugins::Relation::SQL::Postgres::FullTextSearch,
|
53
|
+
type: :relation
|
71
54
|
end
|
72
55
|
end
|
@@ -9,30 +9,33 @@ 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
|
-
require
|
24
|
+
require "sequel_pg"
|
25
25
|
rescue LoadError
|
26
|
-
raise StreamingNotSupportedError,
|
26
|
+
raise StreamingNotSupportedError, "add sequel_pg to Gemfile to use pg_streaming"
|
27
27
|
end
|
28
28
|
|
29
29
|
unless Sequel::Postgres.supports_streaming?
|
30
|
-
raise StreamingNotSupportedError,
|
30
|
+
raise StreamingNotSupportedError, "postgres version does not support streaming"
|
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,13 +49,13 @@ 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
|
-
raise StreamingNotSupportedError,
|
58
|
+
raise StreamingNotSupportedError, "not supported on jruby"
|
56
59
|
end
|
57
60
|
else
|
58
61
|
# Allows you to stream returned rows one at a time, instead of
|
@@ -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
|
#
|
@@ -80,7 +83,7 @@ module ROM
|
|
80
83
|
|
81
84
|
module Combined
|
82
85
|
def stream_each
|
83
|
-
raise StreamingNotSupportedError,
|
86
|
+
raise StreamingNotSupportedError, "not supported on combined relations"
|
84
87
|
end
|
85
88
|
end
|
86
89
|
|
@@ -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
|
@@ -12,8 +12,6 @@ module ROM
|
|
12
12
|
include Associations::SelfRef
|
13
13
|
|
14
14
|
# @api public
|
15
|
-
#
|
16
|
-
# rubocop:disable Metrics/AbcSize
|
17
15
|
def call(target: self.target)
|
18
16
|
left = join_assoc.(target: target)
|
19
17
|
|
@@ -36,7 +34,6 @@ module ROM
|
|
36
34
|
schema.(relation)
|
37
35
|
end
|
38
36
|
end
|
39
|
-
# rubocop:enable Metrics/AbcSize
|
40
37
|
|
41
38
|
# @api public
|
42
39
|
def join(type, source = self.source, target = self.target)
|
@@ -53,7 +50,7 @@ module ROM
|
|
53
50
|
|
54
51
|
# @api public
|
55
52
|
def join_keys
|
56
|
-
{
|
53
|
+
{source_attr => target_attr}
|
57
54
|
end
|
58
55
|
|
59
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
|
@@ -12,8 +12,6 @@ module ROM
|
|
12
12
|
include Associations::SelfRef
|
13
13
|
|
14
14
|
# @api public
|
15
|
-
#
|
16
|
-
# rubocop:disable Metrics/AbcSize
|
17
15
|
def call(target: self.target, preload: false)
|
18
16
|
if preload
|
19
17
|
schema = target.schema.qualified
|
@@ -43,7 +41,6 @@ module ROM
|
|
43
41
|
schema.(relation)
|
44
42
|
end
|
45
43
|
end
|
46
|
-
# rubocop:enable Metrics/AbcSize
|
47
44
|
|
48
45
|
# @api public
|
49
46
|
def join(type, source = self.source, target = self.target)
|
@@ -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"
|