activerecord_pg_stuff 0.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 98e0fe7a1df9305832a41d308d6aba130aec4fb1
4
- data.tar.gz: 8b5558b5366becdfb1fe1ec0ff77f312ab048e42
3
+ metadata.gz: 0a74e9ffd6c02c6912d7ef455e31425fdfbe19b0
4
+ data.tar.gz: dedb60e87ec990e25177ebb59df69ba36217f8d4
5
5
  SHA512:
6
- metadata.gz: 8e20d0174e3ae5d40106b3453807871e7433c02bfdc92dcf25ccf8bfb80fd9fe5a2300053081eb1951d4013a2d91682e1823c25ff1e0597be37318b9957af228
7
- data.tar.gz: bd22ac3135004e020aeec70bbc4ada73170473dbf790fe6a8d223688d5c36e6f7d9113961871f41ae6dc819eb4fc8c22b9f69e6d20a09747b905c184fb9cd909
6
+ metadata.gz: bac00e46e4bbcfdd35a953b1d0e1c666cc2bb18a832efd7339702e68826a82cd0fca7aa7818633e5148a2631b98f01d1ff1f4bc44fe40d3cc543e05340f345ca
7
+ data.tar.gz: 8c8f62c55499ce6ae9567e0311913444e6cb3c7a7929ff3dabdb64f7d0fd44604dbfe0776b1fe081d3a1552ed8789890bc91c649795ea989469f2b0f8b5f7426
data/.travis.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  rvm:
2
- - 1.9.3
3
- - 2.0.0
2
+ - 2.2.2
4
3
 
5
4
  env:
6
5
  global:
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency "activerecord", "~> 4.0"
21
+ spec.add_runtime_dependency "activerecord", "~> 5.0"
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency "rake"
@@ -8,7 +8,7 @@ module ActiveRecordPgStuff
8
8
  begin
9
9
  sql = sql.gsub(/\n/, ' ').gsub(/ +/, ' ').strip
10
10
  sql = "CREATE TEMPORARY TABLE #{name} ON COMMIT DROP AS #{sql}"
11
- conn.execute sql
11
+ execute sql
12
12
  yield name
13
13
  ensure
14
14
  execute("DROP TABLE IF EXISTS #{name}") rescue nil
@@ -17,7 +17,7 @@ module ActiveRecordPgStuff
17
17
  def result_to_array(result)
18
18
  result.to_hash.map do |h|
19
19
  result.columns.inject([]) do |a, col|
20
- a << result.column_types[col].type_cast(h[col])
20
+ a << result.column_types[col].cast(h[col])
21
21
  end
22
22
  end
23
23
  end
@@ -26,8 +26,7 @@ module ActiveRecordPgStuff
26
26
  module Pivot
27
27
 
28
28
  def pivot(row_id, col_id, val_id)
29
-
30
- types_sql = %{ SELECT column_name, data_type FROM information_schema.columns WHERE table_name = #{connection.quote self.table_name} AND column_name IN (#{connection.quote row_id},#{connection.quote val_id}) }
29
+ types_sql = %{ SELECT column_name, data_type FROM information_schema.columns WHERE table_name = #{connection.quote self.table.name} AND column_name IN (#{connection.quote row_id},#{connection.quote val_id}) }
31
30
  types = connection.select_all types_sql
32
31
  types = types.to_a.map(&:values).inject({}) do |a, v|
33
32
  a[v[0]] = v[1]
@@ -4,13 +4,15 @@ module ActiveRecordPgStuff
4
4
  module TemporaryTable
5
5
 
6
6
  class Decorator
7
- attr_reader :table_name, :arel_table, :quoted_table_name
7
+ attr_reader :table_name, :arel_table, :quoted_table_name, :table_metadata, :predicate_builder
8
8
 
9
9
  def initialize(object, table_name)
10
10
  @table_name = table_name
11
11
  @object = object
12
12
  @arel_table = Arel::Table.new(table_name)
13
13
  @quoted_table_name = @object.connection.quote_table_name(table_name)
14
+ @table_metadata = ActiveRecord::TableMetadata.new(self, @arel_table)
15
+ @predicate_builder = ActiveRecord::PredicateBuilder.new(@table_metadata)
14
16
  end
15
17
 
16
18
  def method_missing(name, *args, &block)
@@ -23,10 +25,10 @@ module ActiveRecordPgStuff
23
25
  end
24
26
 
25
27
  def temporary_table
26
- tname = "temporary_#{self.table_name}_#{self.object_id}"
28
+ tname = "temporary_#{self.table.name}_#{self.object_id}"
27
29
  self.klass.connection.with_temporary_table tname, self.to_sql do |name|
28
30
  dec = Decorator.new self.klass, name
29
- rel = ActiveRecord::Relation.new dec, dec.arel_table
31
+ rel = ActiveRecord::Relation.new dec, table: dec.arel_table
30
32
  rel.readonly!
31
33
  yield rel
32
34
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordPgStuff
2
- VERSION = "0.0.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -9,7 +9,7 @@ describe ActiveRecordPgStuff::Connection::TemporaryTable do
9
9
  rs = conn.with_temporary_table 'sellers_tmp', sql do |name|
10
10
  conn.select_all("SELECT * FROM #{name}").to_a.map(&:values)
11
11
  end
12
- expect(rs).to eq [%w{1 foo}, %w{2 bar}]
12
+ expect(rs).to eq [[1, "foo"], [2, "bar"]]
13
13
  expect {
14
14
  conn.execute 'SELECT * FROM sellers_tmp'
15
15
  }.to raise_error(ActiveRecord::StatementInvalid, /PG::UndefinedTable/)
@@ -22,7 +22,7 @@ describe ActiveRecordPgStuff::Connection::TemporaryTable do
22
22
  conn.select_all("SELECT * FROM #{name_nested}").to_a.map(&:values)
23
23
  end
24
24
  end
25
- expect(rs).to eq [%w{1 foo}]
25
+ expect(rs).to eq [[1, "foo"]]
26
26
  expect {
27
27
  conn.execute 'SELECT * FROM sellers_tmp'
28
28
  }.to raise_error(ActiveRecord::StatementInvalid, /PG::UndefinedTable/)
metadata CHANGED
@@ -1,96 +1,96 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_pg_stuff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Galinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-23 00:00:00.000000000 Z
11
+ date: 2018-10-05 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: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pg
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description: ' Adds support for working with temporary tables and pivot tables (PostgreSQL
84
- only) '
83
+ description: " Adds support for working with temporary tables and pivot tables (PostgreSQL
84
+ only) "
85
85
  email:
86
86
  - dima.exe@gmail.com
87
87
  executables: []
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
- - .gitignore
92
- - .rspec
93
- - .travis.yml
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
94
  - Gemfile
95
95
  - LICENSE.txt
96
96
  - README.md
@@ -115,17 +115,17 @@ require_paths:
115
115
  - lib
116
116
  required_ruby_version: !ruby/object:Gem::Requirement
117
117
  requirements:
118
- - - '>='
118
+ - - ">="
119
119
  - !ruby/object:Gem::Version
120
120
  version: '0'
121
121
  required_rubygems_version: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - '>='
123
+ - - ">="
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  requirements: []
127
127
  rubyforge_project:
128
- rubygems_version: 2.0.2
128
+ rubygems_version: 2.4.5.1
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: Adds support for working with temporary tables and pivot tables (PostgreSQL