postgres_with 0.0.2 → 1.0.0
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/lib/postgres_with.rb +1 -0
- data/lib/postgres_with/active_record/relation/query_methods.rb +21 -1
- data/lib/postgres_with/arel.rb +3 -0
- data/lib/postgres_with/arel/nodes.rb +1 -0
- data/lib/postgres_with/arel/nodes/as_materialized.rb +5 -0
- data/lib/postgres_with/arel/visitors.rb +3 -0
- data/lib/postgres_with/arel/visitors/depth_first.rb +7 -0
- data/lib/postgres_with/arel/visitors/dot.rb +7 -0
- data/lib/postgres_with/arel/visitors/to_sql.rb +11 -0
- data/lib/postgres_with/version.rb +1 -1
- data/postgres_with.gemspec +1 -1
- metadata +17 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbff15d0145d5eee85ae2e75eeaf6783ecd1cf8db0899ef905144feeca5026de
|
4
|
+
data.tar.gz: 8afc9a9de9643ee41d720d8e79a2079d5fc1eb0e744e85a7b3225ce8411396c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0be688754367f5514aac6868f99c73403b38900945bc553cf9cc436168c3a44739d5c28393d67ccb83cd58fb9615cb3810a77caf54c9e6695691342c762b7fe
|
7
|
+
data.tar.gz: fb37ba76cadb929b1fe6b4eb0bdcfb101b43c5d505f3aaa22ccdf855c49722fc0f1889543d6919b0b866b4847488b5721dceddf3dead54be126b22af5b311ca6
|
data/lib/postgres_with.rb
CHANGED
@@ -7,6 +7,21 @@ module ActiveRecord
|
|
7
7
|
@scope = scope
|
8
8
|
end
|
9
9
|
|
10
|
+
def materialized(*args)
|
11
|
+
materialized_args = args.flat_map do |arg|
|
12
|
+
case arg
|
13
|
+
when Hash
|
14
|
+
name = arg.keys.first
|
15
|
+
new_name = "_materialized_#{name}"
|
16
|
+
{ new_name => arg[name] }
|
17
|
+
else
|
18
|
+
arg
|
19
|
+
end
|
20
|
+
end
|
21
|
+
@scope.with_values += materialized_args
|
22
|
+
@scope
|
23
|
+
end
|
24
|
+
|
10
25
|
# Returns a new relation expressing WITH RECURSIVE
|
11
26
|
def recursive(*args)
|
12
27
|
@scope.with_values += args
|
@@ -75,7 +90,12 @@ module ActiveRecord
|
|
75
90
|
when ActiveRecord::Relation, Arel::SelectManager
|
76
91
|
select = Arel::Nodes::SqlLiteral.new "(#{expression.to_sql})"
|
77
92
|
end
|
78
|
-
|
93
|
+
if name.to_s.start_with?('_materialized_')
|
94
|
+
name = name.gsub('_materialized_', '')
|
95
|
+
Arel::Nodes::AsMaterialized.new Arel::Nodes::SqlLiteral.new("\"#{name}\""), select
|
96
|
+
else
|
97
|
+
Arel::Nodes::As.new Arel::Nodes::SqlLiteral.new("\"#{name}\""), select
|
98
|
+
end
|
79
99
|
end
|
80
100
|
when Arel::Nodes::As
|
81
101
|
with_value
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'postgres_with/arel/nodes/as_materialized'
|
data/postgres_with.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = PostgresWith::VERSION
|
17
17
|
|
18
|
-
gem.add_dependency 'activerecord', '
|
18
|
+
gem.add_dependency 'activerecord', '~> 5.0'
|
19
19
|
gem.add_dependency 'arel', '>= 4.0'
|
20
20
|
|
21
21
|
gem.add_development_dependency 'pg', '>= 0.13'
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postgres_with
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derrick Neier
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '5.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: arel
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,13 +70,20 @@ files:
|
|
70
70
|
- lib/postgres_with/active_record/relation.rb
|
71
71
|
- lib/postgres_with/active_record/relation/merger.rb
|
72
72
|
- lib/postgres_with/active_record/relation/query_methods.rb
|
73
|
+
- lib/postgres_with/arel.rb
|
74
|
+
- lib/postgres_with/arel/nodes.rb
|
75
|
+
- lib/postgres_with/arel/nodes/as_materialized.rb
|
76
|
+
- lib/postgres_with/arel/visitors.rb
|
77
|
+
- lib/postgres_with/arel/visitors/depth_first.rb
|
78
|
+
- lib/postgres_with/arel/visitors/dot.rb
|
79
|
+
- lib/postgres_with/arel/visitors/to_sql.rb
|
73
80
|
- lib/postgres_with/version.rb
|
74
81
|
- postgres_with.gemspec
|
75
82
|
homepage: https://github.com/dneier/postgres_with
|
76
83
|
licenses:
|
77
84
|
- MIT
|
78
85
|
metadata: {}
|
79
|
-
post_install_message:
|
86
|
+
post_install_message:
|
80
87
|
rdoc_options: []
|
81
88
|
require_paths:
|
82
89
|
- lib
|
@@ -91,9 +98,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
98
|
- !ruby/object:Gem::Version
|
92
99
|
version: '0'
|
93
100
|
requirements: []
|
94
|
-
|
95
|
-
|
96
|
-
signing_key:
|
101
|
+
rubygems_version: 3.0.3
|
102
|
+
signing_key:
|
97
103
|
specification_version: 4
|
98
104
|
summary: Extends ActiveRecord to handle PostgreSQL CTEs
|
99
105
|
test_files: []
|