simple-sql 0.5.31 → 0.5.32
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/lib/simple/sql/helpers/encoder.rb +19 -3
- data/lib/simple/sql/version.rb +1 -0
- data/spec/simple/sql/conversion_spec.rb +10 -7
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb4af8eb0802b84e83370417d134ff18f82c812dbd9a053853739d9570f92a95
|
4
|
+
data.tar.gz: 0b023420320187d12f32cb6e1a4a093775a5bd2849015443768b0177392729fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 996461571d090b5cf7589dfc6f1d12925b11b54d047fc2ec2395bbb6a2d75e583a7f82d0cc92985982891d3254e3e26a83260f6a38be5bee0eac5872effb4609
|
7
|
+
data.tar.gz: 57decbf1a834422bdfc2987056c3fa37f04988de7059ed8c6eb8aa64ffc16c445a19f1dc9e91f880eac8a2ea7e8772dcfb8b1aeaf43b57ca7f13d4662ceaf177
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.32
|
@@ -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
|
data/lib/simple/sql/version.rb
CHANGED
@@ -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.32
|
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-02-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pg_array_parser
|
@@ -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:
|