activerecord-fast-import 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,4 +3,5 @@
3
3
  coverage
4
4
  rdoc
5
5
  pkg
6
- nbproject/private
6
+ nbproject/private
7
+ .idea
@@ -61,6 +61,15 @@ We want to concatenate those two columns into one.
61
61
 
62
62
  Of course you can use any of those shiny [MySQL functions](http://dev.mysql.com/doc/refman/5.1/en/functions.html).
63
63
 
64
+ ### Extra features - added by Rafal Piekarski
65
+
66
+ This version also provides other "LOAD DATA" features and they are fields in options hash:
67
+
68
+ :insert_method # defines method for inserting data: IGNORE or REPLACE
69
+ :charset_name # defines file charset
70
+ :fields_optionally_enclosed_by # allows you to define fields enclosure method
71
+ :fields_escaped_by # changes the escape character
72
+
64
73
  ## Copyright
65
74
 
66
75
  Copyright (c) 2009 Jan Suchal. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.2.0
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{activerecord-fast-import}
8
- s.version = "0.1.4"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jan Suchal"]
12
- s.date = %q{2009-10-08}
12
+ s.date = %q{2010-02-17}
13
13
  s.description = %q{Native MySQL additions to ActiveRecord, like LOAD DATA INFILE, ENABLE/DISABLE KEYS, TRUNCATE TABLE.}
14
14
  s.email = %q{johno@jsmf.net}
15
15
  s.extra_rdoc_files = [
@@ -55,3 +55,4 @@ Gem::Specification.new do |s|
55
55
  s.add_dependency(%q<activerecord>, [">= 2.1.2"])
56
56
  end
57
57
  end
58
+
@@ -1,5 +1,3 @@
1
- require 'activerecord'
2
-
3
1
  module ActiveRecord #:nodoc:
4
2
  class Base
5
3
  # Deletes all rows in table very fast, but without calling +destroy+ method
@@ -25,16 +23,23 @@ module ActiveRecord #:nodoc:
25
23
  enable_keys
26
24
  end
27
25
 
28
- # Loads data from file using MySQL native LOAD DATA INFILE query, disabling
26
+ # Loads data from file(s) using MySQL native LOAD DATA INFILE query, disabling
29
27
  # key updates for even faster import speed
30
28
  #
31
29
  # ==== Parameters
32
- # * +file+ file(s) to import
30
+ # * +files+ file(s) to import
33
31
  # * +options+ (see <tt>load_data_infile</tt>)
34
32
  def self.fast_import(files, options = {})
35
33
  files = [files] unless files.is_a? Array
36
34
  with_keys_disabled do
37
- files.each {|file| load_data_infile(file, options)}
35
+ load_data_infile_multiple(files, options)
36
+ end
37
+ end
38
+
39
+ # Loads data from multiple files using MySQL native LOAD DATA INFILE query
40
+ def self.load_data_infile_multiple(files, options = {})
41
+ files.each do |file|
42
+ load_data_infile(file, options)
38
43
  end
39
44
  end
40
45
 
@@ -44,8 +49,17 @@ module ActiveRecord #:nodoc:
44
49
  # * +file+ the file to import
45
50
  # * +options+
46
51
  def self.load_data_infile(file, options = {})
47
- sql = "LOAD DATA LOCAL INFILE '#{file}' INTO TABLE #{quoted_table_name} "
48
- sql << "FIELDS TERMINATED BY '#{options[:fields_terminated_by]}' " if options[:fields_terminated_by]
52
+ sql = "LOAD DATA LOCAL INFILE '#{file}' "
53
+ sql << "#{options[:insert_method]} " if options[:insert_method]
54
+ sql << "INTO TABLE #{quoted_table_name} "
55
+ sql << "CHARACTER SET #{options[:charset_name]} " if options[:charset_name]
56
+
57
+ fields = ""
58
+ fields << "TERMINATED BY '#{options[:fields_terminated_by]}' " if options[:fields_terminated_by]
59
+ fields << "OPTIONALLY ENCLOSED BY '#{options[:fields_optionally_enclosed_by]}' " if options[:fields_optionally_enclosed_by]
60
+ fields << "ESCAPED BY '#{options[:fields_escaped_by]}' " if options[:fields_escaped_by]
61
+
62
+ sql << "FIELDS #{fields} " unless fields.empty?
49
63
  sql << "LINES TERMINATED BY '#{options[:lines_terminated_by]}' " if options[:lines_terminated_by]
50
64
  sql << "IGNORE #{options[:ignore_lines]} LINES " if options[:ignore_lines]
51
65
  sql << "(" + options[:columns].join(', ') + ") " if options[:columns]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-fast-import
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Suchal
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-08 00:00:00 +02:00
12
+ date: 2010-02-17 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency