slyce 1.3.0 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/slyce +39 -4
  3. data/bin/slyced +2 -2
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1327a9e50802b5e802b1be542681b0c7d051d13e2fd354f20dd12a28b46c14c0
4
- data.tar.gz: cf79a752ce4346d7a0d3a5756ec564e92b512ad454d7e567c89757575c0d334e
3
+ metadata.gz: d593f1fb756c6af9643dfa496027cb39cd85451f351d3dd2541cbfa340b1c7b3
4
+ data.tar.gz: 13753300c5bbebb1b40998bc1cb1c9397b0a2c9ab2691fb9a21f0de1252c3b68
5
5
  SHA512:
6
- metadata.gz: eeaf579fd814d9db6c1120ec2cab9291acad26a14d8c30bbca3585c173b05909e25812c84af2f3524586baba162e0c71429300aff49d5a912444c96a8dbf4fc7
7
- data.tar.gz: abfcf38eeac61002eefe660ff95fabfeadf7439aa60beb33908ac95c2bbd1b1375ceeeb954b4bdaa08a4687a5b2f8f4b316757e9fb78e8fd27a79723277124a4
6
+ metadata.gz: d11b2bad746f523480a8bdcc8659f64e381e63803cabfe4311741f3fe7f40129bfcd65dc1374ef77842c3f4bb2896d4280c2eb4697e1ff66a8c6f04f45d78657
7
+ data.tar.gz: 8da310dc995ca7b73439081666e9e6c62bc56fb9be8e06f8076976ee624923058a2f867f8a326a13c0e76c99391677d670f70cc482117fcc71b634812e5780d2
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.3.0"
14
+ @version = "1.3.2"
15
15
  @banner = "usage: #{program_name} [options] <database> <table>"
16
16
 
17
17
  on "--csv" , "Output comma separated values"
@@ -19,13 +19,15 @@ OptionParser.new.instance_eval do
19
19
  on "--tsv" , "Output tab separated values"
20
20
  on "-a", "--ascii" , "Convert data to ASCII using AnyAscii"
21
21
  on "-c", "--columns" , "Display column names and quit"
22
+ on "-d", "--dump" , "Display table schema and quit"
22
23
  on "-h", "--help" , "Show help and command usage" do Kernel.abort to_s; end
23
24
  on "-n", "--natural" , "Sort naturally, not numerically"
24
25
  on "-r", "--rows <count>" , "Rows of data to show", Integer
25
26
  on "-s", "--suppress" , "Suppress header when exporting delimited files"
27
+ on "-t", "--tables" , "Display table names and quit"
26
28
  on "-v", "--version" , "Show version number" do Kernel.abort "#{program_name} #{@version}"; end
27
29
  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"
30
+ on "-x", "--extract <a,b,c...>" , "Comma separated list of columns (or tables) to extract"
29
31
 
30
32
  self
31
33
  end.parse!(into: opts={}) rescue abort($!.message)
@@ -43,7 +45,7 @@ show = opts[:rows ]
43
45
  want = opts[:extract].to_s.downcase.split(",")
44
46
 
45
47
  dbas ||= ARGV.shift or abort "no database given"
46
- tabl ||= ARGV.shift or abort "no table given"
48
+ tabl ||= ARGV.shift or opts[:tables] or !want.empty? or abort "no table given"
47
49
 
48
50
  [xcsv, xpsv, xtsv].compact.size > 1 and abort "only one of csv, psv, or tsv allowed"
49
51
 
@@ -75,6 +77,7 @@ end
75
77
 
76
78
  # ==[ Let 'er rip! ]==
77
79
 
80
+ # get database connection
78
81
  if dbas.include?("/")
79
82
  dbas = $' if dbas =~ %r|^mysql://| # drop mysql:// prefix, if present
80
83
  auth, dbas = dbas.split("/", 2)
@@ -95,7 +98,39 @@ else
95
98
  end
96
99
 
97
100
  conn = Mysql2::Client.new(**conf, as: :array)
98
- resu = conn.query("select * from `#{tabl}` limit 0")
101
+
102
+ # get table names
103
+ if tabl.nil? || opts[:dump] || opts[:tables]
104
+ resu = conn.sql("show tables")
105
+ tbls = resu.to_a.flatten
106
+ want = (want.empty? || opts[:tables]) ? tbls : want.select {|e| tbls.include?(e) }
107
+
108
+ #!# FIXME: this code is a mess... cleanup soon
109
+
110
+ if opts[:dump]
111
+ pict = "%Y-%m-%dT%H:%M:%S%z"
112
+ puts "-- Dump of `#{dbas}` database on #{Time.now.strftime(pict)}\n\n"
113
+ puts "set foreign_key_checks=0;\n\n" unless want.empty?
114
+ tail = []
115
+ want.each do |name|
116
+ text = conn.sql("show create table `#{name}`").to_a.flatten[1] + ";\n\n"
117
+ if text =~ /^create table/i
118
+ puts text
119
+ elsif text.gsub!(/^(create ).*?(?=view)/i, '\1')
120
+ tail << text
121
+ end
122
+ end
123
+ puts tail.join unless tail.empty?
124
+ puts "set foreign_key_checks=1;\n\n" unless want.empty?
125
+ exit
126
+ end
127
+
128
+ puts want
129
+ exit
130
+ end
131
+
132
+ # get column names
133
+ resu = conn.sql("select * from `#{tabl}` limit 0")
99
134
  cols = resu.fields
100
135
  want = want.empty? ? cols : want.select {|e| cols.include?(e) }
101
136
 
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.3.0"
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)
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.3.0
4
+ version: 1.3.2
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-28 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