slyce 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/slyce +9 -9
  3. data/bin/slyce3 +46 -10
  4. data/bin/slyced +9 -9
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8350b63046aa4e84fd9f04bd73ed92140ec3b569ac6c997f53f74e2235ec685
4
- data.tar.gz: 34ee0a6665542b55df24b55d22150017610f1fdb891860e95b33b8ab30b03eaa
3
+ metadata.gz: 6e6b0abe59bae61e2f6883c497a4aea1496cfb34bc6aaa3e98de9736c8571562
4
+ data.tar.gz: 52e62601f71421927d88fddfa1aaab680c292a0bd6ff62c419d52dbd7db5fd2e
5
5
  SHA512:
6
- metadata.gz: c405dc17703ea8c99617183ef95185deb3703c98ab029106ac87a6e5ea2e3af833c3a6534e99960892de2cd6c6e69ebd2a3653e3c38d93c9c7fc60839df353bd
7
- data.tar.gz: 25273ba52a3fec83f83da1e867255bbf98d238925d50a18a10f77f1587889e7123e423ac6e27eb14a3cad8a5f7d609b52661285e6a7621365c15d8e98228c23f
6
+ metadata.gz: 15d3b6b2c9924c7d12e5b5665d699c717253b4cd85fcbb717694d86bf16d824b6a7de2f16d5990d06a3bc1e4b6fffde75019d13eacc3ab612a0eeb74a2fbf6aa
7
+ data.tar.gz: cb60a335ea7143ac375eb9e9c61a3477b88976127e9af90c6f544e9dbbaecc3efdd609dfd8b22be084a049829110af6b8c2b4a9173b0495a275f5bbe5e8ab7e8
data/bin/slyce CHANGED
@@ -36,7 +36,7 @@ end
36
36
  # ==[ Options ]==
37
37
 
38
38
  OptionParser.new.instance_eval do
39
- @version = "1.5.0"
39
+ @version = "1.5.1"
40
40
  @banner = "usage: #{program_name} [options] <database> <table>"
41
41
 
42
42
  on "--csv" , "Output comma separated values"
@@ -46,7 +46,7 @@ OptionParser.new.instance_eval do
46
46
  on "-c", "--columns" , "Display column names and quit"
47
47
  on "-d", "--dump" , "Dump database schema and quit"
48
48
  on "-h", "--help" , "Show help and command usage" do Kernel.abort to_s; end
49
- on "-H", "--no-headers" , "Do not show headers when exporting delimited files"
49
+ on "-H", "--headerless" , "Do not show headers when exporting delimited files"
50
50
  on "-n", "--natural" , "Sort naturally, not numerically"
51
51
  on "-s", "--show <count>" , "Show this many values", Integer
52
52
  on "-t", "--tables" , "Display table names and quit"
@@ -65,13 +65,13 @@ xpsv = opts[:psv]
65
65
  xtsv = opts[:tsv]
66
66
  xprt = xcsv || xpsv || xtsv and require "censive"
67
67
 
68
- asky = opts[:ascii ] and require "any_ascii"
69
- dump = opts[:dump ]
70
- want = opts[:extract ].to_s.downcase.split(",")
71
- natu = opts[:natural ]
72
- show = opts[:show ]
73
- hide = opts[:"no-headers"]
74
- filt = opts[:where ] and filt = "\nwhere\n #{filt}"
68
+ asky = opts[:ascii ] and require "any_ascii"
69
+ dump = opts[:dump ]
70
+ want = opts[:extract ].to_s.downcase.split(",")
71
+ natu = opts[:natural ]
72
+ show = opts[:show ]
73
+ hide = opts[:headerless]
74
+ filt = opts[:where ] and filt = "\nwhere\n #{filt}"
75
75
 
76
76
  dbas ||= ARGV.shift or abort "no database given"
77
77
  tabl ||= ARGV.shift or opts[:tables] or !want.empty? or abort "no table given"
data/bin/slyce3 CHANGED
@@ -49,13 +49,17 @@ end
49
49
  # ==[ Options ]==
50
50
 
51
51
  OptionParser.new.instance_eval do
52
- @version = "1.5.0"
52
+ @version = "1.5.1"
53
53
  @banner = "usage: #{program_name} [options] <database> <table>"
54
54
 
55
+ on "--csv" , "Output comma separated values"
56
+ on "--psv" , "Output pipe separated values"
57
+ on "--tsv" , "Output tab separated values"
58
+ on "-a", "--ascii" , "Convert data to ASCII using AnyAscii"
55
59
  on "-c", "--columns" , "Display column names and quit"
56
60
  on "-d", "--delete" , "Delete the .slyce database first"
57
61
  on "-h", "--help" , "Show help and command usage" do Kernel.abort to_s; end
58
- on "-k", "--keep" , "For CSV files, keep the .slyce database for reuse"
62
+ on "-H", "--headerless" , "Do not show headers when exporting delimited files"
59
63
  on "-n", "--natural" , "Sort naturally, not numerically"
60
64
  on "-r", "--regexp <path>" , "Path to the sqlean/regexp extension"
61
65
  on "-s", "--show <count>" , "Show this many values", Integer
@@ -69,13 +73,20 @@ end.parse!(into: opts={}) rescue abort($!.message)
69
73
  dbas = nil
70
74
  tabl = nil
71
75
 
72
- nuke = opts[:delete ]
73
- want = opts[:extract ].to_s.downcase.split(",")
74
- keep = opts[:keep ]
75
- natu = opts[:natural ]
76
- regx = opts[:regexp ] || Dir["{.,sqlean,#{ENV['HOME']}}/regexp.{dll,dylib,so}"].first
77
- show = opts[:show ]
78
- filt = opts[:where ] and filt = "\nwhere\n #{filt}"
76
+ xcsv = opts[:csv]
77
+ xpsv = opts[:psv]
78
+ xtsv = opts[:tsv]
79
+ xprt = xcsv || xpsv || xtsv and require "censive"
80
+
81
+ asky = opts[:ascii ] and require "any_ascii"
82
+ nuke = opts[:delete ]
83
+ want = opts[:extract ].to_s.downcase.split(",")
84
+ keep = opts[:keep ]
85
+ natu = opts[:natural ]
86
+ regx = opts[:regexp ] || Dir["{.,sqlean,#{ENV['HOME']}}/regexp.{dll,dylib,so}"].first
87
+ show = opts[:show ]
88
+ hide = opts[:headerless]
89
+ filt = opts[:where ] and filt = "\nwhere\n #{filt}"
79
90
 
80
91
  # ensure regexp extension is available
81
92
  regx && File.exist?(regx) or abort "no regexp extension found#{regx ? " at '#{regx}'" : ''}"
@@ -90,8 +101,9 @@ when /(\.csv)$/, "/dev/stdin", "-"
90
101
  file = $1 ? dbas : "-"
91
102
  dbas = ".slyce"
92
103
  tabl = "csv"
104
+ head = " |head -1" if opts[:columns]
93
105
  `rm -f "#{dbas}"` if File.exist?(dbas) && !keep
94
- `sqlite3 -csv '#{dbas}' ".import '|cat #{file}' '#{tabl}'"`
106
+ `sqlite3 -csv '#{dbas}' ".import '|cat #{file}#{head}' '#{tabl}'"`
95
107
  else
96
108
  tabl ||= ARGV.shift or abort "no table given"
97
109
  end
@@ -112,6 +124,30 @@ if want.empty?
112
124
  abort "no columns are selected"
113
125
  end
114
126
 
127
+ # handle exports
128
+ if xprt
129
+ list = want.map {|item| %{"#{item}"} }.join(", ")
130
+ limt = show ? "limit #{show}" : ""
131
+ data = conn.sql(<<~"".rstrip).to_a
132
+ select
133
+ #{list}
134
+ from
135
+ "#{tabl}"
136
+ #{filt}
137
+ #{limt}
138
+
139
+ seps = xcsv ? "," : xtsv ? "\t" : xpsv ? "|" : abort("unknown separator #{seps.inspect}")
140
+
141
+ Censive.write(sep: seps) do |csv|
142
+ csv << want unless hide
143
+ data.each do |row|
144
+ csv << row.map {|e| asky ? AnyAscii.transliterate(e.to_s) : e.to_s }
145
+ end
146
+ end
147
+
148
+ exit
149
+ end
150
+
115
151
  want.each do |name|
116
152
  sort = natu ? "" : "cnt desc,"
117
153
  limt = show ? "limit #{show}" : ""
data/bin/slyced CHANGED
@@ -38,7 +38,7 @@ end
38
38
  # ==[ Options ]==
39
39
 
40
40
  OptionParser.new.instance_eval do
41
- @version = "1.5.0"
41
+ @version = "1.5.1"
42
42
  @banner = "usage: #{program_name} [options] <database> <table>"
43
43
 
44
44
  on "--csv" , "Output comma separated values"
@@ -47,7 +47,7 @@ OptionParser.new.instance_eval do
47
47
  on "-a", "--ascii" , "Convert data to ASCII using AnyAscii"
48
48
  on "-c", "--columns" , "Display column names and quit"
49
49
  on "-h", "--help" , "Show help and command usage" do Kernel.abort to_s; end
50
- on "-H", "--no-headers" , "Do not show headers when exporting delimited files"
50
+ on "-H", "--headerless" , "Do not show headers when exporting delimited files"
51
51
  on "-n", "--natural" , "Sort naturally, not numerically"
52
52
  on "-s", "--show <count>" , "Show this many values", Integer
53
53
  on "-v", "--version" , "Show version number" do Kernel.abort "#{program_name} #{@version}"; end
@@ -65,12 +65,12 @@ xpsv = opts[:psv]
65
65
  xtsv = opts[:tsv]
66
66
  xprt = xcsv || xpsv || xtsv and require "censive"
67
67
 
68
- asky = opts[:ascii ] and require "any_ascii"
69
- want = opts[:extract] .to_s.downcase.split(",")
70
- natu = opts[:natural ]
71
- show = opts[:show ]
72
- hide = opts[:"no-headers"]
73
- filt = opts[:where ] and filt = "\nwhere\n #{filt}"
68
+ asky = opts[:ascii ] and require "any_ascii"
69
+ want = opts[:extract ].to_s.downcase.split(",")
70
+ natu = opts[:natural ]
71
+ show = opts[:show ]
72
+ hide = opts[:headerless]
73
+ filt = opts[:where ] and filt = "\nwhere\n #{filt}"
74
74
 
75
75
  dbas ||= ARGV.shift or abort "no database given"
76
76
  tabl ||= ARGV.shift or abort "no table given"
@@ -80,7 +80,7 @@ tabl ||= ARGV.shift or abort "no table given"
80
80
  # ==[ Let 'er rip! ]==
81
81
 
82
82
  conn = DuckDB::Database.open(dbas).connect
83
- resu = conn.query(<<~end)
83
+ resu = conn.sql(<<~end)
84
84
  select column_name
85
85
  from information_schema.columns
86
86
  where table_name='#{tabl}'
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.5.0
4
+ version: 1.5.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-10-17 00:00:00.000000000 Z
11
+ date: 2023-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: any_ascii