slyce 1.5.1 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/bin/slyce +15 -11
  3. data/bin/slyce3 +1 -1
  4. data/bin/slyced +58 -29
  5. data/slyce.gemspec +17 -16
  6. metadata +8 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e6b0abe59bae61e2f6883c497a4aea1496cfb34bc6aaa3e98de9736c8571562
4
- data.tar.gz: 52e62601f71421927d88fddfa1aaab680c292a0bd6ff62c419d52dbd7db5fd2e
3
+ metadata.gz: '08dfbd7bd3748e0d4cd69ffe3e4fd3ccc648d6482c213471e4f6ca7152560b06'
4
+ data.tar.gz: 96d073fd13ae14bd374427e28e151c464f2d89a83a220c60796002058ab9af7e
5
5
  SHA512:
6
- metadata.gz: 15d3b6b2c9924c7d12e5b5665d699c717253b4cd85fcbb717694d86bf16d824b6a7de2f16d5990d06a3bc1e4b6fffde75019d13eacc3ab612a0eeb74a2fbf6aa
7
- data.tar.gz: cb60a335ea7143ac375eb9e9c61a3477b88976127e9af90c6f544e9dbbaecc3efdd609dfd8b22be084a049829110af6b8c2b4a9173b0495a275f5bbe5e8ab7e8
6
+ metadata.gz: 139d1ed7233ab36daa78514cb7636aac30bc7388da9be46ddaf32f3814c5b18c836a4cf52e81b5402db712e9c8476f0e69ed042bd0b79377218cd60a2870f3b8
7
+ data.tar.gz: ccb2d3e5f5fcadc7dd15a175a37e99edaa2bf38177024aa5b7aebad84adaf7d7adf84e36926d3416e51f6db5314a3c0bc8bea9457b1d2bc0d64563ee07d72e9d
data/bin/slyce CHANGED
@@ -36,7 +36,7 @@ end
36
36
  # ==[ Options ]==
37
37
 
38
38
  OptionParser.new.instance_eval do
39
- @version = "1.5.1"
39
+ @version = "1.6.0"
40
40
  @banner = "usage: #{program_name} [options] <database> <table>"
41
41
 
42
42
  on "--csv" , "Output comma separated values"
@@ -57,14 +57,6 @@ OptionParser.new.instance_eval do
57
57
  self
58
58
  end.parse!(into: opts={}) rescue abort($!.message)
59
59
 
60
- dbas = nil
61
- tabl = nil
62
-
63
- xcsv = opts[:csv]
64
- xpsv = opts[:psv]
65
- xtsv = opts[:tsv]
66
- xprt = xcsv || xpsv || xtsv and require "censive"
67
-
68
60
  asky = opts[:ascii ] and require "any_ascii"
69
61
  dump = opts[:dump ]
70
62
  want = opts[:extract ].to_s.downcase.split(",")
@@ -73,11 +65,23 @@ show = opts[:show ]
73
65
  hide = opts[:headerless]
74
66
  filt = opts[:where ] and filt = "\nwhere\n #{filt}"
75
67
 
76
- dbas ||= ARGV.shift or abort "no database given"
77
- tabl ||= ARGV.shift or opts[:tables] or !want.empty? or abort "no table given"
68
+ # ==[ Export ]==
69
+
70
+ xcsv = opts[:csv]
71
+ xpsv = opts[:psv]
72
+ xtsv = opts[:tsv]
73
+ xprt = xcsv || xpsv || xtsv and require "censive"
78
74
 
79
75
  [xcsv, xpsv, xtsv].compact.size > 1 and abort "only one of csv, psv, or tsv allowed"
80
76
 
77
+ # ==[ Source ]==
78
+
79
+ dbas = nil
80
+ tabl = nil
81
+
82
+ dbas ||= ARGV.shift or abort "no database given"
83
+ tabl ||= ARGV.shift or opts[:tables] or !want.empty? or abort "no table given"
84
+
81
85
  # ==[ Let 'er rip! ]==
82
86
 
83
87
  # get database connection
data/bin/slyce3 CHANGED
@@ -49,7 +49,7 @@ end
49
49
  # ==[ Options ]==
50
50
 
51
51
  OptionParser.new.instance_eval do
52
- @version = "1.5.1"
52
+ @version = "1.6.0"
53
53
  @banner = "usage: #{program_name} [options] <database> <table>"
54
54
 
55
55
  on "--csv" , "Output comma separated values"
data/bin/slyced CHANGED
@@ -9,8 +9,6 @@ trap("INT" ) { abort "\n" }
9
9
 
10
10
  # ==[ Helpers ]==
11
11
 
12
- DuckDB::Result.use_chunk_each = true
13
-
14
12
  class DuckDB::Connection
15
13
  alias_method :sql, :query
16
14
 
@@ -38,33 +36,26 @@ end
38
36
  # ==[ Options ]==
39
37
 
40
38
  OptionParser.new.instance_eval do
41
- @version = "1.5.1"
39
+ @version = "1.6.0"
42
40
  @banner = "usage: #{program_name} [options] <database> <table>"
43
41
 
44
- on "--csv" , "Output comma separated values"
45
- on "--psv" , "Output pipe separated values"
46
- on "--tsv" , "Output tab separated values"
47
- on "-a", "--ascii" , "Convert data to ASCII using AnyAscii"
48
- on "-c", "--columns" , "Display column names and quit"
49
- on "-h", "--help" , "Show help and command usage" do Kernel.abort to_s; end
50
- on "-H", "--headerless" , "Do not show headers when exporting delimited files"
51
- on "-n", "--natural" , "Sort naturally, not numerically"
52
- on "-s", "--show <count>" , "Show this many values", Integer
53
- on "-v", "--version" , "Show version number" do Kernel.abort "#{program_name} #{@version}"; end
54
- on "-w", "--where <cond>" , "Where clause (eg - 'age>50 and state='AZ')"
55
- on "-x", "--extract <a,b,c...>" , "Comma separated list of columns to extract"
42
+ on "--csv" , "Output comma separated values"
43
+ on "--psv" , "Output pipe separated values"
44
+ on "--tsv" , "Output tab separated values"
45
+ on "-a", "--ascii" , "Convert data to ASCII using AnyAscii"
46
+ on "-c", "--columns" , "Display column names and quit"
47
+ on "-h", "--help" , "Show help and command usage" do Kernel.abort to_s; end
48
+ on "-H", "--headerless" , "Do not show headers when exporting delimited files"
49
+ on "-n", "--natural" , "Sort naturally, not numerically"
50
+ on "-s", "--show <count>" , "Show this many values", Integer
51
+ on "-t", "--tables" , "Display table names and quit"
52
+ on "-v", "--version" , "Show version number" do Kernel.abort "#{program_name} #{@version}"; end
53
+ on "-w", "--where <cond>" , "Where clause (eg - 'age>50 and state='AZ')"
54
+ on "-x", "--extract <a,b,c...>", "Comma separated list of columns or tables to extract"
56
55
 
57
56
  self
58
57
  end.parse!(into: opts={}) rescue abort($!.message)
59
58
 
60
- dbas = nil
61
- tabl = nil
62
-
63
- xcsv = opts[:csv]
64
- xpsv = opts[:psv]
65
- xtsv = opts[:tsv]
66
- xprt = xcsv || xpsv || xtsv and require "censive"
67
-
68
59
  asky = opts[:ascii ] and require "any_ascii"
69
60
  want = opts[:extract ].to_s.downcase.split(",")
70
61
  natu = opts[:natural ]
@@ -72,14 +63,51 @@ show = opts[:show ]
72
63
  hide = opts[:headerless]
73
64
  filt = opts[:where ] and filt = "\nwhere\n #{filt}"
74
65
 
75
- dbas ||= ARGV.shift or abort "no database given"
76
- tabl ||= ARGV.shift or abort "no table given"
66
+ # ==[ Export ]==
67
+
68
+ xcsv = opts[:csv]
69
+ xpsv = opts[:psv]
70
+ xtsv = opts[:tsv]
71
+ xprt = xcsv || xpsv || xtsv and require "censive"
77
72
 
78
73
  [xcsv, xpsv, xtsv].compact.size > 1 and abort "only one of csv, psv, or tsv allowed"
79
74
 
75
+ # ==[ Source ]==
76
+
77
+ file = '/dev/stdin'
78
+ dbas = ':memory:'
79
+ tabl = '_memory_'
80
+
81
+ if ARGV.size == 1
82
+ if opts[:tables]
83
+ dbas = ARGV.shift
84
+ else
85
+ file = ARGV.shift
86
+ File.readable?(file) or abort "#{file.inspect} is unreadable"
87
+ end
88
+ elsif ARGV.size > 1
89
+ dbas = ARGV.shift
90
+ tabl = ARGV.shift
91
+ end
92
+
80
93
  # ==[ Let 'er rip! ]==
81
94
 
82
95
  conn = DuckDB::Database.open(dbas).connect
96
+
97
+ if dbas && opts[:tables]
98
+ resu = conn.sql("show tables")
99
+ tbls = resu.to_a.flatten
100
+ want = want.empty? ? tbls : want & tbls
101
+ puts want
102
+ exit
103
+ end
104
+
105
+ conn.sql(<<~end) if file rescue exit
106
+ create temporary table "#{tabl}" as
107
+ select *
108
+ from read_csv("#{file}", all_varchar=true)
109
+ end
110
+
83
111
  resu = conn.sql(<<~end)
84
112
  select column_name
85
113
  from information_schema.columns
@@ -116,6 +144,7 @@ if xprt
116
144
  csv << want unless hide
117
145
  data.each do |row|
118
146
  csv << row.map {|e| asky ? AnyAscii.transliterate(e.to_s) : e.to_s }
147
+ # csv << row.map {|e| asky ? AnyAscii.transliterate(e.to_s) : e.nil? ? nil : e.to_s }
119
148
  end
120
149
  end
121
150
 
@@ -127,8 +156,8 @@ want.each do |name|
127
156
  limt = show ? "limit #{show}" : ""
128
157
  like = <<~"".gsub(/(.)^/m, '\1 ').rstrip
129
158
  if(regexp_matches("#{name}", '^[-+]?((0|([1-9]\\d*)(\\.\\d*)?)|((0|([1-9]\\d*))\\.\\d+))$'),cast("#{name}" as double),null) nulls last,
130
- if(regexp_matches("#{name}", '^0\\d*$'),length("#{name}"),null) nulls last,
131
- if(regexp_matches("#{name}", '^\\d+\\D'),length(regexp_extract("#{name}",'^(\\d+)',1)),null) nulls last,
159
+ if(regexp_matches("#{name}", '^0\\d*$'),length("#{name}"),null) nulls last,
160
+ if(regexp_matches("#{name}", '^\\d+\\D'),length(regexp_extract("#{name}",'^(\\d+)',1)),null) nulls last,
132
161
 
133
162
  data = conn.sql(<<~"".rstrip).to_a
134
163
  select
@@ -145,8 +174,8 @@ want.each do |name|
145
174
 
146
175
  uniq, tots = conn.sql(<<~"".rstrip).to_a[0]
147
176
  select
148
- count(distinct(ifnull("#{name}",0))),
149
- count(ifnull("#{name}",0))
177
+ count(distinct(ifnull("#{name}",''))),
178
+ count(ifnull("#{name}",''))
150
179
  from
151
180
  "#{tabl}"
152
181
  #{filt}
data/slyce.gemspec CHANGED
@@ -1,19 +1,20 @@
1
1
  # encoding: utf-8
2
2
 
3
- Gem::Specification.new do |s|
4
- s.name = "slyce"
5
- s.version = `grep -m 1 '^\s*@version' bin/slyce | cut -f 2 -d '"'`
6
- s.author = "Steve Shreeve"
7
- s.email = "steve.shreeve@gmail.com"
8
- s.summary =
9
- s.description = "Ruby utility to show data statistics for MySQL databases"
10
- s.homepage = "https://github.com/shreeve/slyce"
11
- s.license = "MIT"
12
- s.files = `git ls-files`.split("\n") - %w[.gitignore]
13
- s.executables = `cd bin && git ls-files .`.split("\n")
14
- s.add_runtime_dependency "any_ascii", "~> 0.3.2"
15
- s.add_runtime_dependency "censive", "~> 1.1.0"
16
- s.add_runtime_dependency "duckdb", "~> 0.8.1"
17
- s.add_runtime_dependency "extralite-bundle", "~> 2.1"
18
- s.add_runtime_dependency "mysql2", "~> 0.5"
3
+ Gem::Specification.new do |gem|
4
+ gem.name = "slyce"
5
+ gem.version = `grep -m 1 '^\s*@version' bin/slyce | cut -f 2 -d '"'`
6
+ gem.author = "Steve Shreeve"
7
+ gem.email = "steve.shreeve@gmail.com"
8
+ gem.summary = "A " +
9
+ gem.description = "Ruby utility to show statistics for databases or csv files"
10
+ gem.homepage = "https://github.com/shreeve/slyce"
11
+ gem.license = "MIT"
12
+ gem.files = `git ls-files`.split("\n") - %w[.gitignore]
13
+ gem.executables = `cd bin && git ls-files .`.split("\n")
14
+ gem.required_ruby_version = Gem::Requirement.new(">= 3.0") if gem.respond_to? :required_ruby_version=
15
+ gem.add_runtime_dependency "any_ascii", "~> 0.3.2"
16
+ gem.add_runtime_dependency "censive", "~> 1.1.0"
17
+ gem.add_runtime_dependency "duckdb", "~> 1.1.2"
18
+ gem.add_runtime_dependency "extralite-bundle", "~> 2.1"
19
+ gem.add_runtime_dependency "mysql2", "~> 0.5"
19
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slyce
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Shreeve
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-18 00:00:00.000000000 Z
11
+ date: 2024-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: any_ascii
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.8.1
47
+ version: 1.1.2
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.8.1
54
+ version: 1.1.2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: extralite-bundle
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.5'
83
- description: Ruby utility to show data statistics for MySQL databases
83
+ description: Ruby utility to show statistics for databases or csv files
84
84
  email: steve.shreeve@gmail.com
85
85
  executables:
86
86
  - slyce
@@ -108,15 +108,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - ">="
110
110
  - !ruby/object:Gem::Version
111
- version: '0'
111
+ version: '3.0'
112
112
  required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - ">="
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
117
  requirements: []
118
- rubygems_version: 3.4.20
118
+ rubygems_version: 3.5.22
119
119
  signing_key:
120
120
  specification_version: 4
121
- summary: Ruby utility to show data statistics for MySQL databases
121
+ summary: A Ruby utility to show statistics for databases or csv files
122
122
  test_files: []