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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f29429815715916d62f0f03dc831d97e0e0312152f431a49c092a09f1bd48d9e
4
- data.tar.gz: d02ced1cda31cdca64bbe1f43035cf628d40b80b20c1782bb16e44aee5f15ea8
3
+ metadata.gz: 567c2dd86ca2849c533ced2e9d3dcc14705ca71659bbe19e63fc82fe2907e15d
4
+ data.tar.gz: 1a799e2970974d7acbcc0587a14547674124686f1361ddc0f8049811eb0653e8
5
5
  SHA512:
6
- metadata.gz: 1f5c9709450f03cd4b7f8691738f182667b5b53a90fc5e22b4ef00a6c7778bbd7f6f78f153839205e5ecea8a14be9beb84da3d9857e418fc09a7d5f0248881e2
7
- data.tar.gz: 6ab77cad786ea2f2d2f2b6bea6d49e5b2e76e3bfa5ed15b9d856dd5b8852b2d1c376b841f5c5c78f1b92964dd0c90f87f89247a0879cf8581f5ccd2a647cbdba
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.28
1
+ 0.5.33
data/config/database.yml CHANGED
@@ -2,7 +2,8 @@ defaults: &defaults
2
2
  adapter: postgresql
3
3
  encoding: utf8
4
4
  host: '127.0.0.1'
5
- # username: postgres
5
+ username: admin
6
+ password: admin
6
7
  pool: 5
7
8
  timeout: 5000
8
9
 
@@ -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(count)
7
- duplicate.send(:limit!, count)
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, "per must be > 0" unless @per > 0
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
- if arg.first.is_a?(String)
13
- "{#{arg.map { |a| "\"#{connection.escape(a)}\"" }.join(',')}}"
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
- "{#{arg.join(',')}}"
31
+ raise ArgumentError, "Don't know how to encode array of #{ary.first.class}"
16
32
  end
17
33
  end
18
34
  end
@@ -1,3 +1,5 @@
1
+ require "simple-immutable"
2
+
1
3
  module Simple
2
4
  module SQL
3
5
  module Helpers
@@ -7,14 +7,7 @@ module Simple::SQL::MonkeyPatches
7
7
 
8
8
  @@warned[msg] = true
9
9
 
10
- msg = <<~MSG
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 "disable Reaper for all ActiveRecord connection pools, see https://github.com/rails/rails/issues/33600"
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 "disable Reaper for all ActiveRecord connection pools, see https://github.com/rails/rails/issues/33600"
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
@@ -5,6 +5,7 @@ module Simple
5
5
 
6
6
  def version(name)
7
7
  spec = Gem.loaded_specs[name]
8
+ return "unreleased" unless spec
8
9
  version = spec.version.to_s
9
10
  version += "+unreleased" if unreleased?(spec)
10
11
  version
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', '> 4.2', *(ENV["SIMPLE_SQL_ACTIVERECORD_SPECS"].split(","))
36
+ gem.add_dependency 'activerecord', '>= 5.2.4.5', *(ENV["SIMPLE_SQL_ACTIVERECORD_SPECS"].split(","))
37
37
  else
38
- gem.add_dependency 'activerecord', '> 4.2', '< 7'
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
- xit "fails sometimes w/ malformed array literal, pt. 1" do
47
- expects 0, 'SELECT $1::varchar[]', [ "foo", 'foo,"bar}' ]
48
- end
49
-
50
- xit "fails sometimes w/ malformed array literal, pt. 2" do
51
- expects 0, 'SELECT $1::varchar[]', [ "foo", 'foo,"bar}' ]
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.28
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: 2020-03-04 00:00:00.000000000 Z
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: '4.2'
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: '4.2'
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.0.6
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: