simple-sql 0.5.19 → 0.5.20

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: 8f07bda4a766c4847fdb1b6ff5b2ffbb46aadf64e57ae72ae0e033027aba2d13
4
- data.tar.gz: 8637da9a4e8de6f7a57c8003db0fb27e0d479005730e88e14476f3c5e7edc6ca
3
+ metadata.gz: 35d1b619f4df0cf9527247e4148c10c035bc6ce3fc3d8302d9d59f68aba13efe
4
+ data.tar.gz: 945a6e98dc8057b9bbf222a149f6cda25105144d0e9815965c05e6b35423627a
5
5
  SHA512:
6
- metadata.gz: 35b8dec9461128d4c1250c6ab3451431aa6defc442afb03cbbeb2fdb5247b9b4258aebcfb86014cf4d6bcad8313320ae028d6d65519a66cddd3dbb35524feb9c
7
- data.tar.gz: b087a97ff95ec6f848bde598625ceaf4fd3864cfb3e37a17d7001edab4eabaffcaf5b124e7b401108fbd5622f25bc02eb019bb428d071f7d4bcbb37345cc1cb4
6
+ metadata.gz: 4a132b274a9ab9c10bebba9948d9611d9eba759ba3e492e40b94da391e136970039e3e88b495073e8da358d029c492a75b42128a8921894acd523362719b6d2d
7
+ data.tar.gz: 938f7f09cd06b1f743434edd3f257b30142fc82b067badef3e7e79aea92da430e0074cb41df9364eb49c13c3d8e32fcbd87932ee4e621c0159bd969a1a74c772
@@ -1,6 +1,6 @@
1
1
  # pg 0.21 requires a file "pg/deprecated_constants" to warn about constant
2
2
  # deprecations of PGconn, PGresult, and PGError. Since this is the latest
3
- # version supported by Rails 4.2 Since this is also the latest version
3
+ # version supported by Rails 4.2 Since this is also the latest version
4
4
  # supported by ActiveRecord 4.2.* this means that with such a old version
5
5
  # you would be stuck with this rather senseless warning.
6
6
 
@@ -11,6 +11,7 @@ require_relative "sql/result"
11
11
  require_relative "sql/config"
12
12
  require_relative "sql/logging"
13
13
  require_relative "sql/connection"
14
+ require_relative "sql/table_print"
14
15
 
15
16
  module Simple
16
17
  # The Simple::SQL module
@@ -34,6 +35,11 @@ module Simple
34
35
  "'#{PG::Connection.escape_string(s)}'"
35
36
  end
36
37
 
38
+ def table_print(records, io: STDOUT, width: :auto)
39
+ ::Simple::SQL::TablePrint.table_print(records, width: width, io: io)
40
+ records
41
+ end
42
+
37
43
  # connects to the database specified via the url parameter. If called
38
44
  # without argument it tries to determine a DATABASE_URL from either the
39
45
  # environment setting (DATABASE_URL) or from a config/database.yml file,
@@ -63,5 +63,3 @@ class Simple::SQL::Connection
63
63
  extend Forwardable
64
64
  delegate [:wait_for_notify] => :raw_connection
65
65
  end
66
-
67
- # TODO disconnect! reconnect!
@@ -68,7 +68,7 @@ class Simple::SQL::Connection
68
68
  records = all sql, *args, into: Hash
69
69
  end
70
70
 
71
- ::Simple::SQL::Helpers::Printer.print(records, width: width, io: io)
71
+ ::Simple::SQL.table_print(records, width: width, io: io)
72
72
  records
73
73
  end
74
74
 
@@ -1,7 +1,6 @@
1
1
  module ::Simple::SQL::Helpers
2
2
  end
3
3
 
4
- require_relative "helpers/printer.rb"
5
4
  require_relative "helpers/decoder.rb"
6
5
  require_relative "helpers/encoder.rb"
7
6
  require_relative "helpers/row_converter.rb"
@@ -1,12 +1,12 @@
1
1
  # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
2
2
 
3
3
  # private
4
- module Simple::SQL::Helpers::Printer
4
+ module Simple::SQL::TablePrint
5
5
  extend self
6
6
 
7
7
  ROW_SEPARATOR = " | "
8
8
 
9
- def print(records, io: STDOUT, width: :auto)
9
+ def table_print(records, io: STDOUT, width: :auto)
10
10
  # check args
11
11
 
12
12
  return if records.empty?
@@ -23,6 +23,7 @@ module Simple::SQL::Helpers::Printer
23
23
 
24
24
  rows = materialize_rows(records)
25
25
  column_widths = column_max_lengths(rows)
26
+
26
27
  if width
27
28
  column_widths = distribute_column_widths(column_widths, width, column_count, rows.first)
28
29
  end
@@ -68,6 +69,9 @@ module Simple::SQL::Helpers::Printer
68
69
 
69
70
  return column_widths if available_chars <= 0
70
71
 
72
+ required_chars = column_widths.sum
73
+ return column_widths if required_chars < total_chars
74
+
71
75
  # [TODO] The algorithm below produces ok-ish results - but usually misses a few characters
72
76
  # that could still be assigned a column. To do this we shuld emply D'Hondt or something
73
77
  # similar.
@@ -1,5 +1,5 @@
1
1
  module Simple
2
2
  module SQL
3
- VERSION = "0.5.19"
3
+ VERSION = "0.5.20"
4
4
  end
5
5
  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.19
4
+ version: 0.5.20
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-07-09 00:00:00.000000000 Z
12
+ date: 2019-07-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pg_array_parser
@@ -210,13 +210,13 @@ files:
210
210
  - lib/simple/sql/helpers/decoder.rb
211
211
  - lib/simple/sql/helpers/encoder.rb
212
212
  - lib/simple/sql/helpers/immutable.rb
213
- - lib/simple/sql/helpers/printer.rb
214
213
  - lib/simple/sql/helpers/row_converter.rb
215
214
  - lib/simple/sql/logging.rb
216
215
  - lib/simple/sql/result.rb
217
216
  - lib/simple/sql/result/association_loader.rb
218
217
  - lib/simple/sql/result/records.rb
219
218
  - lib/simple/sql/scope/count.rb
219
+ - lib/simple/sql/table_print.rb
220
220
  - lib/simple/sql/version.rb
221
221
  - log/.gitkeep
222
222
  - scripts/stats
@@ -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.2
273
273
  signing_key:
274
274
  specification_version: 4
275
275
  summary: SQL with a simple interface