simple-sql 0.5.23 → 0.5.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cbb0a371e312ccb7a120a00dce988ea11882f6261461b4e9f7c2b674bd00dff0
4
- data.tar.gz: 759fe61ab061924a2b3a1668fc1e92bd4ee8d89fa9af74cd266ec680bc96c97d
3
+ metadata.gz: 064d2319d350d4a8c56aa6cdf697ccd06d7c01426000396041e1a8bd1c74a5be
4
+ data.tar.gz: a55aaa2a188f306723911f457383c4536510d010149beaefbf001c025bd46e19
5
5
  SHA512:
6
- metadata.gz: 0dd8a0f966dc83766647f0a5957b5e46432f3ee1c58aefbc11990ad0cc0abf627ff9b9419e2ab26bd53062abdd12b5b082463ed4c6079e46c37e3c4ca34a505e
7
- data.tar.gz: f672f6e5dc920c805f3cc8fc13b02675156bee83a2da070f70f938896428b8bfa5a59d9d6aa0b325a30e846db83ed641931be07ac06616ba86bf6a05ebe3f242
6
+ metadata.gz: 872cf1147c72f1ae4c3030e71077a78ef5f33a7fc19e0779387de15aac18c314263439174e8efb19b3c85cffd43f926fd5c4964f63ead8f566aebaf7df61d873
7
+ data.tar.gz: d20549394c237fa154c0f1cb372b0286806242295a761f3a996e3b9170b0c0b05f81c70bc13bc285296388358cb9d4723322fc90a539fad87e223973a5c145bf
data/Makefile CHANGED
@@ -1,3 +1,17 @@
1
+ tests: test4 test5 test6
2
+
3
+ test4:
4
+ SIMPLE_SQL_ACTIVERECORD_SPECS="< 5" bundle
5
+ rspec
6
+
7
+ test5:
8
+ SIMPLE_SQL_ACTIVERECORD_SPECS="< 6" bundle
9
+ rspec
10
+
11
+ test6:
12
+ SIMPLE_SQL_ACTIVERECORD_SPECS="< 7" bundle
13
+ rspec
14
+
1
15
  stats:
2
16
  @scripts/stats lib/simple/sql
3
17
  @scripts/stats spec/simple/sql
data/Rakefile CHANGED
@@ -22,3 +22,13 @@ task default: "test:prepare_db" do
22
22
  sh "rspec"
23
23
  sh "rubocop -D"
24
24
  end
25
+
26
+ desc 'release a new development gem version'
27
+ task :release do
28
+ sh 'scripts/release.rb'
29
+ end
30
+
31
+ desc 'release a new stable gem version'
32
+ task 'release:stable' do
33
+ sh 'BRANCH=stable scripts/release.rb'
34
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.5.24
@@ -45,8 +45,17 @@ module Simple::SQL
45
45
  automatic_reconnect: connection_pool.automatic_reconnect,
46
46
  checkout_timeout: connection_pool.checkout_timeout
47
47
  }
48
- ::Simple::SQL.logger.info "#{url}: connected to connection pool w/#{connection_pool_stats.inspect}"
48
+ ::Simple::SQL.logger.info "#{URI.without_password url}: connected to connection pool w/#{connection_pool_stats.inspect}"
49
49
  end
50
50
  end
51
51
  end
52
52
  end
53
+
54
+ module URI
55
+ def self.without_password(uri)
56
+ uri = URI.parse(uri) unless uri.is_a?(URI)
57
+ uri = uri.dup
58
+ uri.password = "*" * uri.password.length if uri.password
59
+ uri
60
+ end
61
+ end
@@ -23,7 +23,7 @@ module Simple::SQL::Helpers::Decoder
23
23
  when :hstore then HStore.parse(s)
24
24
  when :json then ::JSON.parse(s)
25
25
  when :jsonb then ::JSON.parse(s)
26
- when :boolean then s == "t"
26
+ when :boolean then s == "t" || s == true
27
27
  else
28
28
  # unknown value, we just return the string here.
29
29
  # STDERR.puts "unknown type: #{type.inspect}"
@@ -46,6 +46,7 @@ class ::Simple::SQL::Result < Array
46
46
  #
47
47
  # This is only available for paginated scopes
48
48
  def total_count
49
+ # TODO: Implement total_count for non-paginated scopes!
49
50
  @total_count ||= pagination_scope.count
50
51
  end
51
52
 
@@ -61,7 +62,7 @@ class ::Simple::SQL::Result < Array
61
62
  end
62
63
 
63
64
  def pagination_scope
64
- raise "Only available only for paginated scopes" unless paginated?
65
+ raise "Available only on paginated scopes" unless paginated?
65
66
 
66
67
  @pagination_scope
67
68
  end
@@ -1,5 +1,23 @@
1
1
  module Simple
2
- module SQL
3
- VERSION = "0.5.23"
2
+ module GemHelper
3
+ extend self
4
+
5
+ def version(name)
6
+ spec = Gem.loaded_specs[name]
7
+ version = spec.version.to_s
8
+ version += "+unreleased" if unreleased?(spec)
9
+ version
10
+ end
11
+
12
+ private
13
+
14
+ def unreleased?(spec)
15
+ return false unless defined?(Bundler::Source::Gemspec)
16
+ return true if spec.source.is_a?(::Bundler::Source::Gemspec)
17
+ return true if spec.source.is_a?(::Bundler::Source::Path)
18
+ false
19
+ end
4
20
  end
21
+
22
+ VERSION = GemHelper.version "simple-sql"
5
23
  end
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+
3
+ $0.rb "$@"
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # -- helpers ------------------------------------------------------------------
4
+
5
+ def sys(cmd)
6
+ STDERR.puts "> #{cmd}"
7
+ system cmd
8
+ return true if $?.success?
9
+
10
+ STDERR.puts "> #{cmd} returned with exitstatus #{$?.exitstatus}"
11
+ $?.success?
12
+ end
13
+
14
+ def sys!(cmd, error: nil)
15
+ return true if sys(cmd)
16
+ STDERR.puts error if error
17
+ exit 1
18
+ end
19
+
20
+ def die!(msg)
21
+ STDERR.puts msg
22
+ exit 1
23
+ end
24
+
25
+ ROOT = File.expand_path("#{File.dirname(__FILE__)}/..")
26
+
27
+ GEMSPEC = Dir.glob("*.gemspec").first || die!("Missing gemspec file.")
28
+
29
+ # -- Version reading and bumping ----------------------------------------------
30
+
31
+ module Version
32
+ extend self
33
+
34
+ VERSION_FILE = "#{Dir.getwd}/VERSION"
35
+
36
+ def read_version
37
+ version = File.exist?(VERSION_FILE) ? File.read(VERSION_FILE) : "0.0.1"
38
+ version.chomp!
39
+ raise "Invalid version number in #{VERSION_FILE}" unless version =~ /^\d+\.\d+\.\d+$/
40
+ version
41
+ end
42
+
43
+ def auto_version_bump
44
+ old_version_number = read_version
45
+ old = old_version_number.split('.')
46
+
47
+ current = old[0..-2] << old[-1].next
48
+ current.join('.')
49
+ end
50
+
51
+ def bump_version
52
+ next_version = ENV["VERSION"] || auto_version_bump
53
+ File.open(VERSION_FILE, "w") { |io| io.write next_version }
54
+ end
55
+ end
56
+
57
+ # -- check, bump, release a new gem version -----------------------------------
58
+
59
+ Dir.chdir ROOT
60
+ $BASE_BRANCH = ENV['BRANCH'] || 'master'
61
+
62
+ # ENV["BUNDLE_GEMFILE"] = "#{Dir.getwd}/Gemfile"
63
+ # sys! "bundle install"
64
+
65
+ sys! "git diff --exit-code > /dev/null", error: 'There are unstaged changes in your working directory'
66
+ sys! "git diff --cached --exit-code > /dev/null", error: 'There are staged but uncommitted changes'
67
+
68
+ sys! "git checkout #{$BASE_BRANCH}"
69
+ sys! "git pull"
70
+
71
+ Version.bump_version
72
+ version = Version.read_version
73
+
74
+ sys! "git add VERSION"
75
+ sys! "git commit -m \"bump gem to v#{version}\""
76
+ sys! "git tag -a v#{version} -m \"Tag #{version}\""
77
+
78
+ sys! "git push origin #{$BASE_BRANCH}"
79
+ sys! 'git push --tags --force'
80
+
81
+ sys! "gem build #{GEMSPEC}"
82
+ sys! "mkdir -p pkg"
83
+ sys! "mv *.gem pkg"
84
+
85
+ gem_file = Dir.glob('pkg/*.gem').sort.last
86
+
87
+ sys! "gem install #{gem_file}"
88
+ sys! "gem push #{gem_file}"
89
+
90
+ STDERR.puts <<-MSG
91
+ ================================================================================
92
+ Thank you for releasing a new gem version. You made my day.
93
+ ================================================================================
94
+ MSG
@@ -3,13 +3,9 @@
3
3
  # Copyright (c) 2016, 2017 @radiospiel, mediapeers Gem
4
4
  # Distributed under the terms of the modified BSD license, see LICENSE.BSD
5
5
 
6
- lib = File.expand_path('../lib', __FILE__)
7
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
8
- require 'simple/sql/version'
9
-
10
6
  Gem::Specification.new do |gem|
11
7
  gem.name = "simple-sql"
12
- gem.version = Simple::SQL::VERSION
8
+ gem.version = File.read "VERSION"
13
9
 
14
10
  gem.authors = [ "radiospiel", "mediapeers GmbH" ]
15
11
  gem.email = "eno@radiospiel.org"
@@ -27,13 +23,19 @@ Gem::Specification.new do |gem|
27
23
 
28
24
  gem.required_ruby_version = '~> 2.3'
29
25
 
30
- gem.add_dependency 'pg_array_parser', '~> 0'
26
+ gem.add_dependency 'pg_array_parser', '~> 0', '>= 0.0.9'
31
27
  gem.add_dependency 'pg', '~> 0.20'
32
28
  gem.add_dependency 'expectation', '~> 1'
33
29
 
34
30
  gem.add_dependency 'digest-crc', '~> 0'
35
31
 
36
- gem.add_dependency 'activerecord', '> 4'
32
+ # during tests we check the SIMPLE_SQL_ACTIVERECORD_SPECS environment setting.
33
+ # Run make tests to run all tests
34
+ if ENV["SIMPLE_SQL_ACTIVERECORD_SPECS"]
35
+ gem.add_dependency 'activerecord', '> 4.2', *(ENV["SIMPLE_SQL_ACTIVERECORD_SPECS"].split(","))
36
+ else
37
+ gem.add_dependency 'activerecord', '> 4.2', '< 7'
38
+ end
37
39
 
38
40
  # optional gems (required by some of the parts)
39
41
 
@@ -43,6 +45,4 @@ Gem::Specification.new do |gem|
43
45
  gem.add_development_dependency 'rspec', '~> 3.7'
44
46
  gem.add_development_dependency 'rubocop', '~> 0.61.1'
45
47
  gem.add_development_dependency 'simplecov', '~> 0'
46
-
47
- gem.add_development_dependency 'memory_profiler', '~> 0.9.12'
48
48
  end
@@ -64,85 +64,4 @@ describe "Simple::SQL.each" do
64
64
  expect(received.map(&:class).uniq).to eq([Simple::SQL::Helpers::Immutable])
65
65
  end
66
66
  end
67
-
68
- xdescribe "memory usage: pending due to inconclusive results" do
69
- it "generates a series" do
70
- each! "SELECT a.n from generate_series(1, 100) as a(n)"
71
- expect(received).to eq((1..100).to_a)
72
- end
73
-
74
- require 'memory_profiler'
75
-
76
- def measure_retained_objects(msg, &block)
77
- r = nil
78
- report = MemoryProfiler.report do
79
- r = yield
80
- end
81
-
82
- STDERR.puts "#{msg} Total allocated: #{report.total_allocated_memsize} bytes (#{report.total_allocated} objects)"
83
- STDERR.puts "#{msg} Total retained: #{report.total_retained_memsize} bytes (#{report.total_retained} objects)"
84
-
85
- report.total_retained_memsize
86
- end
87
-
88
- it "is using less memory than .all" do
89
- sql_warmup = "SELECT a.n from generate_series(10000, 100) as a(n)"
90
-
91
- SQL.all(sql_warmup, into: Hash)
92
-
93
- SQL.each(sql_warmup) do |id|
94
- :nop
95
- end
96
-
97
- cnt = 1000000
98
- sql = "SELECT a.n from generate_series(#{cnt}, #{cnt}) as a(n)"
99
-
100
- r = nil
101
- retained_objects_all = measure_retained_objects "all" do
102
- r = SQL.all(sql, into: Hash)
103
- end
104
-
105
- retained_objects_each = measure_retained_objects "each" do
106
- r = SQL.each(sql) do |id|
107
- :nop
108
- end
109
- end
110
-
111
- expect(0).to eq "one"
112
- end
113
- end
114
- end
115
-
116
- __END__
117
-
118
- describe "each into: X" do
119
- it "calls the database" do
120
- r = SQL.all("SELECT id FROM users", into: Hash)
121
- expect(r).to be_a(Array)
122
- expect(r.length).to eq(USER_COUNT)
123
- expect(r.map(&:class).uniq).to eq([Hash])
124
- end
125
-
126
- it "returns an empty array when there is no match" do
127
- r = SQL.all("SELECT * FROM users WHERE FALSE", into: Hash)
128
- expect(r).to eq([])
129
- end
130
-
131
- it "yields the results into a block" do
132
- received = []
133
- SQL.all("SELECT id FROM users", into: Hash) do |hsh|
134
- received << hsh
135
- end
136
- expect(received.length).to eq(USER_COUNT)
137
- expect(received.map(&:class).uniq).to eq([Hash])
138
- end
139
-
140
- it "does not yield if there is no match" do
141
- received = []
142
- SQL.all("SELECT id FROM users WHERE FALSE", into: Hash) do |hsh|
143
- received << hsh
144
- end
145
- expect(received.length).to eq(0)
146
- end
147
- end
148
67
  end
@@ -4,8 +4,9 @@ require "yaml"
4
4
  abc = YAML.load_file("config/database.yml")
5
5
  ActiveRecord::Base.establish_connection(abc["test"])
6
6
 
7
- # Remove after migration to Rails 5
8
- ActiveRecord::Base.raise_in_transactional_callbacks = true
7
+ if ActiveRecord::Base.respond_to?(:raise_in_transactional_callbacks=)
8
+ ActiveRecord::Base.raise_in_transactional_callbacks = true
9
+ end
9
10
 
10
11
  ActiveRecord::Base.logger = Logger.new("log/test.log")
11
12
 
@@ -5,6 +5,7 @@ SimpleCov.start do
5
5
  add_filter do |src|
6
6
  next true if src.filename =~ /\/spec\//
7
7
  next true if src.filename =~ /\/immutable\.rb/
8
+ next true if src.filename =~ /simple\/sql\/table_print\.rb/
8
9
 
9
10
  false
10
11
  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.23
4
+ version: 0.5.24
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: 2019-10-09 00:00:00.000000000 Z
12
+ date: 2019-12-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pg_array_parser
@@ -18,6 +18,9 @@ dependencies:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
20
  version: '0'
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.9
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -25,6 +28,9 @@ dependencies:
25
28
  - - "~>"
26
29
  - !ruby/object:Gem::Version
27
30
  version: '0'
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.9
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: pg
30
36
  requirement: !ruby/object:Gem::Requirement
@@ -73,14 +79,20 @@ dependencies:
73
79
  requirements:
74
80
  - - ">"
75
81
  - !ruby/object:Gem::Version
76
- version: '4'
82
+ version: '4.2'
83
+ - - "<"
84
+ - !ruby/object:Gem::Version
85
+ version: '7'
77
86
  type: :runtime
78
87
  prerelease: false
79
88
  version_requirements: !ruby/object:Gem::Requirement
80
89
  requirements:
81
90
  - - ">"
82
91
  - !ruby/object:Gem::Version
83
- version: '4'
92
+ version: '4.2'
93
+ - - "<"
94
+ - !ruby/object:Gem::Version
95
+ version: '7'
84
96
  - !ruby/object:Gem::Dependency
85
97
  name: pg
86
98
  requirement: !ruby/object:Gem::Requirement
@@ -151,20 +163,6 @@ dependencies:
151
163
  - - "~>"
152
164
  - !ruby/object:Gem::Version
153
165
  version: '0'
154
- - !ruby/object:Gem::Dependency
155
- name: memory_profiler
156
- requirement: !ruby/object:Gem::Requirement
157
- requirements:
158
- - - "~>"
159
- - !ruby/object:Gem::Version
160
- version: 0.9.12
161
- type: :development
162
- prerelease: false
163
- version_requirements: !ruby/object:Gem::Requirement
164
- requirements:
165
- - - "~>"
166
- - !ruby/object:Gem::Version
167
- version: 0.9.12
168
166
  description: SQL with a simple interface. Postgres only.
169
167
  email: eno@radiospiel.org
170
168
  executables: []
@@ -178,6 +176,7 @@ files:
178
176
  - Makefile
179
177
  - README.md
180
178
  - Rakefile
179
+ - VERSION
181
180
  - bin/console
182
181
  - bin/db_restore
183
182
  - bin/pg
@@ -219,6 +218,8 @@ files:
219
218
  - lib/simple/sql/table_print.rb
220
219
  - lib/simple/sql/version.rb
221
220
  - log/.gitkeep
221
+ - scripts/release
222
+ - scripts/release.rb
222
223
  - scripts/stats
223
224
  - scripts/watch
224
225
  - simple-sql.gemspec
@@ -248,7 +249,6 @@ files:
248
249
  - spec/support/003_factories.rb
249
250
  - spec/support/004_simplecov.rb
250
251
  - spec/support/model/user.rb
251
- - tasks/release.rake
252
252
  - vendor/.gitignore
253
253
  - vendor/Makefile
254
254
  homepage: http://github.com/radiospiel/simple-sql
@@ -269,7 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
269
269
  - !ruby/object:Gem::Version
270
270
  version: '0'
271
271
  requirements: []
272
- rubygems_version: 3.0.4
272
+ rubygems_version: 3.0.6
273
273
  signing_key:
274
274
  specification_version: 4
275
275
  summary: SQL with a simple interface
@@ -1,107 +0,0 @@
1
- require 'bundler'
2
- Bundler.setup
3
-
4
- GEM_ROOT = File.expand_path('../../', __FILE__)
5
- GEM_SPEC = "simple-sql.gemspec"
6
-
7
- require 'simple/sql/version'
8
- VERSION_FILE_PATH = 'lib/simple/sql/version.rb'
9
-
10
- class VersionNumberTracker
11
- class << self
12
- def update_version_file(old_version_number, new_version_number)
13
- old_line = "VERSION = \"#{old_version_number}\""
14
- new_line = "VERSION = \"#{new_version_number}\""
15
- update = File.read(VERSION_FILE_PATH).gsub(old_line, new_line)
16
- File.open(VERSION_FILE_PATH, 'w') { |file| file.puts update }
17
- new_version_number
18
- end
19
-
20
- def auto_version_bump
21
- old_version_number = Simple::SQL::VERSION
22
- old = old_version_number.split('.')
23
- current = old[0..-2] << old[-1].next
24
- new_version_number = current.join('.')
25
-
26
- update_version_file(old_version_number, new_version_number)
27
- end
28
-
29
- def manual_version_bump
30
- update_version_file(Simple::SQL::VERSION, ENV['VERSION'])
31
- end
32
-
33
- def update_version_number
34
- @version = ENV['VERSION'] ? manual_version_bump : auto_version_bump
35
- end
36
-
37
- attr_reader :version
38
- end
39
- end
40
-
41
- namespace :release do
42
- task :version do
43
- VersionNumberTracker.update_version_number
44
- end
45
-
46
- task :build do
47
- Dir.chdir(GEM_ROOT) do
48
- sh("gem build #{GEM_SPEC}")
49
- end
50
- end
51
-
52
- desc "Commit changes"
53
- task :commit do
54
- Dir.chdir(GEM_ROOT) do
55
- version = VersionNumberTracker.version
56
- sh("git add #{VERSION_FILE_PATH}")
57
- sh("git commit -m \"bump to v#{version}\"")
58
- sh("git tag -a v#{version} -m \"Tag\"")
59
- end
60
- end
61
-
62
- desc "Push code and tags"
63
- task :push do
64
- sh("git push origin #{$TARGET_BRANCH}")
65
- sh('git push --tags')
66
- end
67
-
68
- desc "Cleanup"
69
- task :clean do
70
- Dir.glob(File.join(GEM_ROOT, '*.gem')).each { |f| FileUtils.rm_rf(f) }
71
- end
72
-
73
- desc "Push Gem to gemfury"
74
- task :publish do
75
- Dir.chdir(GEM_ROOT) { sh("gem push #{Dir.glob('*.gem').first}") }
76
- end
77
-
78
- task :target_master do
79
- $TARGET_BRANCH = 'master'
80
- end
81
-
82
- task :target_stable do
83
- $TARGET_BRANCH = 'stable'
84
- end
85
-
86
- task :checkout do
87
- sh "git status --untracked-files=no --porcelain > /dev/null || (echo '*** working dir not clean' && false)"
88
- sh "git checkout #{$TARGET_BRANCH}"
89
- sh "git pull"
90
- end
91
-
92
- task default: [
93
- 'checkout',
94
- 'version',
95
- 'clean',
96
- 'build',
97
- 'commit',
98
- 'push',
99
- 'publish'
100
- ]
101
-
102
- task master: %w(target_master default)
103
- task stable: %w(target_stable default)
104
- end
105
-
106
- desc "Clean, build, commit and push"
107
- task release: 'release:master'