load_data_infile2 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba0f292c77592b2d745b4db05fbbbd8245b17044
4
- data.tar.gz: 56e2f3d2bbc9ef359af4025dbd0a07b195e927a6
3
+ metadata.gz: 87b9140ace11ad2189f8f576e5643f554989f043
4
+ data.tar.gz: 5b589c0d32973317a5545a0857a927e9f0a7f7fa
5
5
  SHA512:
6
- metadata.gz: dd75af4d2246b6d6b116808970e4bad0cfaa374c4a2a5f2d31b50ff312f26e3c8a97714295b2202c65c0e1ffa4068779a9e57f116d814a34e29c9f56c4a107f6
7
- data.tar.gz: d32e50d8e90dc0a744ba995c2d5933ff7090d9eb2a8d186e42bc100e06e313e3b656064c38c8c29c7248023a918558d9ebca0e12b889f5af76501767d9cdd8c1
6
+ metadata.gz: 5ba411422e6300479ce7aa9d7928a524c596181725c42f17c3d6e1633061521df7226336ca7091dad7e16df160f9b7f27b91b6bde3bca3195e0ea378172ebf50
7
+ data.tar.gz: 56bc6ed3204230c9e3b975cf294854570e0e98ea8e62e86f4cc1b307d8b96e2e0b4c8db63899ae8c2fab626f754fbbdb62be7257d620748960b6e3aa4b7c717f
@@ -5,11 +5,11 @@ module LoadDataInfile2
5
5
  def initialize(ar_subclass, options = {})
6
6
  @ar_class = ar_subclass
7
7
  if options[:local_infile]
8
- raise "Require option as `local_infile: true` in config/database.yml" unless ar_class.connection.instance_variable_get(:@connection).query_options[:local_infile]
8
+ raise "Require option as `local_infile: true` in config/database.yml" unless @ar_class.connection.instance_variable_get(:@connection).query_options[:local_infile]
9
9
  end
10
10
 
11
11
  @load_data_infile_options = LoadDataInfile2.default_import_options.merge(options)
12
- @load_data_infile_options[:charset] = ar_class.connection_config[:charset] unless options.has_key?(:charset)
12
+ @load_data_infile_options[:charset] = @ar_class.connection_config[:charset] unless options.has_key?(:charset)
13
13
  end
14
14
 
15
15
  def import(file, options = {})
@@ -18,14 +18,12 @@ module LoadDataInfile2
18
18
 
19
19
  private
20
20
 
21
- attr_reader :ar_class, :load_data_infile_options
22
-
23
21
  def build_sql(file, options = {})
24
- LoadDataInfile2::Sql.new(file, ar_class.quoted_table_name, load_data_infile_options.merge(options)).build
22
+ LoadDataInfile2::Sql.new(file, @ar_class.quoted_table_name, @load_data_infile_options.merge(options)).build
25
23
  end
26
24
 
27
25
  def query(sql)
28
- ar_class.connection.execute(sql)
26
+ @ar_class.connection.execute(sql)
29
27
  end
30
28
  end
31
29
  end
@@ -47,26 +47,26 @@ module LoadDataInfile2
47
47
 
48
48
  def load_data_infile
49
49
  stmt = 'LOAD DATA '
50
- stmt.concat("#{options[:low_priority_or_concurrent].upcase} ") if %i(low_priority concurrent).include?(options[:low_priority_or_concurrent])
51
- stmt.concat('LOCAL ') if options[:local_infile]
52
- stmt.concat("INFILE '#{file}'")
50
+ stmt.concat("#{@options[:low_priority_or_concurrent].upcase} ") if %i(low_priority concurrent).include?(@options[:low_priority_or_concurrent])
51
+ stmt.concat('LOCAL ') if @options[:local_infile]
52
+ stmt.concat("INFILE '#{@file}'")
53
53
  stmt
54
54
  end
55
55
 
56
56
  def replace_or_ignore
57
- options[:replace_or_ignore].to_s.upcase if %i(replace ignore).include?(options[:replace_or_ignore])
57
+ @options[:replace_or_ignore].to_s.upcase if %i(replace ignore).include?(@options[:replace_or_ignore])
58
58
  end
59
59
 
60
60
  def into_table
61
- "INTO TABLE #{table}"
61
+ "INTO TABLE #{@table}"
62
62
  end
63
63
 
64
64
  def partition
65
- "PARTITION (#{Array(options[:partition]).join(', ')})" if options[:partition] && options[:partition].size > 0
65
+ "PARTITION (#{Array(@options[:partition]).join(', ')})" if @options[:partition] && @options[:partition].size > 0
66
66
  end
67
67
 
68
68
  def character_set
69
- "CHARACTER SET #{options[:charset]}" if options[:charset]
69
+ "CHARACTER SET #{@options[:charset]}" if @options[:charset]
70
70
  end
71
71
 
72
72
  def fields
@@ -83,19 +83,19 @@ module LoadDataInfile2
83
83
  end
84
84
 
85
85
  def fields_terminated_by
86
- "TERMINATED BY '#{options[:fields_terminated_by]}'" if options[:fields_terminated_by]
86
+ "TERMINATED BY '#{@options[:fields_terminated_by]}'" if @options[:fields_terminated_by]
87
87
  end
88
88
 
89
89
  def fields_enclosed_by
90
- "ENCLOSED BY '#{options[:fields_enclosed_by]}'" if options[:fields_enclosed_by]
90
+ "ENCLOSED BY '#{@options[:fields_enclosed_by]}'" if @options[:fields_enclosed_by]
91
91
  end
92
92
 
93
93
  def fields_optionally_enclosed_by
94
- "OPTIONALLY ENCLOSED BY '#{options[:fields_optionally_enclosed_by]}'" if options[:fields_optionally_enclosed_by]
94
+ "OPTIONALLY ENCLOSED BY '#{@options[:fields_optionally_enclosed_by]}'" if @options[:fields_optionally_enclosed_by]
95
95
  end
96
96
 
97
97
  def fields_escaped_by
98
- "ESCAPED BY '#{options[:fields_escaped_by]}'" if options[:fields_escaped_by]
98
+ "ESCAPED BY '#{@options[:fields_escaped_by]}'" if @options[:fields_escaped_by]
99
99
  end
100
100
 
101
101
  def lines
@@ -110,24 +110,24 @@ module LoadDataInfile2
110
110
  end
111
111
 
112
112
  def lines_starting_by
113
- "STARTING BY '#{options[:lines_starting_by]}'" if options[:lines_starting_by]
113
+ "STARTING BY '#{@options[:lines_starting_by]}'" if @options[:lines_starting_by]
114
114
  end
115
115
 
116
116
  def lines_terminated_by
117
- "TERMINATED BY '#{options[:lines_terminated_by]}'" if options[:lines_terminated_by]
117
+ "TERMINATED BY '#{@options[:lines_terminated_by]}'" if @options[:lines_terminated_by]
118
118
  end
119
119
 
120
120
  def ignore_lines
121
- "IGNORE #{options[:ignore_lines].to_i} LINES" if options[:ignore_lines].to_i > 0
121
+ "IGNORE #{@options[:ignore_lines].to_i} LINES" if @options[:ignore_lines].to_i > 0
122
122
  end
123
123
 
124
124
  def columns
125
- "(#{options[:columns].join(', ')})" if options[:columns] && options[:columns].size > 0
125
+ "(#{@options[:columns].join(', ')})" if @options[:columns] && @options[:columns].size > 0
126
126
  end
127
127
 
128
128
  def set
129
- if options[:set] && options[:set].size > 0
130
- s = options[:set].map {|col, val| "#{col} = #{val}" }.join(', ')
129
+ if @options[:set] && @options[:set].size > 0
130
+ s = @options[:set].map {|col, val| "#{col} = #{val}" }.join(', ')
131
131
  "SET #{s}"
132
132
  end
133
133
  end
@@ -1,3 +1,3 @@
1
1
  module LoadDataInfile2
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: load_data_infile2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nalabjp