slyce 1.5.0 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) 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. data/slyce.gemspec +1 -1
  6. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8350b63046aa4e84fd9f04bd73ed92140ec3b569ac6c997f53f74e2235ec685
4
- data.tar.gz: 34ee0a6665542b55df24b55d22150017610f1fdb891860e95b33b8ab30b03eaa
3
+ metadata.gz: 44084fdce3c1789a721168848cf683134ba5fd6e4cfc507407e00c3c0513ac99
4
+ data.tar.gz: 9ed23516f4f28c3a36f9107d6edffe1c93fc1d19abf83573ba15bac339eff873
5
5
  SHA512:
6
- metadata.gz: c405dc17703ea8c99617183ef95185deb3703c98ab029106ac87a6e5ea2e3af833c3a6534e99960892de2cd6c6e69ebd2a3653e3c38d93c9c7fc60839df353bd
7
- data.tar.gz: 25273ba52a3fec83f83da1e867255bbf98d238925d50a18a10f77f1587889e7123e423ac6e27eb14a3cad8a5f7d609b52661285e6a7621365c15d8e98228c23f
6
+ metadata.gz: a9d9bebd0f769095ffb62deb70aafe40f03d4bf2b0744cc8940709ffe8d11f8d19cccf4d6206dc5ff20c947feac3c747d2f0510a5370acb5e9b2d0049c50630a
7
+ data.tar.gz: f58765772f90d5af7c395db8ff3624556a7bba867155c3c2bdc0114406e6976d5c69846e131ea6e051bc091086e7af3eaa4f033e419e43161a1ea38128f66c04
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.2"
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.2"
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.2"
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}'
data/slyce.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.executables = `cd bin && git ls-files .`.split("\n")
14
14
  s.add_runtime_dependency "any_ascii", "~> 0.3.2"
15
15
  s.add_runtime_dependency "censive", "~> 1.1.0"
16
- s.add_runtime_dependency "duckdb", "~> 0.8.1"
16
+ s.add_runtime_dependency "duckdb", "~> 0.9"
17
17
  s.add_runtime_dependency "extralite-bundle", "~> 2.1"
18
18
  s.add_runtime_dependency "mysql2", "~> 0.5"
19
19
  end
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.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-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
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.8.1
47
+ version: '0.9'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.8.1
54
+ version: '0.9'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: extralite-bundle
57
57
  requirement: !ruby/object:Gem::Requirement