simple-sql 0.4.36 → 0.4.37
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/simple/sql/result.rb +23 -16
- data/lib/simple/sql/version.rb +1 -1
- data/lib/simple/sql.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb4ff06bf7f2aeba2ded053177b20b1db9630ee1f2534672e9bb5616a1d6ad93
|
4
|
+
data.tar.gz: 9ec867c270c8e4b263e61b0e222748d663021a40da6e650f2b072165e66eef21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ecf49aa237ba87bb1cab4aa026eb3ce7dbaf123e0b161a0d9fd997e47aaf46bdba454a1f85f864ac8e85bd733ffd805fdc97df0d6981764ddb32642b5e24829
|
7
|
+
data.tar.gz: 8d54d93bcbfb5c06ce8be25264bf3b1f10cf0eb0039b60ea05350d0b2da23d1888d561ead99eddd984400b0cb3c6d48ada81f4bcc81a9ba6859c4a482383c904
|
data/lib/simple/sql/result.rb
CHANGED
@@ -35,17 +35,8 @@ class ::Simple::SQL::Result < Array
|
|
35
35
|
# This is filled in when resolving a paginated scope.
|
36
36
|
def total_count_estimate
|
37
37
|
return @total_count_estimate if instance_variable_defined?(:@total_count_estimate)
|
38
|
-
|
39
|
-
@total_count_estimate =
|
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
|
47
|
-
end
|
48
|
-
end
|
38
|
+
|
39
|
+
@total_count_estimate = _total_count_estimate
|
49
40
|
end
|
50
41
|
|
51
42
|
# returns the estimated total number of pages of search hits
|
@@ -53,7 +44,7 @@ class ::Simple::SQL::Result < Array
|
|
53
44
|
# This is filled in when resolving a paginated scope.
|
54
45
|
def total_pages_estimate
|
55
46
|
return @total_pages_estimate if instance_variable_defined?(:@total_pages_estimate)
|
56
|
-
|
47
|
+
|
57
48
|
@total_pages_estimate = (total_count_estimate * 1.0 / @pagination_scope.per).ceil if @pagination_scope
|
58
49
|
end
|
59
50
|
|
@@ -63,10 +54,7 @@ class ::Simple::SQL::Result < Array
|
|
63
54
|
def total_count
|
64
55
|
return @total_count if instance_variable_defined?(:@total_count)
|
65
56
|
|
66
|
-
@total_count =
|
67
|
-
sql = @pagination_scope.order_by(nil).to_sql(pagination: false)
|
68
|
-
::Simple::SQL.ask("SELECT COUNT(*) FROM (#{sql}) _total_count", *@pagination_scope.args)
|
69
|
-
end
|
57
|
+
@total_count = _total_count
|
70
58
|
end
|
71
59
|
|
72
60
|
# returns the total number of pages of search hits
|
@@ -104,4 +92,23 @@ class ::Simple::SQL::Result < Array
|
|
104
92
|
@pagination_scope = scope
|
105
93
|
end
|
106
94
|
end
|
95
|
+
|
96
|
+
def _total_count_estimate
|
97
|
+
return unless @pagination_scope
|
98
|
+
|
99
|
+
sql = @pagination_scope.order_by(nil).to_sql(pagination: false)
|
100
|
+
::Simple::SQL.each("EXPLAIN #{sql}", *@pagination_scope.args) do |line|
|
101
|
+
next unless line =~ /\brows=(\d+)/
|
102
|
+
return Integer($1)
|
103
|
+
end
|
104
|
+
|
105
|
+
-1
|
106
|
+
end
|
107
|
+
|
108
|
+
def _total_count
|
109
|
+
return unless @pagination_scope
|
110
|
+
|
111
|
+
sql = @pagination_scope.order_by(nil).to_sql(pagination: false)
|
112
|
+
::Simple::SQL.ask("SELECT COUNT(*) FROM (#{sql}) _total_count", *@pagination_scope.args)
|
113
|
+
end
|
107
114
|
end
|
data/lib/simple/sql/version.rb
CHANGED
data/lib/simple/sql.rb
CHANGED
@@ -35,6 +35,11 @@ module Simple
|
|
35
35
|
Connection.create(database_url)
|
36
36
|
end
|
37
37
|
|
38
|
+
# deprecated
|
39
|
+
def configuration
|
40
|
+
Config.parse_url(Config.determine_url)
|
41
|
+
end
|
42
|
+
|
38
43
|
# -- default connection ---------------------------------------------------
|
39
44
|
|
40
45
|
DEFAULT_CONNECTION_KEY = :"Simple::SQL.default_connection"
|