slyce 0.5.1 → 0.9.0
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 +4 -4
- data/bin/slyce +16 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b35094f0096060fd354165e0c24331549ae85eb73b3568c2ee25d318b4dada2
|
4
|
+
data.tar.gz: 4354a7b22ab2ba4628e85f34b2bf7275873d044c10dd16c4a624ca31ae61fed1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4ea7f796286ed343fef00dc1401ebf8960301975fbe40414834ae84c52162344f14521b5b2aea8073ff73aaa5122514552fa6d262246d2b738e95811d9747ab
|
7
|
+
data.tar.gz: 6f6fd02773c11cf9c25b788657f452fa310d6fe997fcf3aae3a7dfb6a4fa2fe2c2896ced81f13370db8b80c1252e23cbd84bcb26b22f3c5fad71fb62151847b2
|
data/bin/slyce
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
STDOUT.sync = true
|
4
4
|
|
5
|
-
VERSION="0.
|
5
|
+
VERSION="0.9.0"
|
6
6
|
|
7
7
|
require "bundler/setup"
|
8
8
|
require "mysql2"
|
@@ -16,6 +16,7 @@ tabl = nil
|
|
16
16
|
OptionParser.new.instance_eval do
|
17
17
|
@banner = "usage: #{program_name} [options] <database> <table>"
|
18
18
|
|
19
|
+
on "-a", "--alpha" , "Sort alphabetically, not numerically"
|
19
20
|
on "-c", "--columns" , "Display column names and quit"
|
20
21
|
on "-h", "--help" , "Show help and command usage" do Kernel.abort to_s; end
|
21
22
|
on "-s", "--show <count>" , "Show this many values", Integer
|
@@ -25,8 +26,9 @@ OptionParser.new.instance_eval do
|
|
25
26
|
self
|
26
27
|
end.parse!(into: opts={}) rescue abort($!.message)
|
27
28
|
|
29
|
+
abcd = opts[:alpha]
|
28
30
|
show = opts[:show]
|
29
|
-
|
31
|
+
want = opts[:extract].to_s.downcase.split(",")
|
30
32
|
|
31
33
|
dbas ||= ARGV.shift or Kernel.abort "no database given"
|
32
34
|
tabl ||= ARGV.shift or Kernel.abort "no table given"
|
@@ -35,13 +37,14 @@ tabl ||= ARGV.shift or Kernel.abort "no table given"
|
|
35
37
|
|
36
38
|
class Mysql2::Client
|
37
39
|
def query!(stmt, *args, **, &)
|
38
|
-
puts "\n==[ SQL statement ]==\n\n", stmt, ";"
|
40
|
+
puts "\n==[ SQL statement ]==\n\n", stmt.strip, ";"
|
39
41
|
query(stmt, *args, **, &)
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
43
45
|
def display(name, data, show, uniq, tots)
|
44
46
|
seen = data.inject(0) {|seen, coun| seen += coun[0] }
|
47
|
+
rows = [data.size, seen].min
|
45
48
|
wide = tots.to_s.size
|
46
49
|
fill = " " * wide
|
47
50
|
line = "=" * name.size
|
@@ -49,7 +52,7 @@ def display(name, data, show, uniq, tots)
|
|
49
52
|
puts "\n#{fill} #{name}\n#{fill} #{line}\n"
|
50
53
|
data.each {|cnt, val| puts "%*d %s" % [wide, cnt, val || "NULL"] }
|
51
54
|
puts "#{fill} -----\n"
|
52
|
-
puts "%*d shown (top #{
|
55
|
+
puts "%*d shown (top #{rows})" % [wide, rows] if show
|
53
56
|
puts "%*d total (all #{uniq})" % [wide, tots]
|
54
57
|
end
|
55
58
|
|
@@ -58,16 +61,15 @@ end
|
|
58
61
|
conn = Mysql2::Client.new(database: dbas, as: :array)
|
59
62
|
resu = conn.query("select * from `#{tabl}` limit 0")
|
60
63
|
cols = resu.fields
|
61
|
-
|
64
|
+
want = want.empty? ? cols : want & cols
|
62
65
|
|
63
66
|
if opts[:columns]
|
64
67
|
puts cols
|
65
68
|
exit
|
66
69
|
end
|
67
70
|
|
68
|
-
|
69
|
-
|
70
|
-
# data summary
|
71
|
+
want.each do |name|
|
72
|
+
sort = abcd ? "" : "cnt desc,"
|
71
73
|
stmt = show ? "limit #{show}" : ""
|
72
74
|
data = conn.query(<<~"" + stmt).to_a
|
73
75
|
select
|
@@ -77,12 +79,15 @@ keep.each do |name|
|
|
77
79
|
`#{tabl}`
|
78
80
|
group by
|
79
81
|
val
|
80
|
-
order by
|
81
|
-
|
82
|
+
order by #{sort}
|
83
|
+
-if(regexp_like(`#{name}`, '^[-+]?((0|([1-9]\\\\d*)(\\\\.\\\\d*)?)|((0|([1-9]\\\\d*))\\\\.\\\\d+))$'), `#{name}` + 0, null) desc,
|
84
|
+
-if(regexp_like(`#{name}`, '^0\\\\d+$'), length(`#{name}`), null) desc,
|
85
|
+
-if(regexp_like(`#{name}`, '^\\\\d'), regexp_instr(`#{name}`, '[^\\\\d]'), null) desc,
|
86
|
+
`#{name}` is null, `#{name}`
|
82
87
|
|
83
88
|
uniq = conn.query(<<~"").to_a[0][0]
|
84
89
|
select
|
85
|
-
count(distinct(`#{name}
|
90
|
+
count(distinct(ifnull(`#{name}`,0)))
|
86
91
|
from
|
87
92
|
`#{tabl}`
|
88
93
|
|
@@ -93,5 +98,4 @@ keep.each do |name|
|
|
93
98
|
`#{tabl}`
|
94
99
|
|
95
100
|
display(name, data, show, uniq, tots)
|
96
|
-
|
97
101
|
end
|