slyce 0.5.2 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/slyce +21 -13
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86b46697d15f638424f3369939a12f962a5daa1a9614bb1cf98cb34c8b8d2519
4
- data.tar.gz: 9361896529ecaf43baef50da66e2cf41600cc42a110b3af5b97bc53e81270ef5
3
+ metadata.gz: 057777cd908c785455b4ab4fc4c20b3aa545901bf552d0d1d568583424606103
4
+ data.tar.gz: 0cd8af51f8c809244bf308157d02adf5bcd4d0a6038acd2cb0abd73e9f609bd3
5
5
  SHA512:
6
- metadata.gz: e4bd3c648d559ee5f0d7395c09e0836f3d309a1a99729f9d5fdd0d1441ccd8954dc0275e13b0de35d471a51f3c7b64bcfefa6cf0120c53a3ad2b9eef92e09d76
7
- data.tar.gz: f2100f83caa2d1b116b0cc934841ce450208dc38dcf370242a788b563feb6ac84a4499e24a691e210425eca4c7102daaa1f4a45833e05617120b9de7b9d41cdf
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.2"
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
- keep = opts[:extract].to_s.downcase.split(",")
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 #{rows})" % [wide, rows] if show
54
- puts "%*d total (all #{uniq})" % [wide, tots]
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
- keep = keep.empty? ? cols : keep & cols
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
- keep.each do |name|
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
- cnt desc
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
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.5.2
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Shreeve