simple-sql 0.5.31 → 0.5.36

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: 7490b50fc301d6e1a8c424e46a21f4a5cb97767ca2a99c7bdeed94b7c499a0d6
4
- data.tar.gz: 3e1ec456a008d2abee6260b84beb1c17ca4b5934c1b934f00298ad6263b0f849
3
+ metadata.gz: a5185777df8efad3d0d17334a70d30b35551f4abd7adf0fded3549dd2d1b1325
4
+ data.tar.gz: e34ee800440259bfbe8ef88f9f70fb1675dee4a91e441c162a8bdc6313e5d88f
5
5
  SHA512:
6
- metadata.gz: 5c4ff2ac25d314393ff79a5f8ff3171508b05f30a99f37d1681a5b4af0fe3f07f247623321e235fc70de4d384d8e994935fc69eaf592c41b8459ceb0c875adf7
7
- data.tar.gz: e59f00c7d6a3f00d1f4c2ca101985e8a01b453cc80b774f5f95b867eebea3e1dddf70a341fd4bf8904e497b19738d58e2a66d20a08372a138bf2302d918af1cb
6
+ metadata.gz: 9b03b9f204d9bd0e87e0c349f1f2ab962bc94101f14ab33cb2522c0287861e801ddca3cd98e97f4317716df7a07a054f6acf26837309f18bc14b8a50f95eac4a
7
+ data.tar.gz: 5eb4fe4c83ca847aef2263251b56f95b3ea450c15abc1e8289ed92bbcaaaa5d5d8a3683814c009c2dd4928d679a4072d10717a616e3cbac2978d59f2d2f453e8
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.31
1
+ 0.5.36
@@ -21,7 +21,13 @@ class Simple::SQL::Connection::Scope
21
21
  sql = order_by(nil).to_sql(pagination: false)
22
22
 
23
23
  cost = @connection.estimate_cost "SELECT MIN(#{sql_fragment}) FROM (#{sql}) sq", *args
24
- raise "enumerate_groups(#{sql_fragment.inspect}) takes too much time. Make sure to create a suitable index" if cost > 10_000
24
+
25
+ # cost estimates are good, but are hard to check against a hard coded value.
26
+ # see https://issues.mediafellows.com/issues/75232
27
+ #
28
+ # if cost > 10_000
29
+ # raise "enumerate_groups(#{sql_fragment.inspect}) takes too much time. Make sure to create a suitable index"
30
+ # end
25
31
 
26
32
  groups = []
27
33
  var_name = "$#{@args.count + 1}"
@@ -43,8 +49,12 @@ class Simple::SQL::Connection::Scope
43
49
  end
44
50
 
45
51
  def count_by_estimate(sql_fragment)
46
- sql = order_by(nil).to_sql(pagination: false)
52
+ return count_by(sql_fragment)
47
53
 
54
+ # The code below runs an estimate on the effort to count by a group. This is currently
55
+ # disabled (see https://issues.mediafellows.com/issues/75237).
56
+
57
+ sql = order_by(nil).to_sql(pagination: false)
48
58
  cost = @connection.estimate_cost "SELECT COUNT(*) FROM (#{sql}) sq GROUP BY #{sql_fragment}", *args
49
59
 
50
60
  return count_by(sql_fragment) if cost < 10_000
@@ -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
@@ -2,12 +2,14 @@
2
2
 
3
3
  module Simple::SQL::MonkeyPatches
4
4
  def self.warn(msg)
5
+ return if ENV["SIMPLE_SQL_SILENCE"] == "1"
6
+
5
7
  @@warned ||= {}
6
8
  return if @@warned[msg]
7
9
 
8
10
  @@warned[msg] = true
9
11
 
10
- STDERR.puts "== monkeypatch warning: #{msg}"
12
+ STDERR.puts "== monkeypatch warning: #{msg} (set SIMPLE_SQL_SILENCE=1 to disable)"
11
13
  end
12
14
  end
13
15
 
@@ -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
@@ -0,0 +1,29 @@
1
+ require "benchmark"
2
+ require "simple-sql"
3
+
4
+ ENV["DATABASE_URL"] = "postgres://admin:admin@localhost/um_development"
5
+
6
+ Simple::SQL.connect
7
+ # require 'stackprof'# added
8
+
9
+ Benchmark.bmbm do |x|
10
+ x.report("1000x Simple::SQL HStore performance for 100 users") do
11
+ 1000.times { Simple::SQL.all("SELECT id, meta_data FROM users limit 100") }
12
+ end
13
+
14
+ x.report("1000x Simple::SQL HStore::varchar performance for 100 users") do
15
+ 1000.times { Simple::SQL.all("SELECT id, meta_data::varchar FROM users limit 100") }
16
+ end
17
+
18
+ x.report("1000x Simple::SQL HStore as jsonb performance for 100 users") do
19
+ 1000.times { Simple::SQL.all("SELECT id, to_jsonb(meta_data) FROM users limit 100") }
20
+ end
21
+
22
+ x.report("1000x Simple::SQL timestamp performance for 100 users") do
23
+ 1000.times { Simple::SQL.all("SELECT id, created_at FROM users limit 100") }
24
+ end
25
+
26
+ x.report("1000x Simple::SQL timestamp::varchar performance for 100 users") do
27
+ 1000.times { Simple::SQL.all("SELECT id, created_at::varchar FROM users limit 100") }
28
+ end
29
+ end
data/simple-sql.gemspec CHANGED
@@ -33,16 +33,16 @@ 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', '< 6.1'
39
39
  end
40
40
 
41
41
  # optional gems (required by some of the parts)
42
42
 
43
43
  # development gems
44
44
  gem.add_development_dependency 'pg', '0.20'
45
- gem.add_development_dependency 'rake', '~> 11'
45
+ gem.add_development_dependency 'rake', '>= 12.3.3'
46
46
  gem.add_development_dependency 'rspec', '~> 3.7'
47
47
  gem.add_development_dependency 'rubocop', '~> 0.61.1'
48
48
  gem.add_development_dependency 'simplecov', '~> 0'
@@ -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.31
4
+ version: 0.5.36
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-09-04 00:00:00.000000000 Z
12
+ date: 2021-04-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pg_array_parser
@@ -91,22 +91,22 @@ 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
- version: '7'
99
+ version: '6.1'
100
100
  type: :runtime
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
- version: '7'
109
+ version: '6.1'
110
110
  - !ruby/object:Gem::Dependency
111
111
  name: pg
112
112
  requirement: !ruby/object:Gem::Requirement
@@ -125,16 +125,16 @@ dependencies:
125
125
  name: rake
126
126
  requirement: !ruby/object:Gem::Requirement
127
127
  requirements:
128
- - - "~>"
128
+ - - ">="
129
129
  - !ruby/object:Gem::Version
130
- version: '11'
130
+ version: 12.3.3
131
131
  type: :development
132
132
  prerelease: false
133
133
  version_requirements: !ruby/object:Gem::Requirement
134
134
  requirements:
135
- - - "~>"
135
+ - - ">="
136
136
  - !ruby/object:Gem::Version
137
- version: '11'
137
+ version: 12.3.3
138
138
  - !ruby/object:Gem::Dependency
139
139
  name: rspec
140
140
  requirement: !ruby/object:Gem::Requirement
@@ -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
@@ -234,6 +235,7 @@ files:
234
235
  - lib/simple/sql/table_print.rb
235
236
  - lib/simple/sql/version.rb
236
237
  - log/.gitkeep
238
+ - scripts/benchmark1.rb
237
239
  - scripts/release
238
240
  - scripts/release.rb
239
241
  - scripts/stats
@@ -271,7 +273,7 @@ files:
271
273
  homepage: http://github.com/radiospiel/simple-sql
272
274
  licenses: []
273
275
  metadata: {}
274
- post_install_message:
276
+ post_install_message:
275
277
  rdoc_options: []
276
278
  require_paths:
277
279
  - lib
@@ -286,8 +288,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
286
288
  - !ruby/object:Gem::Version
287
289
  version: '0'
288
290
  requirements: []
289
- rubygems_version: 3.0.6
290
- signing_key:
291
+ rubygems_version: 3.1.4
292
+ signing_key:
291
293
  specification_version: 4
292
294
  summary: SQL with a simple interface
293
295
  test_files: