simple-sql 0.5.30 → 0.5.31
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/config/database.yml +2 -1
- data/lib/simple/sql/connection/scope.rb +1 -0
- data/lib/simple/sql/connection/scope/order.rb +16 -2
- data/lib/simple/sql/connection/scope/pagination.rb +4 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7490b50fc301d6e1a8c424e46a21f4a5cb97767ca2a99c7bdeed94b7c499a0d6
|
4
|
+
data.tar.gz: 3e1ec456a008d2abee6260b84beb1c17ca4b5934c1b934f00298ad6263b0f849
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c4ff2ac25d314393ff79a5f8ff3171508b05f30a99f37d1681a5b4af0fe3f07f247623321e235fc70de4d384d8e994935fc69eaf592c41b8459ceb0c875adf7
|
7
|
+
data.tar.gz: e59f00c7d6a3f00d1f4c2ca101985e8a01b453cc80b774f5f95b867eebea3e1dddf70a341fd4bf8904e497b19738d58e2a66d20a08372a138bf2302d918af1cb
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.31
|
data/config/database.yml
CHANGED
@@ -84,6 +84,7 @@ class Simple::SQL::Connection::Scope
|
|
84
84
|
dupe.instance_variable_set :@page, @page
|
85
85
|
dupe.instance_variable_set :@order_by_fragment, @order_by_fragment
|
86
86
|
dupe.instance_variable_set :@limit, @limit
|
87
|
+
dupe.instance_variable_set :@offset, @offset
|
87
88
|
dupe
|
88
89
|
end
|
89
90
|
|
@@ -3,8 +3,16 @@ class Simple::SQL::Connection::Scope
|
|
3
3
|
duplicate.send(:order_by!, sql_fragment)
|
4
4
|
end
|
5
5
|
|
6
|
-
def limit(
|
7
|
-
|
6
|
+
def limit(limit)
|
7
|
+
raise ArgumentError, "limit must be >= 0" unless limit >= 0
|
8
|
+
|
9
|
+
duplicate.send(:limit!, limit)
|
10
|
+
end
|
11
|
+
|
12
|
+
def offset(offset)
|
13
|
+
raise ArgumentError, "offset must be >= 0" unless offset >= 0
|
14
|
+
|
15
|
+
duplicate.send(:offset!, offset)
|
8
16
|
end
|
9
17
|
|
10
18
|
private
|
@@ -21,10 +29,16 @@ class Simple::SQL::Connection::Scope
|
|
21
29
|
self
|
22
30
|
end
|
23
31
|
|
32
|
+
def offset!(offset)
|
33
|
+
@offset = offset
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
24
37
|
# called from to_sql
|
25
38
|
def apply_order_and_limit(sql)
|
26
39
|
sql = "#{sql} ORDER BY #{@order_by_fragment}" if @order_by_fragment
|
27
40
|
sql = "#{sql} LIMIT #{@limit}" if @limit
|
41
|
+
sql = "#{sql} OFFSET #{@offset}" if @offset
|
28
42
|
|
29
43
|
sql
|
30
44
|
end
|
@@ -3,6 +3,9 @@
|
|
3
3
|
class Simple::SQL::Connection::Scope
|
4
4
|
# Set pagination
|
5
5
|
def paginate(per:, page:)
|
6
|
+
raise ArgumentError, "per must be > 0" unless per > 0
|
7
|
+
raise ArgumentError, "page must be > 0" unless page > 0
|
8
|
+
|
6
9
|
duplicate.send(:paginate!, per: per, page: page)
|
7
10
|
end
|
8
11
|
|
@@ -23,8 +26,7 @@ class Simple::SQL::Connection::Scope
|
|
23
26
|
def apply_pagination(sql, pagination:)
|
24
27
|
return sql unless pagination == :auto && @per && @page
|
25
28
|
|
26
|
-
raise ArgumentError, "
|
27
|
-
raise ArgumentError, "page must be > 0" unless @page > 0
|
29
|
+
raise ArgumentError, "You cannot mix 'paginate' and 'offset'/'limit'" if @offset || @limit
|
28
30
|
|
29
31
|
"#{sql} LIMIT #{@per} OFFSET #{(@page - 1) * @per}"
|
30
32
|
end
|
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.5.
|
4
|
+
version: 0.5.31
|
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: 2020-04
|
12
|
+
date: 2020-09-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pg_array_parser
|