slyce 1.2.7 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/slyce +23 -5
  3. data/bin/slyced +3 -3
  4. data/slyce.gemspec +1 -1
  5. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fec75a29f832be5cce086420a326344089addb6804c8c881b0608560797f8f5c
4
- data.tar.gz: 2f24983ed709549e1ef18f10e80a5417e8bd7c890f43e725abbcbe18c656232e
3
+ metadata.gz: 2ba003aec5b58e63630c2b5fc40437ecfc841e8b2c2239fea6fba2cc785687d8
4
+ data.tar.gz: 3713c8ea0c95383fad5151012553a4f22fba837925d19839bcef5abadba1b2d6
5
5
  SHA512:
6
- metadata.gz: c746ea7eeb63859b7318f9245028f530b973b997ca1de1220a2346d363307756e8ca6d879f4155719da49dd2420220e54ef34bdf225ea39dade507a49030400d
7
- data.tar.gz: 213560784f729604ce2cea20dc57b51c45775cfc8c9be273842cb0818448f9792764516dcb2ff00fc435c2de9b8f0ceccfd9153bcd7899a8043969dc21c689bb
6
+ metadata.gz: e93706e9acd8ce49b35d1c47c19cffb388ab3e77dbe1cdeff9f1e817c3b89d5b854edbafb1422951d82b4a395c63882cf6f267c4bff772597a830ea13cc98c42
7
+ data.tar.gz: cec5303f23cd5e5370c349e566f1afed2d5a7f3a6b094aede4ba7c851aeaf2ef76f58adfe1148660b3e852bfea4923ade8dab40ae73e9c656560f55a210f05d6
data/bin/slyce CHANGED
@@ -11,7 +11,7 @@ dbas = nil
11
11
  tabl = nil
12
12
 
13
13
  OptionParser.new.instance_eval do
14
- @version = "1.2.7"
14
+ @version = "1.3.1"
15
15
  @banner = "usage: #{program_name} [options] <database> <table>"
16
16
 
17
17
  on "--csv" , "Output comma separated values"
@@ -23,9 +23,10 @@ OptionParser.new.instance_eval do
23
23
  on "-n", "--natural" , "Sort naturally, not numerically"
24
24
  on "-r", "--rows <count>" , "Rows of data to show", Integer
25
25
  on "-s", "--suppress" , "Suppress header when exporting delimited files"
26
+ on "-t", "--tables" , "Display table names and quit"
26
27
  on "-v", "--version" , "Show version number" do Kernel.abort "#{program_name} #{@version}"; end
27
28
  on "-w", "--where <cond>" , "Where clause (eg - 'age>50 and state='AZ')"
28
- on "-x", "--extract <col1,col2,...>", "Comma separated list of columns to extract"
29
+ on "-x", "--extract <a,b,c...>" , "Comma separated list of columns (or tables) to extract"
29
30
 
30
31
  self
31
32
  end.parse!(into: opts={}) rescue abort($!.message)
@@ -43,7 +44,7 @@ show = opts[:rows ]
43
44
  want = opts[:extract].to_s.downcase.split(",")
44
45
 
45
46
  dbas ||= ARGV.shift or abort "no database given"
46
- tabl ||= ARGV.shift or abort "no table given"
47
+ tabl ||= ARGV.shift or opts[:tables] or !want.empty? or abort "no table given"
47
48
 
48
49
  [xcsv, xpsv, xtsv].compact.size > 1 and abort "only one of csv, psv, or tsv allowed"
49
50
 
@@ -75,6 +76,7 @@ end
75
76
 
76
77
  # ==[ Let 'er rip! ]==
77
78
 
79
+ # get database connection
78
80
  if dbas.include?("/")
79
81
  dbas = $' if dbas =~ %r|^mysql://| # drop mysql:// prefix, if present
80
82
  auth, dbas = dbas.split("/", 2)
@@ -95,7 +97,18 @@ else
95
97
  end
96
98
 
97
99
  conn = Mysql2::Client.new(**conf, as: :array)
98
- resu = conn.query("select * from `#{tabl}` limit 0")
100
+
101
+ # get table names
102
+ if tabl.nil? || opts[:tables]
103
+ resu = conn.sql("show tables")
104
+ tbls = resu.to_a.flatten
105
+ want = (want.empty? || opts[:tables]) ? tbls : want.select {|e| tbls.include?(e) }
106
+ puts want
107
+ exit
108
+ end
109
+
110
+ # get column names
111
+ resu = conn.sql("select * from `#{tabl}` limit 0")
99
112
  cols = resu.fields
100
113
  want = want.empty? ? cols : want.select {|e| cols.include?(e) }
101
114
 
@@ -121,7 +134,7 @@ if xprt
121
134
 
122
135
  seps = xcsv ? "," : xtsv ? "\t" : xpsv ? "|" : abort("unknown separator #{seps.inspect}")
123
136
 
124
- Censive.writer(sep: seps) do |csv|
137
+ Censive.write(sep: seps) do |csv|
125
138
  csv << want unless hide
126
139
  data.each do |row|
127
140
  csv << row.map {|e| asky ? AnyAscii.transliterate(e.to_s) : e.to_s }
@@ -131,6 +144,11 @@ if xprt
131
144
  exit
132
145
  end
133
146
 
147
+ # MySQL 5.7 compatible version (still need to find replacement for regexp_instr)
148
+ # -if((`#{name}` rlike '^[-+]?((0|([1-9]\\\\d*)(\\\\.\\\\d*)?)|((0|([1-9]\\\\d*))\\\\.\\\\d+))$'), `#{name}` + 0, null) desc,
149
+ # -if((`#{name}` rlike '^0\\\\d+$'), length(`#{name}`), null) desc,
150
+ # -if((`#{name}` rlike '^\\\\d'), regexp_instr(`#{name}`, '[^\\\\d]'), null) desc,
151
+
134
152
  want.each do |name|
135
153
  sort = natu ? "" : "cnt desc,"
136
154
  stmt = show ? "limit #{show}" : ""
data/bin/slyced CHANGED
@@ -11,7 +11,7 @@ dbas = nil
11
11
  tabl = nil
12
12
 
13
13
  OptionParser.new.instance_eval do
14
- @version = "1.2.7"
14
+ @version = "1.3.1"
15
15
  @banner = "usage: #{program_name} [options] <database> <table>"
16
16
 
17
17
  on "--csv" , "Output comma separated values"
@@ -25,7 +25,7 @@ OptionParser.new.instance_eval do
25
25
  on "-s", "--suppress" , "Suppress header when exporting delimited files"
26
26
  on "-v", "--version" , "Show version number" do Kernel.abort "#{program_name} #{@version}"; end
27
27
  on "-w", "--where <cond>" , "Where clause (eg - 'age>50 and state='AZ')"
28
- on "-x", "--extract <col1,col2,...>", "Comma separated list of columns to extract"
28
+ on "-x", "--extract <a,b,c...>" , "Comma separated list of columns to extract"
29
29
 
30
30
  self
31
31
  end.parse!(into: opts={}) rescue abort($!.message)
@@ -107,7 +107,7 @@ if xprt
107
107
 
108
108
  seps = xcsv ? "," : xtsv ? "\t" : xpsv ? "|" : abort("unknown separator #{seps.inspect}")
109
109
 
110
- Censive.writer(sep: seps) do |csv|
110
+ Censive.write(sep: seps) do |csv|
111
111
  csv << want unless hide
112
112
  data.each do |row|
113
113
  csv << row.map {|e| asky ? AnyAscii.transliterate(e.to_s) : e.to_s }
data/slyce.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.files = `git ls-files`.split("\n") - %w[.gitignore]
13
13
  s.executables = `cd bin && git ls-files .`.split("\n")
14
14
  s.add_runtime_dependency "any_ascii", "~> 0.3.2"
15
- s.add_runtime_dependency "censive", "~> 1.0.3"
15
+ s.add_runtime_dependency "censive", "~> 1.1.0"
16
16
  s.add_runtime_dependency "duckdb", "~> 0.8.0"
17
17
  s.add_runtime_dependency "extralite-bundle", "~> 1.25"
18
18
  s.add_runtime_dependency "mysql2", "~> 0.5"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slyce
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.7
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Shreeve
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-15 00:00:00.000000000 Z
11
+ date: 2023-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: any_ascii
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.0.3
33
+ version: 1.1.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.0.3
40
+ version: 1.1.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: duckdb
43
43
  requirement: !ruby/object:Gem::Requirement