csv_to_sqlite3 0.1.1 → 0.1.2
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/.DS_Store +0 -0
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/Rakefile +9 -10
- data/lib/csv_reader.rb +14 -2
- data/lib/csv_to_sqlite.rb +1 -2
- data/lib/csv_to_sqlite/version.rb +1 -1
- data/lib/sql/column.rb +8 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29085b03af4098c78b2b1ef115618ea606054866909d4c9f22c8c157336b63fb
|
4
|
+
data.tar.gz: e770c2154eb29c5c0cdad8321d2b27b1a9a091d0b96445acc64f962105e39e2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7be539d9f72f92e403356d838aeb3837ec5566563af38cd8ca4d87562c484a41d58707e2deb6689348c671d49405eb20bc81067b4b7d5d722c39801cf7021b4
|
7
|
+
data.tar.gz: fe1310bc7b61d33d9caa21592fca1f38514dbff276faccc86cf30241e1504683c1956ba0774336a2f3be1755eb1f705b17231b5f2d50dbfc7e390b7601e714e5
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -6,17 +6,16 @@
|
|
6
6
|
# task :default => :spec
|
7
7
|
|
8
8
|
|
9
|
-
require_relative "lib/database"
|
10
|
-
require_relative "lib/csv_reader"
|
11
|
-
require_relative "lib/sql/create_table"
|
12
|
-
require_relative "lib/sql/insert"
|
9
|
+
# require_relative "lib/database"
|
10
|
+
# require_relative "lib/csv_reader"
|
11
|
+
# require_relative "lib/sql/create_table"
|
12
|
+
# require_relative "lib/sql/insert"
|
13
13
|
|
14
|
-
|
14
|
+
require_relative "lib/csv_to_sqlite"
|
15
|
+
|
16
|
+
task default: :convert
|
15
17
|
|
16
18
|
desc "Create tables used in sqlite"
|
17
|
-
task :
|
18
|
-
|
19
|
-
csv_table = CsvToSQLite::CsvReader.load_file './spec/test_files/test_file.csv'
|
20
|
-
CsvToSQLite::SQL::CreateTable.new(name: 'persons', csv_table: csv_table, connection: connection).run
|
21
|
-
CsvToSQLite::SQL::Insert.new(name: 'persons', csv_table: csv_table, connection: connection).run
|
19
|
+
task :convert do
|
20
|
+
CsvToSqlite::CsvToSQLite.new.convert(ARGV[1])
|
22
21
|
end
|
data/lib/csv_reader.rb
CHANGED
@@ -4,8 +4,20 @@ module CsvToSqlite
|
|
4
4
|
|
5
5
|
class CsvReader
|
6
6
|
|
7
|
-
def
|
8
|
-
|
7
|
+
def initialize file_path
|
8
|
+
@file_path = file_path
|
9
|
+
end
|
10
|
+
|
11
|
+
def load_file
|
12
|
+
CSV.parse(File.read(@file_path), headers: true, col_sep: separator)
|
13
|
+
end
|
14
|
+
|
15
|
+
def separator
|
16
|
+
first_line = File.open(@file_path) do |file|
|
17
|
+
line = file.readline
|
18
|
+
return ";" if line.include? ";"
|
19
|
+
return "," if line.include? ","
|
20
|
+
end
|
9
21
|
end
|
10
22
|
|
11
23
|
end
|
data/lib/csv_to_sqlite.rb
CHANGED
@@ -11,8 +11,7 @@ module CsvToSqlite
|
|
11
11
|
|
12
12
|
def convert file_path
|
13
13
|
connection = CsvToSqlite::Database.new().connect
|
14
|
-
csv_table = CsvToSqlite::CsvReader.load_file
|
15
|
-
puts file_path
|
14
|
+
csv_table = CsvToSqlite::CsvReader.new(file_path).load_file
|
16
15
|
table_name = file_path.split("/").last.split(".csv").first
|
17
16
|
CsvToSqlite::SQL::CreateTable.new(name: table_name, csv_table: csv_table, connection: connection).run
|
18
17
|
CsvToSqlite::SQL::Insert.new(name: table_name, csv_table: csv_table, connection: connection).run
|
data/lib/sql/column.rb
CHANGED
@@ -8,7 +8,9 @@ module CsvToSqlite::SQL
|
|
8
8
|
|
9
9
|
def sql_for column
|
10
10
|
@data = @csv_table[column][0..2]
|
11
|
-
if
|
11
|
+
if null?
|
12
|
+
type = "TEXT DEFAULT NULL"
|
13
|
+
elsif int?
|
12
14
|
type = "INTEGER"
|
13
15
|
elsif float?
|
14
16
|
type = "FLOAT"
|
@@ -24,6 +26,11 @@ module CsvToSqlite::SQL
|
|
24
26
|
"#{column} #{type},"
|
25
27
|
end
|
26
28
|
|
29
|
+
def null?
|
30
|
+
match_cases = @data.map { |value| value == nil }
|
31
|
+
match_cases.any? { |value| value == true }
|
32
|
+
end
|
33
|
+
|
27
34
|
def int?
|
28
35
|
meta_comparing :Integer
|
29
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csv_to_sqlite3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- joaofelipelopes
|
@@ -18,6 +18,7 @@ executables:
|
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
+
- ".DS_Store"
|
21
22
|
- ".gitignore"
|
22
23
|
- ".rspec"
|
23
24
|
- ".travis.yml"
|