simple-sql 0.4.35 → 0.4.36
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/simple/sql/result.rb +21 -14
- data/lib/simple/sql/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8dc1ec7e4bb737434a4bcd95b612b9e100386bbc2896d67e09b68b6c7946172
|
4
|
+
data.tar.gz: a3cfb7860e3c085514b4e294b7b99773cd2365292ca68e96bc81ede0c10fc8c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3de0a9214dce2e7fc91de037fb58dc4beef47ee066acfdf366e2b6100f1a4592436078d13c34d34cbc102be25c5281b0177aace3b5c36be30dc0ed735e3438f
|
7
|
+
data.tar.gz: fdb5081fae742c348157af72bcb119cc61ad88831f313fa640a64020ff6254c65ba1e662325bd684a92dda27c2d0f3bb40a7c0ef4dd8af82b3b7cdee0fdc59b9
|
data/lib/simple/sql/result.rb
CHANGED
@@ -34,15 +34,17 @@ class ::Simple::SQL::Result < Array
|
|
34
34
|
#
|
35
35
|
# This is filled in when resolving a paginated scope.
|
36
36
|
def total_count_estimate
|
37
|
-
@total_count_estimate
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
37
|
+
return @total_count_estimate if instance_variable_defined?(:@total_count_estimate)
|
38
|
+
|
39
|
+
@total_count_estimate = if @pagination_scope
|
40
|
+
catch(:total_count_estimate) do
|
41
|
+
sql = @pagination_scope.order_by(nil).to_sql(pagination: false)
|
42
|
+
::Simple::SQL.each("EXPLAIN #{sql}", *@pagination_scope.args) do |line|
|
43
|
+
next unless line =~ /\brows=(\d+)/
|
44
|
+
throw :total_count_estimate, Integer($1)
|
45
|
+
end
|
46
|
+
-1
|
44
47
|
end
|
45
|
-
-1
|
46
48
|
end
|
47
49
|
end
|
48
50
|
|
@@ -50,17 +52,20 @@ class ::Simple::SQL::Result < Array
|
|
50
52
|
#
|
51
53
|
# This is filled in when resolving a paginated scope.
|
52
54
|
def total_pages_estimate
|
53
|
-
@total_pages_estimate
|
55
|
+
return @total_pages_estimate if instance_variable_defined?(:@total_pages_estimate)
|
56
|
+
|
57
|
+
@total_pages_estimate = (total_count_estimate * 1.0 / @pagination_scope.per).ceil if @pagination_scope
|
54
58
|
end
|
55
59
|
|
56
60
|
# returns the total_count of search hits
|
57
61
|
#
|
58
62
|
# This is filled in when resolving a paginated scope.
|
59
63
|
def total_count
|
60
|
-
@total_count
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
+
return @total_count if instance_variable_defined?(:@total_count)
|
65
|
+
|
66
|
+
@total_count = if @pagination_scope
|
67
|
+
sql = @pagination_scope.order_by(nil).to_sql(pagination: false)
|
68
|
+
::Simple::SQL.ask("SELECT COUNT(*) FROM (#{sql}) _total_count", *@pagination_scope.args)
|
64
69
|
end
|
65
70
|
end
|
66
71
|
|
@@ -69,7 +74,9 @@ class ::Simple::SQL::Result < Array
|
|
69
74
|
# This is filled in when resolving a paginated scope. It takes
|
70
75
|
# into account the scope's "per" option.
|
71
76
|
def total_pages
|
72
|
-
@total_pages
|
77
|
+
return @total_pages if instance_variable_defined?(:@total_pages)
|
78
|
+
|
79
|
+
@total_pages = (total_count * 1.0 / @pagination_scope.per).ceil if @pagination_scope
|
73
80
|
end
|
74
81
|
|
75
82
|
# returns the current page number in a paginated search
|
data/lib/simple/sql/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-sql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.36
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- radiospiel
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-03-
|
12
|
+
date: 2019-03-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pg_array_parser
|
@@ -267,8 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
267
267
|
- !ruby/object:Gem::Version
|
268
268
|
version: '0'
|
269
269
|
requirements: []
|
270
|
-
|
271
|
-
rubygems_version: 2.7.6
|
270
|
+
rubygems_version: 3.0.2
|
272
271
|
signing_key:
|
273
272
|
specification_version: 4
|
274
273
|
summary: SQL with a simple interface
|