slyce 0.9.1 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/slyce +14 -11
- data/bin/slyce3 +114 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81d5ddf505bb1b8f75770447e2c6015a3cf2c1ce2003b543cbce2c3364b8c9cf
|
4
|
+
data.tar.gz: 2b4ae78ed3f654619e9b2d01e1d50a2cdc561f0e541416cb8739400fa8980e1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90657cc538cfaff2540321d9fe3862593d1136820ca02a5c604d5994c495f5d91164554a1de2b142b131dca37309423cda926ed4abb12a6a941d93a3ff6c2f7c
|
7
|
+
data.tar.gz: 59eb8d3217d38f71972dff57fcf331746a866c8fa5c5cda60d69eeb96de7bb778aa8ac0e3b6d013f6d59e0bbcebfe03191423a244fc97654df7359f6e0665291
|
data/bin/slyce
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
3
|
+
VERSION="0.9.5"
|
4
4
|
|
5
|
-
|
5
|
+
STDOUT.sync = true
|
6
6
|
|
7
|
-
require "bundler/setup"
|
8
7
|
require "mysql2"
|
9
8
|
require "optparse"
|
10
9
|
|
@@ -28,19 +27,23 @@ OptionParser.new.instance_eval do
|
|
28
27
|
end.parse!(into: opts={}) rescue abort($!.message)
|
29
28
|
|
30
29
|
abcd = opts[:alpha]
|
30
|
+
filt = opts[:where] and filt = "where\n #{filt}"
|
31
31
|
show = opts[:show]
|
32
32
|
want = opts[:extract].to_s.downcase.split(",")
|
33
|
-
filt = opts[:where] and filt = "where\n #{filt}"
|
34
33
|
|
35
|
-
dbas ||= ARGV.shift or
|
36
|
-
tabl ||= ARGV.shift or
|
34
|
+
dbas ||= ARGV.shift or abort "no database given"
|
35
|
+
tabl ||= ARGV.shift or abort "no table given"
|
37
36
|
|
38
37
|
# ==[ Helpers ]==
|
39
38
|
|
40
39
|
class Mysql2::Client
|
41
|
-
def
|
40
|
+
def sql(...)
|
41
|
+
query(...)
|
42
|
+
end
|
43
|
+
|
44
|
+
def sql!(stmt, *args, **, &)
|
42
45
|
puts "\n==[ SQL statement ]==\n\n", stmt.strip, ";"
|
43
|
-
|
46
|
+
sql(stmt, *args, **, &)
|
44
47
|
end
|
45
48
|
end
|
46
49
|
|
@@ -73,7 +76,7 @@ end
|
|
73
76
|
want.each do |name|
|
74
77
|
sort = abcd ? "" : "cnt desc,"
|
75
78
|
stmt = show ? "limit #{show}" : ""
|
76
|
-
data = conn.
|
79
|
+
data = conn.sql(<<~"" + stmt).to_a
|
77
80
|
select
|
78
81
|
count(*) as cnt,
|
79
82
|
`#{name}` as val
|
@@ -88,14 +91,14 @@ want.each do |name|
|
|
88
91
|
-if(regexp_like(`#{name}`, '^\\\\d'), regexp_instr(`#{name}`, '[^\\\\d]'), null) desc,
|
89
92
|
`#{name}` is null, `#{name}`
|
90
93
|
|
91
|
-
uniq = conn.
|
94
|
+
uniq = conn.sql(<<~"").to_a[0][0]
|
92
95
|
select
|
93
96
|
count(distinct(ifnull(`#{name}`,0)))
|
94
97
|
from
|
95
98
|
`#{tabl}`
|
96
99
|
#{filt}
|
97
100
|
|
98
|
-
tots = conn.
|
101
|
+
tots = conn.sql(<<~"").to_a[0][0]
|
99
102
|
select
|
100
103
|
count(ifnull(`#{name}`,0))
|
101
104
|
from
|
data/bin/slyce3
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# NOTE: Requires the 'regexp' sqlite3 extension from https://github.com/nalgeon/sqlean
|
4
|
+
|
5
|
+
VERSION="0.9.5"
|
6
|
+
|
7
|
+
STDOUT.sync = true
|
8
|
+
|
9
|
+
require "extralite"
|
10
|
+
require "optparse"
|
11
|
+
|
12
|
+
trap("INT" ) { abort "\n" }
|
13
|
+
|
14
|
+
dbas = nil
|
15
|
+
tabl = nil
|
16
|
+
|
17
|
+
OptionParser.new.instance_eval do
|
18
|
+
@banner = "usage: #{program_name} [options] <database> <table>"
|
19
|
+
|
20
|
+
on "-a", "--alpha" , "Sort alphabetically, not numerically"
|
21
|
+
on "-c", "--columns" , "Display column names and quit"
|
22
|
+
on "-h", "--help" , "Show help and command usage" do Kernel.abort to_s; end
|
23
|
+
on "-r", "--regexp <path>" , "Path to the sqlean/regexp extension"
|
24
|
+
on "-s", "--show <count>" , "Show this many values", Integer
|
25
|
+
on "-v", "--version" , "Show version number" do Kernel.abort "#{program_name} #{VERSION}"; end
|
26
|
+
on "-w", "--where <cond>" , "Filter rows (eg - 'age=33,Name=/[BW]ill/i,color=\"\"'"
|
27
|
+
on "-x", "--extract <col1,col2,...>", "Comma separated list of columns to extract"
|
28
|
+
|
29
|
+
self
|
30
|
+
end.parse!(into: opts={regexp: "regexp"}) rescue abort($!.message)
|
31
|
+
|
32
|
+
abcd = opts[:alpha]
|
33
|
+
filt = opts[:where] and filt = "where\n #{filt}"
|
34
|
+
regx = opts[:regexp]; File.exist?(regx) or abort "no regexp extension found at '#{regx}'"
|
35
|
+
show = opts[:show]
|
36
|
+
want = opts[:extract].to_s.downcase.split(",")
|
37
|
+
|
38
|
+
dbas ||= ARGV.shift or abort "no database given"
|
39
|
+
tabl ||= ARGV.shift or abort "no table given"
|
40
|
+
|
41
|
+
# ==[ Helpers ]==
|
42
|
+
|
43
|
+
class Extralite::Database
|
44
|
+
def sql(...)
|
45
|
+
query_ary(...)
|
46
|
+
end
|
47
|
+
|
48
|
+
def sql!(stmt, *args, **, &)
|
49
|
+
puts "\n==[ SQL statement ]==\n\n", stmt.strip, ";"
|
50
|
+
sql(stmt, *args, **, &)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def display(name, data, show, uniq, tots)
|
55
|
+
seen = data.inject(0) {|seen, coun| seen += coun[0] }
|
56
|
+
rows = [data.size, seen].min
|
57
|
+
wide = tots.to_s.size
|
58
|
+
fill = " " * wide
|
59
|
+
line = "=" * name.size
|
60
|
+
|
61
|
+
puts "\n#{fill} #{name}\n#{fill} #{line}\n"
|
62
|
+
data.each {|cnt, val| puts "%*d %s" % [wide, cnt, val || "NULL"] }
|
63
|
+
puts "#{fill} -----\n"
|
64
|
+
puts "%*d shown (top %d)" % [wide, rows, rows] if show
|
65
|
+
puts "%*d total (all %d)" % [wide, tots, uniq]
|
66
|
+
end
|
67
|
+
|
68
|
+
# ==[ Let 'er rip! ]==
|
69
|
+
|
70
|
+
conn = Extralite::Database.new(dbas)
|
71
|
+
resu = conn.load_extension(regx)
|
72
|
+
cols = conn.columns("select * from `#{tabl}` limit 0").map(&:to_s)
|
73
|
+
want = want.empty? ? cols : want & cols
|
74
|
+
|
75
|
+
if opts[:columns]
|
76
|
+
puts cols
|
77
|
+
exit
|
78
|
+
end
|
79
|
+
|
80
|
+
want.each do |name|
|
81
|
+
sort = abcd ? "" : "cnt desc,"
|
82
|
+
stmt = show ? "limit #{show}" : ""
|
83
|
+
data = conn.sql(<<~"" + stmt).to_a
|
84
|
+
select
|
85
|
+
count(*) as cnt,
|
86
|
+
`#{name}` as val
|
87
|
+
from
|
88
|
+
`#{tabl}`
|
89
|
+
#{filt}
|
90
|
+
group by
|
91
|
+
val
|
92
|
+
order by #{sort}
|
93
|
+
-iif(regexp_like(`#{name}`, '^[-+]?((0|([1-9]\\d*)(\\.\\d*)?)|((0|([1-9]\\d*))\\.\\d+))$'), `#{name}` + 0, null) desc,
|
94
|
+
-iif(regexp_like(`#{name}`, '^0\\d+$'), length(`#{name}`), null) desc,
|
95
|
+
-iif(regexp_like(`#{name}`, '^\\d'), length(regexp_substr(`#{name}`, '^\\d+')), null) desc,
|
96
|
+
`#{name}` is null, `#{name}`
|
97
|
+
collate nocase
|
98
|
+
|
99
|
+
uniq = conn.sql(<<~"").to_a[0][0]
|
100
|
+
select
|
101
|
+
count(distinct(ifnull(`#{name}`,0)))
|
102
|
+
from
|
103
|
+
`#{tabl}`
|
104
|
+
#{filt}
|
105
|
+
|
106
|
+
tots = conn.sql(<<~"").to_a[0][0]
|
107
|
+
select
|
108
|
+
count(ifnull(`#{name}`,0))
|
109
|
+
from
|
110
|
+
`#{tabl}`
|
111
|
+
#{filt}
|
112
|
+
|
113
|
+
display(name, data, show, uniq, tots)
|
114
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slyce
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Shreeve
|
@@ -28,6 +28,7 @@ description: Ruby utility to show data statistics for MySQL databases
|
|
28
28
|
email: steve.shreeve@gmail.com
|
29
29
|
executables:
|
30
30
|
- slyce
|
31
|
+
- slyce3
|
31
32
|
extensions: []
|
32
33
|
extra_rdoc_files: []
|
33
34
|
files:
|
@@ -35,6 +36,7 @@ files:
|
|
35
36
|
- LICENSE
|
36
37
|
- README.md
|
37
38
|
- bin/slyce
|
39
|
+
- bin/slyce3
|
38
40
|
- slyce.gemspec
|
39
41
|
homepage: https://github.com/shreeve/slyce
|
40
42
|
licenses:
|