slyce 0.5.2 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/slyce +21 -13
- 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: 057777cd908c785455b4ab4fc4c20b3aa545901bf552d0d1d568583424606103
|
4
|
+
data.tar.gz: 0cd8af51f8c809244bf308157d02adf5bcd4d0a6038acd2cb0abd73e9f609bd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10e034e61797fa5cbad886553f00ff4017e4c0a8a78d473ec2790ebe179a6d914f2194ca1d4c6283516fe39c69f8532ace24be807591431c2a52b1b202c48b78
|
7
|
+
data.tar.gz: 1115cb037df547637f2c0d3f67b41297c27e37fba4d4f12d8cfe0780c2fa962d9d75d7527a1dc232f22b30c0d5cf6ef60221b3113b08b4eae31a7a005218ef41
|
data/bin/slyce
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
STDOUT.sync = true
|
4
4
|
|
5
|
-
VERSION="0.
|
5
|
+
VERSION="0.9.1"
|
6
6
|
|
7
7
|
require "bundler/setup"
|
8
8
|
require "mysql2"
|
@@ -16,17 +16,21 @@ 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
|
22
23
|
on "-v", "--version" , "Show version number" do Kernel.abort "#{program_name} #{VERSION}"; end
|
24
|
+
on "-w", "--where <cond>" , "Filter rows (eg - 'age=33,Name=/[BW]ill/i,color=\"\"'"
|
23
25
|
on "-x", "--extract <col1,col2,...>", "Comma separated list of columns to extract"
|
24
26
|
|
25
27
|
self
|
26
28
|
end.parse!(into: opts={}) rescue abort($!.message)
|
27
29
|
|
30
|
+
abcd = opts[:alpha]
|
28
31
|
show = opts[:show]
|
29
|
-
|
32
|
+
want = opts[:extract].to_s.downcase.split(",")
|
33
|
+
filt = opts[:where] and filt = "where\n #{filt}"
|
30
34
|
|
31
35
|
dbas ||= ARGV.shift or Kernel.abort "no database given"
|
32
36
|
tabl ||= ARGV.shift or Kernel.abort "no table given"
|
@@ -35,7 +39,7 @@ tabl ||= ARGV.shift or Kernel.abort "no table given"
|
|
35
39
|
|
36
40
|
class Mysql2::Client
|
37
41
|
def query!(stmt, *args, **, &)
|
38
|
-
puts "\n==[ SQL statement ]==\n\n", stmt, ";"
|
42
|
+
puts "\n==[ SQL statement ]==\n\n", stmt.strip, ";"
|
39
43
|
query(stmt, *args, **, &)
|
40
44
|
end
|
41
45
|
end
|
@@ -50,8 +54,8 @@ def display(name, data, show, uniq, tots)
|
|
50
54
|
puts "\n#{fill} #{name}\n#{fill} #{line}\n"
|
51
55
|
data.each {|cnt, val| puts "%*d %s" % [wide, cnt, val || "NULL"] }
|
52
56
|
puts "#{fill} -----\n"
|
53
|
-
puts "%*d shown (top
|
54
|
-
puts "%*d total (all
|
57
|
+
puts "%*d shown (top %d)" % [wide, rows, rows] if show
|
58
|
+
puts "%*d total (all %d)" % [wide, tots, uniq]
|
55
59
|
end
|
56
60
|
|
57
61
|
# ==[ Let 'er rip! ]==
|
@@ -59,16 +63,15 @@ end
|
|
59
63
|
conn = Mysql2::Client.new(database: dbas, as: :array)
|
60
64
|
resu = conn.query("select * from `#{tabl}` limit 0")
|
61
65
|
cols = resu.fields
|
62
|
-
|
66
|
+
want = want.empty? ? cols : want & cols
|
63
67
|
|
64
68
|
if opts[:columns]
|
65
69
|
puts cols
|
66
70
|
exit
|
67
71
|
end
|
68
72
|
|
69
|
-
|
70
|
-
|
71
|
-
# data summary
|
73
|
+
want.each do |name|
|
74
|
+
sort = abcd ? "" : "cnt desc,"
|
72
75
|
stmt = show ? "limit #{show}" : ""
|
73
76
|
data = conn.query(<<~"" + stmt).to_a
|
74
77
|
select
|
@@ -76,23 +79,28 @@ keep.each do |name|
|
|
76
79
|
`#{name}` as val
|
77
80
|
from
|
78
81
|
`#{tabl}`
|
82
|
+
#{filt}
|
79
83
|
group by
|
80
84
|
val
|
81
|
-
order by
|
82
|
-
|
85
|
+
order by #{sort}
|
86
|
+
-if(regexp_like(`#{name}`, '^[-+]?((0|([1-9]\\\\d*)(\\\\.\\\\d*)?)|((0|([1-9]\\\\d*))\\\\.\\\\d+))$'), `#{name}` + 0, null) desc,
|
87
|
+
-if(regexp_like(`#{name}`, '^0\\\\d+$'), length(`#{name}`), null) desc,
|
88
|
+
-if(regexp_like(`#{name}`, '^\\\\d'), regexp_instr(`#{name}`, '[^\\\\d]'), null) desc,
|
89
|
+
`#{name}` is null, `#{name}`
|
83
90
|
|
84
91
|
uniq = conn.query(<<~"").to_a[0][0]
|
85
92
|
select
|
86
93
|
count(distinct(ifnull(`#{name}`,0)))
|
87
94
|
from
|
88
95
|
`#{tabl}`
|
96
|
+
#{filt}
|
89
97
|
|
90
98
|
tots = conn.query(<<~"").to_a[0][0]
|
91
99
|
select
|
92
|
-
count(`#{name}
|
100
|
+
count(ifnull(`#{name}`,0))
|
93
101
|
from
|
94
102
|
`#{tabl}`
|
103
|
+
#{filt}
|
95
104
|
|
96
105
|
display(name, data, show, uniq, tots)
|
97
|
-
|
98
106
|
end
|