csv_to_sqlite3 0.1.2 → 0.1.3.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29085b03af4098c78b2b1ef115618ea606054866909d4c9f22c8c157336b63fb
4
- data.tar.gz: e770c2154eb29c5c0cdad8321d2b27b1a9a091d0b96445acc64f962105e39e2b
3
+ metadata.gz: 56c03665afe1b983d14a337499848d9c3e726b27fb167bd0d3188667c461d663
4
+ data.tar.gz: 4b5b1c27aefbfc9bab5570a41b444bf275ed33e1e0c35b8506635751e97b87bf
5
5
  SHA512:
6
- metadata.gz: c7be539d9f72f92e403356d838aeb3837ec5566563af38cd8ca4d87562c484a41d58707e2deb6689348c671d49405eb20bc81067b4b7d5d722c39801cf7021b4
7
- data.tar.gz: fe1310bc7b61d33d9caa21592fca1f38514dbff276faccc86cf30241e1504683c1956ba0774336a2f3be1755eb1f705b17231b5f2d50dbfc7e390b7601e714e5
6
+ metadata.gz: 8838ba8bfda796e828cfe8480173e8452f1a0d03abf13dfde349c15fbed8a828dd84d3982f1ae0703ec79e753bcd6bc89b0a23af6a1682ee11454c9ec3fad42c
7
+ data.tar.gz: 31777150c5c6bd22ea13a7b24160cd8bc977ae054eca7f638db646db290b28a39d34c5faea66c6baba5f8c28b7f773e3858e1a4f78e84c5e0670faa2cb119391
data/Gemfile CHANGED
@@ -6,3 +6,4 @@ gemspec
6
6
  gem "rake", "~> 12.0"
7
7
  gem 'rspec', '~> 3.9'
8
8
  gem 'sqlite3', '~> 1.4', '>= 1.4.2'
9
+ gem 'tty-progressbar'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- csv_to_sqlite3 (0.1.1)
4
+ csv_to_sqlite3 (0.1.3.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -22,6 +22,15 @@ GEM
22
22
  rspec-support (~> 3.9.0)
23
23
  rspec-support (3.9.3)
24
24
  sqlite3 (1.4.2)
25
+ strings-ansi (0.1.0)
26
+ tty-cursor (0.7.1)
27
+ tty-progressbar (0.17.0)
28
+ strings-ansi (~> 0.1.0)
29
+ tty-cursor (~> 0.7)
30
+ tty-screen (~> 0.7)
31
+ unicode-display_width (~> 1.6)
32
+ tty-screen (0.8.1)
33
+ unicode-display_width (1.7.0)
25
34
 
26
35
  PLATFORMS
27
36
  ruby
@@ -31,6 +40,7 @@ DEPENDENCIES
31
40
  rake (~> 12.0)
32
41
  rspec (~> 3.9)
33
42
  sqlite3 (~> 1.4, >= 1.4.2)
43
+ tty-progressbar
34
44
 
35
45
  BUNDLED WITH
36
46
  2.1.4
data/README.md CHANGED
@@ -1,28 +1,24 @@
1
- # CsvToSqlite
1
+ # CsvToSqlite3
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/csv_to_sqlite`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ CsvToSqlite3 is a gem that aims to work as a executable like rake or bundler, it servs as a Sqlite3 database generator from csv files. It is used to create and insert all data from one or more csv files to the same Sqlite3 database.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ The ideia comes from a specific cenario when I needed to run complex sql queries on a huge database, and once I was afraid to run it directly in prolduction and it impacts in the operation I chose to run simples selects (select * from some_table when created_at > some_date) from each table used on my query, export to csv files than create a specific ruby script that create a sqlite3 database and run the inserts, thereby i can run any havy query on my local computer without generate any impact in the operation.
6
6
 
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
7
+ Once this cenario is quite common I decided to rewrite the script to work with any csv file exported from any table.
10
8
 
11
- ```ruby
12
- gem 'csv_to_sqlite'
13
- ```
9
+ ## Installation
14
10
 
15
- And then execute:
11
+ Installed with gem:
16
12
 
17
- $ bundle install
13
+ $ gem install csv_to_sqlite3
18
14
 
19
- Or install it yourself as:
15
+ ## Usage
20
16
 
21
- $ gem install csv_to_sqlite
17
+ Once the gem is installed it is aviable the command "csv_to_sqlite", to generate a new database you need to run on terminal "csv_to_sqlite path/to/file.csv'". It will create a file named data.sqlite3 and create a table with name equal to file name, case the table already exists it will only insert all data from this file.
22
18
 
23
- ## Usage
19
+ $ csv_to_sqlite stores.csv
24
20
 
25
- TODO: Write usage instructions here
21
+ By running the command above it will be generated a database data.sqlite3 with a table named stores with all data included.
26
22
 
27
23
  ## Development
28
24
 
@@ -32,7 +28,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
28
 
33
29
  ## Contributing
34
30
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/csv_to_sqlite.
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/joaofelipe1294/csv_to_sqlite3.
36
32
 
37
33
 
38
34
  ## License
@@ -1,4 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'csv_to_sqlite'
4
- CsvToSqlite::CsvToSqlite.convert(ARGV[0])
@@ -6,8 +6,8 @@ Gem::Specification.new do |spec|
6
6
  spec.authors = ["joaofelipelopes"]
7
7
  spec.email = ["joaofelipe1294@gmail.com"]
8
8
 
9
- spec.summary = %q{An easy way to convert a csv file into SQLite database.}
10
- spec.description = %q{Add a better description.}
9
+ spec.summary = %q{An easy way to convert a csv file into SQLite3 database.}
10
+ spec.description = %q{Add the executable "csv_to_sqlite" to your terminal, wich is used to create a SQLite3 database with all data from a csv file by running "csv_to_sqlite file.csv". It was developed to be used as a command line.}
11
11
  spec.homepage = "https://github.com/joaofelipe1294/csv_to_sqlite3"
12
12
  spec.license = "MIT"
13
13
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.executables << 'csv_to_sqlite'
27
27
  spec.require_paths = ["lib"]
28
+ spec.add_runtime_dependency "tty-progressbar"
28
29
  end
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'csv_to_sqlite'
4
- CsvToSqlite::CsvToSQLite.new.convert(ARGV[0])
4
+
5
+ CsvToSqlite::CsvToSQLite.new(ARGV).run
6
+
@@ -0,0 +1,30 @@
1
+ module CsvToSqlite
2
+ class ArgumentHandlerService
3
+
4
+ def initialize argv
5
+ @argv = argv
6
+ end
7
+
8
+ def call
9
+ return empty if @argv.empty?
10
+ return help if @argv.include? "-h"
11
+ :convert
12
+ end
13
+
14
+ def help
15
+ puts "Run csv_lto_sqlite3 is easy!"
16
+ puts "To convert a csv file into a sqlite3 database you just need to run the follow command from the same directory of the csv file:"
17
+ puts "csv_to_sqlite your_csv_file.csv"
18
+ puts "==============================="
19
+ puts "-t <table-name> -> parameter used to set wich table will be created/used"
20
+ puts "Some customisations will be aviable on next versions :)"
21
+ nil
22
+ end
23
+
24
+ def empty
25
+ puts "Run 'csv_to_sqlite -h' to receive some help or csv_to_sqlite csv_file.csv to generate a SQLite3 database from a csv file."
26
+ nil
27
+ end
28
+
29
+ end
30
+ end
@@ -3,20 +3,46 @@ require_relative "./database"
3
3
  require_relative "./csv_reader"
4
4
  require_relative "./sql/create_table"
5
5
  require_relative "./sql/insert"
6
+ require_relative "./argument_handler_service"
6
7
 
7
8
  module CsvToSqlite
8
9
  # class Error < StandardError; end
9
10
 
10
11
  class CsvToSQLite
11
12
 
13
+ def initialize argv
14
+ @args = argv
15
+ end
16
+
17
+ def run
18
+ method = CsvToSqlite::ArgumentHandlerService.new(@args).call
19
+ self.convert(@args.first) unless method.nil?
20
+ end
21
+
12
22
  def convert file_path
13
23
  connection = CsvToSqlite::Database.new().connect
14
24
  csv_table = CsvToSqlite::CsvReader.new(file_path).load_file
15
- table_name = file_path.split("/").last.split(".csv").first
16
25
  CsvToSqlite::SQL::CreateTable.new(name: table_name, csv_table: csv_table, connection: connection).run
17
26
  CsvToSqlite::SQL::Insert.new(name: table_name, csv_table: csv_table, connection: connection).run
18
27
  end
19
28
 
29
+ def table_name
30
+ if @args.include? "-t"
31
+ table_name_index = @args.find_index "-t"
32
+ return @args[table_name_index + 1]
33
+ else
34
+ return csv_file_name.split("/").last.split(".csv").first
35
+ end
36
+ end
37
+
38
+ def csv_file_name
39
+ file_name = nil
40
+ @args.each_with_index do |param, index|
41
+ file_name = param if param.include? ".csv"
42
+ end
43
+ file_name
44
+ end
45
+
20
46
  end
21
47
 
22
48
  end
@@ -1,3 +1,3 @@
1
1
  module CsvToSqlite
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3.4"
3
3
  end
@@ -1,3 +1,5 @@
1
+ require "tty-progressbar"
2
+
1
3
  module CsvToSqlite::SQL
2
4
 
3
5
  class Insert
@@ -10,11 +12,14 @@ module CsvToSqlite::SQL
10
12
 
11
13
  def run
12
14
  columns = @csv_table.headers.sort
15
+ bar = TTY::ProgressBar.new("Inserting data [:bar] :percent", total: @csv_table.by_row.count)
13
16
  @csv_table.by_row.each do |row|
14
17
  values = columns.map { |column| row[column] }
15
18
  question_marks = ("?," * columns.size).chop!
16
19
  @connection.execute("INSERT INTO #{@name} (#{columns.join(',')}) VALUES (#{question_marks})", values)
20
+ bar.advance(1)
17
21
  end
22
+ bar.finish
18
23
  end
19
24
 
20
25
  end
metadata CHANGED
@@ -1,16 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv_to_sqlite3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - joaofelipelopes
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-21 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Add a better description.
11
+ date: 2020-10-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tty-progressbar
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Add the executable "csv_to_sqlite" to your terminal, wich is used to
28
+ create a SQLite3 database with all data from a csv file by running "csv_to_sqlite
29
+ file.csv". It was developed to be used as a command line.
14
30
  email:
15
31
  - joaofelipe1294@gmail.com
16
32
  executables:
@@ -32,6 +48,7 @@ files:
32
48
  - bin/setup
33
49
  - csv_to_sqlite3.gemspec
34
50
  - exe/csv_to_sqlite
51
+ - lib/argument_handler_service.rb
35
52
  - lib/csv_reader.rb
36
53
  - lib/csv_to_sqlite.rb
37
54
  - lib/csv_to_sqlite/version.rb
@@ -63,5 +80,5 @@ requirements: []
63
80
  rubygems_version: 3.0.3
64
81
  signing_key:
65
82
  specification_version: 4
66
- summary: An easy way to convert a csv file into SQLite database.
83
+ summary: An easy way to convert a csv file into SQLite3 database.
67
84
  test_files: []