idata 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/iexport +37 -14
  3. data/lib/idata/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 783eb30b0a6cd789cc9d2fb0da70f4778fde4cc4
4
- data.tar.gz: 437a27a9a00e673d428725091f73e7c68629db39
3
+ metadata.gz: a65ffab6dcd5b46ea706e0234d603432d8dfe967
4
+ data.tar.gz: 375b06bd1ba205618418c0fd536ea241cf59dc10
5
5
  SHA512:
6
- metadata.gz: ab81630fc7a8293952e91074275ba447dca0f55e08507a1512237774eed8da58202814f655087f03d6d92ecdfe33a45efc8c6ab82ef30501cf3793ed978352cb
7
- data.tar.gz: 95ca71dceb6ac7cd5616f02d708ae3cd071040501e764a7e384c5fb2486dc73861fff0c141b0aca4ac9a61cf372b6d23435f3355bc699d3be73527cd7e5df7db
6
+ metadata.gz: 1e35c422fa9eae8475d33b750022f236ec74e0f1f95fd4baff680abaec9f7d2ff1c6ef436a183c7c8d9d09cf35c3b0b4b4aed2bf4cb18d674356d16787024130
7
+ data.tar.gz: 0c8838b2a6483870fec4289d4d8570e24e2da1af095a12d6ccdc274451b1b2ab55413f81e5f8916b80b50a2fb905d035b7a9d19a3fdfc8db53ba56055be06f19
@@ -14,6 +14,7 @@ require 'active_record'
14
14
  require 'rubygems'
15
15
  require 'digest/sha1'
16
16
  require 'fileutils'
17
+ require 'sqlite3'
17
18
 
18
19
  SUPPORTED_INPUT_FORMATS = ['CSV']
19
20
  POSTGRESQL_PORT = 5432
@@ -80,6 +81,10 @@ parser = OptionParser.new("", 24) do |opts|
80
81
  opts.on("-o", "--output FILE", "Output file") do |v|
81
82
  $options[:output] = v
82
83
  end
84
+
85
+ opts.on("--sqlitedb PATH", "Path to SQLite3 database file") do |v|
86
+ $options[:sqlitedb] = v
87
+ end
83
88
 
84
89
  opts.on("-h", "--host HOST", "PostgreSQL host") do |v|
85
90
  $options[:host] = v
@@ -157,21 +162,32 @@ if $options[:output].nil?
157
162
  exit
158
163
  end
159
164
 
160
- if $options[:host].nil?
165
+ if $options[:host].nil? && $options[:sqlitedb].nil?
161
166
  puts "\nPlease specify host name: -h\n\n"
162
167
  exit
163
168
  end
164
169
 
165
- if $options[:database].nil?
170
+ if $options[:database].nil? && $options[:sqlitedb].nil?
166
171
  puts "\nPlease specify PostgreSQL database name: -d\n\n"
167
172
  exit
168
173
  end
169
174
 
170
- if $options[:username].nil?
175
+ if $options[:username].nil? && $options[:sqlitedb].nil?
171
176
  puts "\nPlease specify PostgreSQL username: -u\n\n"
172
177
  exit
173
178
  end
174
179
 
180
+ if ($options[:host] || $options[:username] || $options[:listen] || $options[:password]) && $options[:sqlitedb]
181
+ puts "\nYou cannot specify both PostgreSQL ('host', 'username', 'listen', 'password') and SQLite ('sqlitedb') parameters \n\n"
182
+ exit
183
+ end
184
+
185
+ if $options[:sqlitedb] && !File.exists?($options[:sqlitedb])
186
+ puts "\nFile does not exist '#{$options[:sqlitedb]}'\n\n"
187
+ exit
188
+ end
189
+
190
+
175
191
  # Default value
176
192
  $options[:listen] ||= POSTGRESQL_PORT
177
193
  $options[:delim] ||= CSV_DEFAULT_DELIMITER
@@ -182,7 +198,7 @@ $options[:headers] ||= false
182
198
  $options[:quotes] ||= false
183
199
  $options[:quote_empty] ||= false
184
200
  $options[:select] ||= '*'
185
- $options[:where] ||= 'true'
201
+ $options[:where] ||= ( $options[:sqlitedb].nil? ) ? 'true' : '1=1'
186
202
  $options[:include] ||= ""
187
203
 
188
204
  # Do not quote the '"' char
@@ -203,16 +219,23 @@ end
203
219
 
204
220
  $options[:select] = [$options[:select].split(/\s*,\s*/) + $options[:include].split(/\s*,\s*/)].join(", ")
205
221
 
206
- #$options = {host: 'localhost', database: 'db', username: 'postgres', password: 'postgres', table: 'products', listen: 5432}
207
- ActiveRecord::Base.establish_connection(
208
- 'adapter' => 'postgresql',
209
- 'host' => $options[:host],
210
- 'database' => $options[:database],
211
- 'username' => $options[:username],
212
- 'password' => $options[:password],
213
- 'port' => $options[:listen],
214
- 'timeout' => 15000
215
- )
222
+ if $options[:sqlitedb]
223
+ ActiveRecord::Base.establish_connection(
224
+ 'adapter' => 'sqlite3',
225
+ 'database' => $options[:sqlitedb],
226
+ 'timeout' => 15000
227
+ )
228
+ else
229
+ ActiveRecord::Base.establish_connection(
230
+ 'adapter' => 'postgresql',
231
+ 'host' => $options[:host],
232
+ 'database' => $options[:database],
233
+ 'username' => $options[:username],
234
+ 'password' => $options[:password],
235
+ 'port' => $options[:listen],
236
+ 'timeout' => 15000
237
+ )
238
+ end
216
239
 
217
240
  class Product < ActiveRecord::Base
218
241
  self.table_name = $options[:table]
@@ -1,3 +1,3 @@
1
1
  module Idata
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: idata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nghi Pham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-26 00:00:00.000000000 Z
11
+ date: 2014-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler