quick_count 0.1.0 → 0.1.1

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
- SHA1:
3
- metadata.gz: f66820d33c95c3c038829d7fc456850301d5514f
4
- data.tar.gz: 4117c911a066b29f324bc7dc8ad4e093a70ada3c
2
+ SHA256:
3
+ metadata.gz: b96ac3ad5c0ecf19aaa83bdda2805c30221b26ae36d19a614aaa637cf2a52dbc
4
+ data.tar.gz: f42909f6a0a932e98329d4e4676cdc085db7aceac847fcd035746cbfd652439b
5
5
  SHA512:
6
- metadata.gz: 8f1b35c2ff31bc1c80ae3a31472b08b12047a9951253a3030dbeac450d3e633500e3a56bd09d9f63195ffcdb474c451b5209df80975d03a70feee6d3ae24c4ef
7
- data.tar.gz: 23b26e62eaf837bc6f999531f0d123c1c1501a7cea95993363ff1939240ecc9186572943bcd2a633065d7956cc584919c09c5142b1765d1b7588b790ac1e594a
6
+ metadata.gz: 30d43a8f2dca676c28c68b8f94fb699f09c9af067f27f8cfe7a9332c6ed322e10ac745130e9e0f21b74157fb9dcdee4b696115b1483f1054eb4e60d992bcd42d
7
+ data.tar.gz: 0aae2ca316cb80fe2bab834bc2ed95769897db442ab186931d17fa1de2a01d923834eca1beb37518d913409a679177adf949f6a95f2b6cae4d3465046f981cc9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # QuickCount
2
2
 
3
+ ## 0.1.1 _(November 27th 2018)_
4
+ - Fix for table names with special characters
5
+
3
6
  ## 0.1.0 _(June 22nd 2018)_
4
7
  - Unlock `pg` gem (allow for > 0.2.x)
5
8
  - Cleaned up gemspec and what it bundles in the gem
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
- [![Version ](https://img.shields.io/gem/v/quick_count.svg?maxAge=2592000)](https://rubygems.org/gems/quick_count)
1
+ [![Version ](https://img.shields.io/gem/v/quick_count.svg)](https://rubygems.org/gems/quick_count)
2
2
  [![Build Status ](https://travis-ci.org/TwilightCoders/quick_count.svg)](https://travis-ci.org/TwilightCoders/quick_count)
3
3
  [![Code Climate ](https://api.codeclimate.com/v1/badges/43ba3e038a91b44fba2c/maintainability)](https://codeclimate.com/github/TwilightCoders/quick_count/maintainability)
4
- [![Test Coverage](https://codeclimate.com/github/TwilightCoders/quick_count/badges/coverage.svg)](https://codeclimate.com/github/TwilightCoders/quick_count/coverage)
5
- [![Dependencies ](https://badges.depfu.com/badges/564300bfe49871ba217a3f78de3ecc0c/overview.svg)](https://depfu.com/github/TwilightCoders/quick_count)
4
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/43ba3e038a91b44fba2c/test_coverage)](https://codeclimate.com/github/TwilightCoders/quick_count/test_coverage)
6
5
 
7
6
  # QuickCount
8
7
 
@@ -44,6 +43,10 @@ Or install it yourself as:
44
43
 
45
44
  $ gem install quick_count
46
45
 
46
+ To finish the install, in rails console:
47
+
48
+ $ QuickCount.install # Install with default (500000) threshold
49
+
47
50
  ## Usage
48
51
 
49
52
  ```ruby
@@ -0,0 +1,15 @@
1
+ require 'active_support/concern'
2
+
3
+ module CountEstimate
4
+ module ActiveRecord
5
+ module Relation
6
+
7
+ def count_estimate
8
+ my_statement = ::ActiveRecord::Base.connection.quote(to_sql)
9
+ result = ::ActiveRecord::Base.connection.execute("SELECT count_estimate(#{my_statement})")
10
+ result[0]["count_estimate"].to_i
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ require 'active_support/concern'
2
+
3
+ module QuickCount
4
+ module ActiveRecord
5
+ module Base
6
+ extend ActiveSupport::Concern
7
+
8
+ module ClassMethods
9
+
10
+ def quick_count(threshold: nil)
11
+ threshold = threshold ? ", #{threshold}" : nil
12
+ result = ::ActiveRecord::Base.connection.execute("SELECT quick_count('#{table_name}'#{threshold})")
13
+ result[0]["quick_count"].to_i
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module QuickCount
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/quick_count.rb CHANGED
@@ -35,7 +35,7 @@ private
35
35
  EXECUTE 'SELECT
36
36
  CASE
37
37
  WHEN SUM(estimate)::integer < '|| threshold ||' THEN
38
- (SELECT COUNT(*) FROM '|| table_name ||')
38
+ (SELECT COUNT(*) FROM "'|| table_name ||'")
39
39
  ELSE
40
40
  SUM(estimate)::integer
41
41
  END AS count
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quick_count
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dale Stevens
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-22 00:00:00.000000000 Z
11
+ date: 2018-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -132,8 +132,10 @@ files:
132
132
  - LICENSE
133
133
  - README.md
134
134
  - lib/count_estimate/active_record.rb
135
+ - lib/count_estimate/active_record/relation.rb
135
136
  - lib/quick_count.rb
136
137
  - lib/quick_count/active_record.rb
138
+ - lib/quick_count/active_record/base.rb
137
139
  - lib/quick_count/railtie.rb
138
140
  - lib/quick_count/version.rb
139
141
  homepage: https://github.com/TwilightCoders/quick_count
@@ -158,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
160
  version: '0'
159
161
  requirements: []
160
162
  rubyforge_project:
161
- rubygems_version: 2.6.14.1
163
+ rubygems_version: 2.7.7
162
164
  signing_key:
163
165
  specification_version: 4
164
166
  summary: Quickly get an accurate count estimation for large tables.