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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d632ffb65879e2262ae18f279584769d3c139594297d83821059bcd5e6d6763
4
- data.tar.gz: 34b6bcb70c40ff3393020b1cb541b756e74dfd35415731a42eae868ce41cc6a9
3
+ metadata.gz: fbff15d0145d5eee85ae2e75eeaf6783ecd1cf8db0899ef905144feeca5026de
4
+ data.tar.gz: 8afc9a9de9643ee41d720d8e79a2079d5fc1eb0e744e85a7b3225ce8411396c0
5
5
  SHA512:
6
- metadata.gz: ea222c7477b4ea330d0cf3d8b353df19215486ad63830e675772a0ff967dd8e2869cf5abcc0d853475d1e40997d887b1562a8ca42d643aba477e917fc39cfd1e
7
- data.tar.gz: b21db070bbb98a266a6c9dcebe0131f9b044794522354bff8642a39a583f4c9c4a77a498bf6d4ebef88df9cae8c98b1a1d122f160c687e9942e44c92b42d106e
6
+ metadata.gz: f0be688754367f5514aac6868f99c73403b38900945bc553cf9cc436168c3a44739d5c28393d67ccb83cd58fb9615cb3810a77caf54c9e6695691342c762b7fe
7
+ data.tar.gz: fb37ba76cadb929b1fe6b4eb0bdcfb101b43c5d505f3aaa22ccdf855c49722fc0f1889543d6919b0b866b4847488b5721dceddf3dead54be126b22af5b311ca6
@@ -1,2 +1,3 @@
1
1
  require 'postgres_with/version'
2
2
  require 'postgres_with/active_record'
3
+ require 'postgres_with/arel'
@@ -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
- Arel::Nodes::As.new Arel::Nodes::SqlLiteral.new("\"#{name}\""), select
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,3 @@
1
+ require 'arel'
2
+ require 'postgres_with/arel/nodes'
3
+ require 'postgres_with/arel/visitors'
@@ -0,0 +1 @@
1
+ require 'postgres_with/arel/nodes/as_materialized'
@@ -0,0 +1,5 @@
1
+ module Arel # :nodoc: all
2
+ module Nodes
3
+ class AsMaterialized < Arel::Nodes::Binary; end
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ require 'postgres_with/arel/visitors/depth_first'
2
+ require 'postgres_with/arel/visitors/dot'
3
+ require 'postgres_with/arel/visitors/to_sql'
@@ -0,0 +1,7 @@
1
+ module Arel
2
+ module Visitors
3
+ class DepthFirst < Arel::Visitors::Visitor
4
+ alias :visit_Arel_Nodes_AsMaterialized :binary
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Arel
2
+ module Visitors
3
+ class Dot < Arel::Visitors::Visitor
4
+ alias :visit_Arel_Nodes_AsMaterialized :binary
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module Arel
2
+ module Visitors
3
+ class ToSql < Arel::Visitors::Reduce
4
+ def visit_Arel_Nodes_AsMaterialized o, collector
5
+ collector = visit o.left, collector
6
+ collector << " AS MATERIALIZED "
7
+ visit o.right, collector
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module PostgresWith
2
- VERSION = '0.0.2'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -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', '>= 4.0'
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.2
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: 2018-10-29 00:00:00.000000000 Z
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: '4.0'
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: '4.0'
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
- rubyforge_project:
95
- rubygems_version: 2.7.6
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: []