simple-sql 0.5.28 → 0.5.33
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- 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
- data/lib/simple/sql/helpers/encoder.rb +19 -3
- data/lib/simple/sql/helpers/immutable.rb +2 -0
- data/lib/simple/sql/monkey_patches.rb +3 -10
- data/lib/simple/sql/version.rb +1 -0
- data/simple-sql.gemspec +2 -2
- data/spec/simple/sql/conversion_spec.rb +10 -7
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 567c2dd86ca2849c533ced2e9d3dcc14705ca71659bbe19e63fc82fe2907e15d
|
4
|
+
data.tar.gz: 1a799e2970974d7acbcc0587a14547674124686f1361ddc0f8049811eb0653e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef6c51b2827d93e11b68c0094052604b55f790e8bca3a5667e6113f6d413b6f0c663b3e3e0f718e46e4ae492972216ae5495f51c03e72fbf8b6b40cae511f266
|
7
|
+
data.tar.gz: 5a51b78d962fac7ba6fe651ed08d34fa9d3854749fb9708855b83c29ee8d1a6cabb2b97d007c658cd447324e45e30123113c9f72b2674cded7144eec289f0e0b
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.33
|
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
|
@@ -8,11 +8,27 @@ module Simple::SQL::Helpers::Encoder
|
|
8
8
|
|
9
9
|
def encode_arg(connection, arg)
|
10
10
|
return arg unless arg.is_a?(Array)
|
11
|
+
return "{}" if arg.empty?
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
encoded_ary = encode_array(connection, arg)
|
14
|
+
"{" + encoded_ary.join(",") + "}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def encode_array(connection, ary)
|
18
|
+
case ary.first
|
19
|
+
when String
|
20
|
+
ary.map do |str|
|
21
|
+
str = connection.escape(str)
|
22
|
+
|
23
|
+
# These fixes have been discovered during tests. see spec/simple/sql/conversion_spec.rb
|
24
|
+
str = str.gsub("\"", "\\\"")
|
25
|
+
str = str.gsub("''", "'")
|
26
|
+
"\"#{str}\""
|
27
|
+
end
|
28
|
+
when Integer
|
29
|
+
ary
|
14
30
|
else
|
15
|
-
"
|
31
|
+
raise ArgumentError, "Don't know how to encode array of #{ary.first.class}"
|
16
32
|
end
|
17
33
|
end
|
18
34
|
end
|
@@ -7,14 +7,7 @@ module Simple::SQL::MonkeyPatches
|
|
7
7
|
|
8
8
|
@@warned[msg] = true
|
9
9
|
|
10
|
-
|
11
|
-
== patching notice: ======================================================================================
|
12
|
-
Note that simple-sql changes the behaviour of underlying gems in subtle ways:
|
13
|
-
#{msg}
|
14
|
-
==========================================================================================================
|
15
|
-
MSG
|
16
|
-
|
17
|
-
STDERR.puts msg
|
10
|
+
STDERR.puts "== monkeypatch warning: #{msg}"
|
18
11
|
end
|
19
12
|
end
|
20
13
|
|
@@ -34,7 +27,7 @@ when /^5.2/
|
|
34
27
|
class ActiveRecord::ConnectionAdapters::ConnectionPool::Reaper
|
35
28
|
def run
|
36
29
|
return unless frequency && frequency > 0
|
37
|
-
Simple::SQL::MonkeyPatches.warn "
|
30
|
+
Simple::SQL::MonkeyPatches.warn "simple-sql disables reapers for all connection pools, see https://github.com/rails/rails/issues/33600"
|
38
31
|
end
|
39
32
|
end
|
40
33
|
|
@@ -50,7 +43,7 @@ when /^6/
|
|
50
43
|
class ActiveRecord::ConnectionAdapters::ConnectionPool::Reaper
|
51
44
|
def run
|
52
45
|
return unless frequency && frequency > 0
|
53
|
-
Simple::SQL::MonkeyPatches.warn "
|
46
|
+
Simple::SQL::MonkeyPatches.warn "simple-sql disables reapers for all connection pools, see https://github.com/rails/rails/issues/33600"
|
54
47
|
end
|
55
48
|
end
|
56
49
|
end
|
data/lib/simple/sql/version.rb
CHANGED
data/simple-sql.gemspec
CHANGED
@@ -33,9 +33,9 @@ Gem::Specification.new do |gem|
|
|
33
33
|
# during tests we check the SIMPLE_SQL_ACTIVERECORD_SPECS environment setting.
|
34
34
|
# Run make tests to run all tests
|
35
35
|
if ENV["SIMPLE_SQL_ACTIVERECORD_SPECS"]
|
36
|
-
gem.add_dependency 'activerecord', '
|
36
|
+
gem.add_dependency 'activerecord', '>= 5.2.4.5', *(ENV["SIMPLE_SQL_ACTIVERECORD_SPECS"].split(","))
|
37
37
|
else
|
38
|
-
gem.add_dependency 'activerecord', '
|
38
|
+
gem.add_dependency 'activerecord', '>= 5.2.4.5', '< 7'
|
39
39
|
end
|
40
40
|
|
41
41
|
# optional gems (required by some of the parts)
|
@@ -23,6 +23,7 @@ describe "Simple::SQL conversions" do
|
|
23
23
|
expects "foo,\"bar}", "SELECT $1::varchar", "foo,\"bar}"
|
24
24
|
expects ["one", "two", "3.5", "foo,\"bar}"], "SELECT ARRAY['one', 'two', '3.5', 'foo,\"bar}']"
|
25
25
|
expects ["foo", "foo,bar}"], "SELECT $1::varchar[]", ["foo", "foo,bar}"]
|
26
|
+
expects "foo'bar", 'SELECT $1', "foo'bar"
|
26
27
|
end
|
27
28
|
|
28
29
|
it "parses JSON as expected" do
|
@@ -42,13 +43,15 @@ describe "Simple::SQL conversions" do
|
|
42
43
|
it "converts hstore" do
|
43
44
|
expects({ a: "1", b: "3" }, "SELECT 'a=>1,b=>3'::hstore")
|
44
45
|
end
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "arra conversions" do
|
49
|
+
it "works with strings" do
|
50
|
+
expects [ "foo", "bar" ], 'SELECT $1::varchar[]', [ "foo", "bar" ]
|
51
|
+
|
52
|
+
# test escaping
|
53
|
+
expects [ "foo", "foo'bar\"baz" ], 'SELECT $1::varchar[]', [ "foo", "foo'bar\"baz" ]
|
54
|
+
expects [ ], 'SELECT $1::varchar[]', []
|
52
55
|
end
|
53
56
|
end
|
54
57
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
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.33
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- radiospiel
|
8
8
|
- mediapeers GmbH
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-03-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pg_array_parser
|
@@ -91,9 +91,9 @@ dependencies:
|
|
91
91
|
name: activerecord
|
92
92
|
requirement: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 5.2.4.5
|
97
97
|
- - "<"
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: '7'
|
@@ -101,9 +101,9 @@ dependencies:
|
|
101
101
|
prerelease: false
|
102
102
|
version_requirements: !ruby/object:Gem::Requirement
|
103
103
|
requirements:
|
104
|
-
- - "
|
104
|
+
- - ">="
|
105
105
|
- !ruby/object:Gem::Version
|
106
|
-
version:
|
106
|
+
version: 5.2.4.5
|
107
107
|
- - "<"
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '7'
|
@@ -185,6 +185,7 @@ extra_rdoc_files: []
|
|
185
185
|
files:
|
186
186
|
- ".gitignore"
|
187
187
|
- ".rubocop.yml"
|
188
|
+
- ".ruby-version"
|
188
189
|
- ".tm_properties"
|
189
190
|
- Gemfile
|
190
191
|
- Makefile
|
@@ -271,7 +272,7 @@ files:
|
|
271
272
|
homepage: http://github.com/radiospiel/simple-sql
|
272
273
|
licenses: []
|
273
274
|
metadata: {}
|
274
|
-
post_install_message:
|
275
|
+
post_install_message:
|
275
276
|
rdoc_options: []
|
276
277
|
require_paths:
|
277
278
|
- lib
|
@@ -286,8 +287,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
286
287
|
- !ruby/object:Gem::Version
|
287
288
|
version: '0'
|
288
289
|
requirements: []
|
289
|
-
rubygems_version: 3.
|
290
|
-
signing_key:
|
290
|
+
rubygems_version: 3.1.4
|
291
|
+
signing_key:
|
291
292
|
specification_version: 4
|
292
293
|
summary: SQL with a simple interface
|
293
294
|
test_files:
|