slyce 0.5.2 → 0.9.0

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 +13 -10
  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: 5b35094f0096060fd354165e0c24331549ae85eb73b3568c2ee25d318b4dada2
4
+ data.tar.gz: 4354a7b22ab2ba4628e85f34b2bf7275873d044c10dd16c4a624ca31ae61fed1
5
5
  SHA512:
6
- metadata.gz: e4bd3c648d559ee5f0d7395c09e0836f3d309a1a99729f9d5fdd0d1441ccd8954dc0275e13b0de35d471a51f3c7b64bcfefa6cf0120c53a3ad2b9eef92e09d76
7
- data.tar.gz: f2100f83caa2d1b116b0cc934841ce450208dc38dcf370242a788b563feb6ac84a4499e24a691e210425eca4c7102daaa1f4a45833e05617120b9de7b9d41cdf
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.2"
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
- keep = opts[:extract].to_s.downcase.split(",")
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,7 +37,7 @@ 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
@@ -59,16 +61,15 @@ end
59
61
  conn = Mysql2::Client.new(database: dbas, as: :array)
60
62
  resu = conn.query("select * from `#{tabl}` limit 0")
61
63
  cols = resu.fields
62
- keep = keep.empty? ? cols : keep & cols
64
+ want = want.empty? ? cols : want & cols
63
65
 
64
66
  if opts[:columns]
65
67
  puts cols
66
68
  exit
67
69
  end
68
70
 
69
- keep.each do |name|
70
-
71
- # data summary
71
+ want.each do |name|
72
+ sort = abcd ? "" : "cnt desc,"
72
73
  stmt = show ? "limit #{show}" : ""
73
74
  data = conn.query(<<~"" + stmt).to_a
74
75
  select
@@ -78,8 +79,11 @@ keep.each do |name|
78
79
  `#{tabl}`
79
80
  group by
80
81
  val
81
- order by
82
- cnt desc
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}`
83
87
 
84
88
  uniq = conn.query(<<~"").to_a[0][0]
85
89
  select
@@ -94,5 +98,4 @@ keep.each do |name|
94
98
  `#{tabl}`
95
99
 
96
100
  display(name, data, show, uniq, tots)
97
-
98
101
  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.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Shreeve