slyce 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/slyce +43 -7
- data/slyce.gemspec +2 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a2d1af8d0c1835beb4e57d013704dc791ac769a71ed1c507b1f1a39be4b2ace
|
4
|
+
data.tar.gz: 0eb2255e8effcb0a12a72cb3dc020ebe35943f73b181f511ec865e168604b699
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c8c2e3ae1862d9a549a38f01fc2f438d736a85ff08f6a072e18894b93a8081317fa50293f382bbadd4b64ba21f8a37cbd3b0c383f8c2e0dfdb2cf16c966c49a
|
7
|
+
data.tar.gz: d3895d08a1c90e110906f29d74fd0623e715b933c1b5de7a369a8f47d149bc955e22e79ee17ebee0209dc429db6683535baed77dc59f874a91438309b1e17922
|
data/bin/slyce
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
VERSION="1.0.2"
|
4
|
-
|
5
3
|
STDOUT.sync = true
|
6
4
|
|
7
5
|
require "mysql2"
|
@@ -13,27 +11,42 @@ dbas = nil
|
|
13
11
|
tabl = nil
|
14
12
|
|
15
13
|
OptionParser.new.instance_eval do
|
14
|
+
@version = "1.1.0"
|
16
15
|
@banner = "usage: #{program_name} [options] <database> <table>"
|
17
16
|
|
17
|
+
on "--csv" , "Output comma separated values"
|
18
|
+
on "--psv" , "Output pipe separated values"
|
19
|
+
on "--tsv" , "Output tab separated values"
|
20
|
+
on "-a", "--ascii" , "Convert data to ASCII using AnyAscii"
|
18
21
|
on "-c", "--columns" , "Display column names and quit"
|
19
22
|
on "-h", "--help" , "Show help and command usage" do Kernel.abort to_s; end
|
20
23
|
on "-n", "--natural" , "Sort naturally, not numerically"
|
21
|
-
on "-
|
22
|
-
on "-
|
24
|
+
on "-r", "--rows <count>" , "Rows of data to select", Integer
|
25
|
+
on "-s", "--suppress" , "Suppress header when exporting delimited files"
|
26
|
+
on "-v", "--version" , "Show version number" do Kernel.abort "#{program_name} #{@version}"; end
|
23
27
|
on "-w", "--where <cond>" , "Where clause (eg - 'age>50 and state='AZ')"
|
24
28
|
on "-x", "--extract <col1,col2,...>", "Comma separated list of columns to extract"
|
25
29
|
|
26
30
|
self
|
27
31
|
end.parse!(into: opts={}) rescue abort($!.message)
|
28
32
|
|
29
|
-
|
30
|
-
|
31
|
-
|
33
|
+
xcsv = opts[:csv]
|
34
|
+
xpsv = opts[:psv]
|
35
|
+
xtsv = opts[:tsv]
|
36
|
+
xprt = xcsv || xpsv || xtsv and require "censive"
|
37
|
+
|
38
|
+
asky = opts[:ascii ] and require "any_ascii"
|
39
|
+
filt = opts[:where ] and filt = "where\n #{filt}"
|
40
|
+
hide = opts[:suppress]
|
41
|
+
natu = opts[:natural ]
|
42
|
+
show = opts[:rows ]
|
32
43
|
want = opts[:extract].to_s.downcase.split(",")
|
33
44
|
|
34
45
|
dbas ||= ARGV.shift or abort "no database given"
|
35
46
|
tabl ||= ARGV.shift or abort "no table given"
|
36
47
|
|
48
|
+
[xcsv, xpsv, xtsv].compact.size > 1 and abort "only one of csv, psv, or tsv allowed"
|
49
|
+
|
37
50
|
# ==[ Helpers ]==
|
38
51
|
|
39
52
|
class Mysql2::Client
|
@@ -76,6 +89,29 @@ if want.empty?
|
|
76
89
|
abort "no columns are selected"
|
77
90
|
end
|
78
91
|
|
92
|
+
# handle exports
|
93
|
+
if xprt
|
94
|
+
list = want.map {|item| "`#{item}`" }.join(", ")
|
95
|
+
stmt = show ? "limit #{show}" : ""
|
96
|
+
data = conn.sql(<<~"" + stmt).to_a
|
97
|
+
select
|
98
|
+
#{list}
|
99
|
+
from
|
100
|
+
`#{tabl}`
|
101
|
+
#{filt}
|
102
|
+
|
103
|
+
seps = xcsv ? "," : xtsv ? "\t" : xpsv ? "|" : abort("unknown separator #{seps.inspect}")
|
104
|
+
|
105
|
+
Censive.writer(sep: seps) do |csv|
|
106
|
+
csv << want unless hide
|
107
|
+
data.each do |row|
|
108
|
+
csv << row.map {|e| asky ? AnyAscii.transliterate(e.to_s) : e.to_s }
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
exit
|
113
|
+
end
|
114
|
+
|
79
115
|
want.each do |name|
|
80
116
|
sort = natu ? "" : "cnt desc,"
|
81
117
|
stmt = show ? "limit #{show}" : ""
|
data/slyce.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "slyce"
|
5
|
-
s.version = `grep '
|
5
|
+
s.version = `grep -m 1 '^\s*@version' bin/slyce | cut -f 2 -d '"'`
|
6
6
|
s.author = "Steve Shreeve"
|
7
7
|
s.email = "steve.shreeve@gmail.com"
|
8
8
|
s.summary =
|
@@ -11,6 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.license = "MIT"
|
12
12
|
s.files = `git ls-files`.split("\n") - %w[.gitignore]
|
13
13
|
s.executables = `cd bin && git ls-files .`.split("\n")
|
14
|
+
s.add_runtime_dependency "any_ascii", "~> 0.3.2"
|
14
15
|
s.add_runtime_dependency "extralite-bundle", "~> 1.25"
|
15
16
|
s.add_runtime_dependency "mysql2", "~> 0.5"
|
16
17
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slyce
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
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-03-
|
11
|
+
date: 2023-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: any_ascii
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.3.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.3.2
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: extralite-bundle
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|