csv2psql 0.0.6 → 0.0.8
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +38 -13
- data/TODO.md +12 -0
- data/data/cia-data-all.csv +262 -0
- data/lib/csv2psql/analyzer/analyzer.rb +89 -0
- data/lib/csv2psql/analyzer/types/bigint.rb +27 -0
- data/lib/csv2psql/analyzer/types/decimal.rb +27 -0
- data/lib/csv2psql/cli/app.rb +36 -6
- data/lib/csv2psql/cli/cmd/analyze_cmd.rb +24 -0
- data/lib/csv2psql/cli/cmd/convert_cmd.rb +0 -27
- data/lib/csv2psql/convert/convert.rb +5 -0
- data/lib/csv2psql/dialects/psql.rb +66 -0
- data/lib/csv2psql/extensions/string.rb +10 -0
- data/lib/csv2psql/generator/generator.rb +126 -0
- data/lib/csv2psql/helpers/csv_helper.rb +21 -0
- data/lib/csv2psql/output/output.rb +18 -0
- data/lib/csv2psql/processor/processor.rb +30 -103
- data/lib/csv2psql/version.rb +2 -1
- data/templates/header.sql.erb +1 -1
- metadata +13 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f5f61f71e9f7603d48dc14ef87523cc694aa2d1
|
4
|
+
data.tar.gz: b94b1da7149fc9440b9a32fd814759d65fe1d6cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3aaadd21b47420361bd97b1b43f331527f5302a89670d58160c5bdadfc67772aa978659651b780da81ed53308f3686890b903558a9c993e58134de14d2105620
|
7
|
+
data.tar.gz: a95cbe9e026613a399e62081666ecc3505a26377534b915d1748730018fe92e78a3e5efcb6a28c354788d003a40b1064ac1cc9d569652e35509806700d84e690
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
Tool for transforming CSV into SQL statements
|
4
4
|
|
5
|
+
*Formalities*
|
6
|
+
|
7
|
+
- [License](https://github.com/korczis/csv2psql/blob/master/LICENSE)
|
8
|
+
- [To Do](https://github.com/korczis/csv2psql/blob/master/TODO.md)
|
9
|
+
- [Issues](https://github.com/korczis/csv2psql/issues)
|
10
|
+
|
5
11
|
## Status
|
6
12
|
|
7
13
|
[](http://badge.fury.io/rb/csv2psql)
|
@@ -10,6 +16,18 @@ Tool for transforming CSV into SQL statements
|
|
10
16
|
[](https://codeclimate.com/github/korczis/csv2psql)
|
11
17
|
[](https://gemnasium.com/korczis/csv2psql)
|
12
18
|
|
19
|
+
|
20
|
+
## Features
|
21
|
+
|
22
|
+
- Works outside of box
|
23
|
+
- Customizable (parameters can be tweaked)
|
24
|
+
- Extendable (external modules can bring functionality)
|
25
|
+
- Database aware
|
26
|
+
- SQL Dialects sensitive
|
27
|
+
- [Drop table](https://github.com/korczis/csv2psql/blob/master/templates/drop_table.sql.erb)
|
28
|
+
- [Create table](https://github.com/korczis/csv2psql/blob/master/templates/create_table.sql.erb)
|
29
|
+
- [Truncate database](https://github.com/korczis/csv2psql/blob/master/templates/truncate_table.sql.erb)
|
30
|
+
|
13
31
|
## Getting started
|
14
32
|
|
15
33
|
```
|
@@ -30,13 +48,17 @@ csv2psql convert data/sample.csv
|
|
30
48
|
csv2psql help
|
31
49
|
|
32
50
|
NAME
|
33
|
-
csv2psql - csv2psql 0.0.
|
51
|
+
csv2psql - csv2psql 0.0.7 (Codename: Smelly cat)
|
34
52
|
|
35
53
|
SYNOPSIS
|
36
54
|
csv2psql [global options] command [command options] [arguments...]
|
37
55
|
|
38
56
|
GLOBAL OPTIONS
|
39
|
-
--
|
57
|
+
-d, --delimiter=arg - Column delimiter (default: ,)
|
58
|
+
-h, --[no-]header - Header row included (default: enabled)
|
59
|
+
--help - Show this message
|
60
|
+
-q, --quote=arg - Quoting character (default: ")
|
61
|
+
-s, --separator=arg - Line separator (default: auto)
|
40
62
|
|
41
63
|
COMMANDS
|
42
64
|
convert - Convert csv file
|
@@ -57,12 +79,8 @@ SYNOPSIS
|
|
57
79
|
|
58
80
|
COMMAND OPTIONS
|
59
81
|
--[no-]create-table - Crate SQL Table before inserts
|
60
|
-
-d, --delimiter=arg - Column delimiter (default: ,)
|
61
82
|
--[no-]drop-table - Drop SQL Table before inserts
|
62
|
-
-
|
63
|
-
-q, --quote=arg - Quoting character (default: ")
|
64
|
-
-s, --separator=arg - Line separator (default: auto)
|
65
|
-
-t, --table=arg - Table to insert to (default: my_table)
|
83
|
+
-t, --table=arg - Table to insert to (default: none)
|
66
84
|
--[no-]transaction - Import in transaction block (default: enabled)
|
67
85
|
--[no-]truncate-table - Truncate SQL Table before inserts
|
68
86
|
```
|
@@ -85,8 +103,10 @@ id,Firstname,Lastname,Address.Street,Address.City,Address.Details.Note
|
|
85
103
|
csv2psql convert data/sample.csv
|
86
104
|
|
87
105
|
BEGIN;
|
88
|
-
|
89
|
-
|
106
|
+
-- Table: my_table
|
107
|
+
|
108
|
+
INSERT INTO (id, firstname, lastname, address_street, address_city, address_details_note) VALUES('12345', 'Joe', 'Doe', '#2140 Taylor Street, 94133', 'San Francisco', 'Pool available');
|
109
|
+
INSERT INTO (id, firstname, lastname, address_street, address_city, address_details_note) VALUES('45678', 'Jack', 'Plumber', '#111 Sutter St, 94104', 'San Francisco', 'Korean Deli near to main entrance');
|
90
110
|
COMMIT;
|
91
111
|
```
|
92
112
|
|
@@ -97,7 +117,6 @@ csv2psql convert --create-table -t pokus data/sample.csv
|
|
97
117
|
|
98
118
|
BEGIN;
|
99
119
|
-- Table: pokus
|
100
|
-
-- DROP TABLE pokus;
|
101
120
|
|
102
121
|
CREATE TABLE pokus(
|
103
122
|
id TEXT,
|
@@ -116,10 +135,10 @@ INSERT INTO pokus(id, firstname, lastname, address_street, address_city, address
|
|
116
135
|
COMMIT;
|
117
136
|
```
|
118
137
|
|
119
|
-
**Convert CSV - Stream directly to
|
138
|
+
**Convert CSV - Stream directly to Postgres client (psql)**
|
120
139
|
|
121
140
|
```
|
122
|
-
csv2psql convert --create-table -t hokus data/sample.csv | psql
|
141
|
+
csv2psql convert --create-table -t hokus data/sample.csv | psql
|
123
142
|
|
124
143
|
BEGIN
|
125
144
|
CREATE TABLE
|
@@ -155,6 +174,12 @@ INSERT INTO test(id, firstname, lastname, address_street, address_city, address_
|
|
155
174
|
COMMIT;
|
156
175
|
```
|
157
176
|
|
177
|
+
**Convert CSV - Load CIA Factbook automagically**
|
178
|
+
|
179
|
+
```
|
180
|
+
csv2psql convert --create-table --drop-table --truncate-table --no-transaction -t test data/cia-data-all.csv | psql
|
181
|
+
```
|
182
|
+
|
158
183
|
## Contributing to csv2psql
|
159
184
|
|
160
185
|
- Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
@@ -167,4 +192,4 @@ COMMIT;
|
|
167
192
|
|
168
193
|
## Copyright
|
169
194
|
|
170
|
-
Copyright (c) 2014 Tomas Korcak. See LICENSE for details.
|
195
|
+
Copyright (c) 2014 [Tomas Korcak](https://www.linkedin.com/in/korcaktomas). See [LICENSE](https://github.com/korczis/csv2psql/blob/master/LICENSE) for details.
|
data/TODO.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# To Do
|
2
|
+
|
3
|
+
List od task to do
|
4
|
+
|
5
|
+
## Tasks
|
6
|
+
|
7
|
+
- Column names override
|
8
|
+
- Data type detection
|
9
|
+
- Include/Exclude columns
|
10
|
+
- Column datatype guesser (with sha based caching of results)
|
11
|
+
- Templates override
|
12
|
+
- Custom row formater - no need to override templates
|