slyce 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/slyce +46 -9
  3. data/bin/slyce3 +3 -2
  4. data/slyce.gemspec +2 -1
  5. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5dcf804e2deb0adaff36f965561a0946e20ba4b0740d3a83ea064f09409f73a
4
- data.tar.gz: 8975517f3e9ac589fac7117b37c652af7b8ec463e3abbc002cc7a2e0523494c9
3
+ metadata.gz: 6a2d1af8d0c1835beb4e57d013704dc791ac769a71ed1c507b1f1a39be4b2ace
4
+ data.tar.gz: 0eb2255e8effcb0a12a72cb3dc020ebe35943f73b181f511ec865e168604b699
5
5
  SHA512:
6
- metadata.gz: 59a99719c5a7c7193753bdf34075d67db43906da64e984e629104be5d9d4906b42bb7c6bc21d62f835af56c053480c861699a589398759d4b6d0ff621a406171
7
- data.tar.gz: 89bf5f7e16919e60e836c56da62460b1ff0760e7397fe579fdc61144d1492f3b0adb15423ae000c8a0a959a0fd0012ed8fd64fd9b0f4e82301d319b25bacaa8f
6
+ metadata.gz: 3c8c2e3ae1862d9a549a38f01fc2f438d736a85ff08f6a072e18894b93a8081317fa50293f382bbadd4b64ba21f8a37cbd3b0c383f8c2e0dfdb2cf16c966c49a
7
+ data.tar.gz: d3895d08a1c90e110906f29d74fd0623e715b933c1b5de7a369a8f47d149bc955e22e79ee17ebee0209dc429db6683535baed77dc59f874a91438309b1e17922
data/bin/slyce CHANGED
@@ -1,7 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- VERSION="1.0.1"
4
-
5
3
  STDOUT.sync = true
6
4
 
7
5
  require "mysql2"
@@ -13,27 +11,42 @@ dbas = nil
13
11
  tabl = nil
14
12
 
15
13
  OptionParser.new.instance_eval do
14
+ @version = "1.1.0"
16
15
  @banner = "usage: #{program_name} [options] <database> <table>"
17
16
 
17
+ on "--csv" , "Output comma separated values"
18
+ on "--psv" , "Output pipe separated values"
19
+ on "--tsv" , "Output tab separated values"
20
+ on "-a", "--ascii" , "Convert data to ASCII using AnyAscii"
18
21
  on "-c", "--columns" , "Display column names and quit"
19
22
  on "-h", "--help" , "Show help and command usage" do Kernel.abort to_s; end
20
23
  on "-n", "--natural" , "Sort naturally, not numerically"
21
- on "-s", "--show <count>" , "Show this many values", Integer
22
- on "-v", "--version" , "Show version number" do Kernel.abort "#{program_name} #{VERSION}"; end
24
+ on "-r", "--rows <count>" , "Rows of data to select", Integer
25
+ on "-s", "--suppress" , "Suppress header when exporting delimited files"
26
+ on "-v", "--version" , "Show version number" do Kernel.abort "#{program_name} #{@version}"; end
23
27
  on "-w", "--where <cond>" , "Where clause (eg - 'age>50 and state='AZ')"
24
28
  on "-x", "--extract <col1,col2,...>", "Comma separated list of columns to extract"
25
29
 
26
30
  self
27
31
  end.parse!(into: opts={}) rescue abort($!.message)
28
32
 
29
- filt = opts[:where] and filt = "where\n #{filt}"
30
- natu = opts[:natural]
31
- show = opts[:show]
33
+ xcsv = opts[:csv]
34
+ xpsv = opts[:psv]
35
+ xtsv = opts[:tsv]
36
+ xprt = xcsv || xpsv || xtsv and require "censive"
37
+
38
+ asky = opts[:ascii ] and require "any_ascii"
39
+ filt = opts[:where ] and filt = "where\n #{filt}"
40
+ hide = opts[:suppress]
41
+ natu = opts[:natural ]
42
+ show = opts[:rows ]
32
43
  want = opts[:extract].to_s.downcase.split(",")
33
44
 
34
45
  dbas ||= ARGV.shift or abort "no database given"
35
46
  tabl ||= ARGV.shift or abort "no table given"
36
47
 
48
+ [xcsv, xpsv, xtsv].compact.size > 1 and abort "only one of csv, psv, or tsv allowed"
49
+
37
50
  # ==[ Helpers ]==
38
51
 
39
52
  class Mysql2::Client
@@ -55,8 +68,9 @@ def display(name, data, show, uniq, tots)
55
68
  puts "\n#{fill} #{name}\n#{fill} #{line}\n"
56
69
  data.each {|cnt, val| puts "%*d %s" % [wide, cnt, val || "NULL"] }
57
70
  puts "#{fill} -----\n"
58
- puts "%*d shown (top %d)" % [wide, seen, rows] if show && rows > 1
59
- puts "%*d total (all %d)" % [wide, tots, uniq]
71
+ puts "%*d shown (top %d)" % [wide, seen, rows] if show && rows > 1
72
+ puts "%*d total (all %d)" % [wide, tots, uniq] if uniq > 1
73
+ puts "%*d total" % [wide, tots ] unless uniq > 1
60
74
  end
61
75
 
62
76
  # ==[ Let 'er rip! ]==
@@ -75,6 +89,29 @@ if want.empty?
75
89
  abort "no columns are selected"
76
90
  end
77
91
 
92
+ # handle exports
93
+ if xprt
94
+ list = want.map {|item| "`#{item}`" }.join(", ")
95
+ stmt = show ? "limit #{show}" : ""
96
+ data = conn.sql(<<~"" + stmt).to_a
97
+ select
98
+ #{list}
99
+ from
100
+ `#{tabl}`
101
+ #{filt}
102
+
103
+ seps = xcsv ? "," : xtsv ? "\t" : xpsv ? "|" : abort("unknown separator #{seps.inspect}")
104
+
105
+ Censive.writer(sep: seps) do |csv|
106
+ csv << want unless hide
107
+ data.each do |row|
108
+ csv << row.map {|e| asky ? AnyAscii.transliterate(e.to_s) : e.to_s }
109
+ end
110
+ end
111
+
112
+ exit
113
+ end
114
+
78
115
  want.each do |name|
79
116
  sort = natu ? "" : "cnt desc,"
80
117
  stmt = show ? "limit #{show}" : ""
data/bin/slyce3 CHANGED
@@ -9,7 +9,7 @@
9
9
  # wget https://github.com/nalgeon/sqlean/releases/download/0.19.3/sqlean-macos-arm64.zip
10
10
  # unzip sqlean-macos-arm64.zip regexp.dylib
11
11
 
12
- VERSION="1.0.1"
12
+ VERSION="1.0.2"
13
13
 
14
14
  STDOUT.sync = true
15
15
 
@@ -69,7 +69,8 @@ def display(name, data, show, uniq, tots)
69
69
  data.each {|cnt, val| puts "%*d %s" % [wide, cnt, val || "NULL"] }
70
70
  puts "#{fill} -----\n"
71
71
  puts "%*d shown (top %d)" % [wide, seen, rows] if show and rows > 1
72
- puts "%*d total (all %d)" % [wide, tots, uniq]
72
+ puts "%*d total (all %d)" % [wide, tots, uniq] if uniq > 1
73
+ puts "%*d total" % [wide, tots ] unless uniq > 1
73
74
  end
74
75
 
75
76
  # ==[ Let 'er rip! ]==
data/slyce.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "slyce"
5
- s.version = `grep '^VERSION' bin/slyce | cut -f 2 -d '"'`
5
+ s.version = `grep -m 1 '^\s*@version' bin/slyce | cut -f 2 -d '"'`
6
6
  s.author = "Steve Shreeve"
7
7
  s.email = "steve.shreeve@gmail.com"
8
8
  s.summary =
@@ -11,6 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.license = "MIT"
12
12
  s.files = `git ls-files`.split("\n") - %w[.gitignore]
13
13
  s.executables = `cd bin && git ls-files .`.split("\n")
14
+ s.add_runtime_dependency "any_ascii", "~> 0.3.2"
14
15
  s.add_runtime_dependency "extralite-bundle", "~> 1.25"
15
16
  s.add_runtime_dependency "mysql2", "~> 0.5"
16
17
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slyce
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.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-03-13 00:00:00.000000000 Z
11
+ date: 2023-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: any_ascii
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.2
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: extralite-bundle
15
29
  requirement: !ruby/object:Gem::Requirement