csvql 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/csvql.rb +3 -2
- data/lib/csvql/csvql.rb +2 -4
- data/lib/csvql/version.rb +1 -1
- data/spec/csvql_spec.rb +30 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 878ed2bcc132c4a7d1eef108770fdf7eaf32a0a0
|
4
|
+
data.tar.gz: 6623dae499cbb326d08d74906722dd37507ac3ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bd0cfbe691654236fe9c4c7c29fe258ceddf9909dac8ab94f54a72ff584dafd95da440d0d3e0291d508233869c7a57b3b2f667b1aa1a14c1a30e684bf85fe6b
|
7
|
+
data.tar.gz: 82de714a1dcad79f54c41aeaacb0f19a0980054d875f63688a31c658662a21d68bff7942926fcf46fc08f91964563fc6c72c15ab45f5cb00d79bbe3deb49b5da
|
data/lib/csvql.rb
CHANGED
@@ -10,13 +10,12 @@ require "csvql/version"
|
|
10
10
|
module Csvql
|
11
11
|
class << self
|
12
12
|
def option_parse(argv)
|
13
|
-
opt = OptionParser.new
|
13
|
+
opt = OptionParser.new("Usage: csvql [csvfile] [options]")
|
14
14
|
option = {}
|
15
15
|
|
16
16
|
# default
|
17
17
|
option[:header] = true
|
18
18
|
|
19
|
-
opt.banner = "Usage: csvql [csvfile] [options]"
|
20
19
|
opt.on("--console", "After all commands are run, open sqlite3 console with this data") {|v| option[:console] = v }
|
21
20
|
opt.on("--[no-]header", "Treat file as having the first row as a header row") {|v| option[:header] = v }
|
22
21
|
opt.on('--output-dlm="|"', "Output delimiter (|)") {|v| option[:output_dlm] = v }
|
@@ -27,6 +26,7 @@ module Csvql
|
|
27
26
|
opt.on("--sql=SQL", "SQL Command(s) to run on the data") {|v| option[:sql] = v }
|
28
27
|
opt.on("--select=COLUMN", "Select column (*)") {|v| option[:select] = v }
|
29
28
|
opt.on("--schema=FILE or STRING", "Specify a table schema") {|v| option[:schema] = v }
|
29
|
+
opt.on("--strip", "strip every column data") {|v| option[:strip] = v }
|
30
30
|
opt.on("--where=COND", "Where clause") {|v| option[:where] = v }
|
31
31
|
opt.on("--table-name=NAME", "Override the default table name (tbl)") {|v| option[:table_name] = v }
|
32
32
|
opt.on("--verbose", "Enable verbose logging") {|v| option[:verbose] = v }
|
@@ -88,6 +88,7 @@ module Csvql
|
|
88
88
|
next if line.size == 0
|
89
89
|
next if option[:skip_comment] && line.start_with?("#")
|
90
90
|
row = line.parse_csv
|
91
|
+
row.map!(&:strip) if option[:strip]
|
91
92
|
tbl.insert(row, i)
|
92
93
|
end
|
93
94
|
tbl.exec("COMMIT TRANSACTION")
|
data/lib/csvql/csvql.rb
CHANGED
@@ -21,13 +21,11 @@ module Csvql
|
|
21
21
|
@col_name = schema.split(",").map {|c| c.split.first.strip }
|
22
22
|
@col_size = @col_name.size
|
23
23
|
@table_name = table_name
|
24
|
-
|
25
|
-
@db.execute(sql)
|
24
|
+
exec "CREATE TABLE IF NOT EXISTS #{@table_name} (#{schema})"
|
26
25
|
end
|
27
26
|
|
28
27
|
def drop_table(table_name="tbl")
|
29
|
-
|
30
|
-
@db.execute(sql)
|
28
|
+
exec "DROP TABLE IF EXISTS #{table_name}"
|
31
29
|
end
|
32
30
|
|
33
31
|
def prepare(cols)
|
data/lib/csvql/version.rb
CHANGED
data/spec/csvql_spec.rb
CHANGED
@@ -47,10 +47,39 @@ EOL
|
|
47
47
|
|
48
48
|
it 'change table name' do
|
49
49
|
expect(capture {
|
50
|
-
Csvql.run([csvfile, "--sql", "select id,name from
|
50
|
+
Csvql.run([csvfile, "--sql", "select id,name from users where id >= 4", "--table-name", "users"])
|
51
51
|
}).to eq(<<EOL)
|
52
52
|
4|Daniel
|
53
53
|
5|Edward
|
54
|
+
EOL
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'save-to db file' do
|
58
|
+
dbfile = "csvql_test.db"
|
59
|
+
Csvql.run([csvfile, "--save-to", dbfile])
|
60
|
+
expect(`sqlite3 #{dbfile} "select * from tbl"`).to eq(<<EOL)
|
61
|
+
1|Anne|33
|
62
|
+
2|Bob|25
|
63
|
+
3|Charry|48
|
64
|
+
4|Daniel|16
|
65
|
+
5|Edward|52
|
66
|
+
EOL
|
67
|
+
File.delete dbfile
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'no header' do
|
71
|
+
expect(capture {
|
72
|
+
Csvql.run([csvfile, "--no-header", "--where", "typeof(c0)!='integer'"])
|
73
|
+
}).to eq(<<EOL)
|
74
|
+
id|name|age
|
75
|
+
EOL
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'source option' do
|
79
|
+
expect(capture {
|
80
|
+
Csvql.run(["--source", csvfile, "--select", "count(*)"])
|
81
|
+
}).to eq(<<EOL)
|
82
|
+
5
|
54
83
|
EOL
|
55
84
|
end
|
56
85
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csvql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- YANO Satoru
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|
@@ -75,3 +75,4 @@ test_files:
|
|
75
75
|
- spec/csvql_spec.rb
|
76
76
|
- spec/sample.csv
|
77
77
|
- spec/spec_helper.rb
|
78
|
+
has_rdoc:
|