Sha256: f3df60d3a324079fe991f96952ee56ed6cc655b036cf32f3254becce621ade4a
Contents?: true
Size: 1.46 KB
Versions: 1
Compression:
Stored size: 1.46 KB
Contents
require 'active_record/connection_adapters/abstract_adapter' module ActiveRecord module ConnectionAdapters class MysqlAdapter < AbstractAdapter # Execute a truncate statement on the table. Note that in MySQL a truncate will *NOT* reset # the auto_increment def truncate(table_name) execute("TRUNCATE #{table_name}") end # Bulk load the data in the specified file. This implementation always uses the LOCAL keyword # so the file must be found locally, not on the remote server, to be loaded. # # Options: # * <tt>:ignore</tt> -- Ignore the specified number of lines from the source file # * <tt>:columns</tt> -- Array of column names defining the source file column order # * <tt>:fields</tt> -- Hash of options for fields: # ** <tt>:delimited_by</tt> -- The field delimiter # ** <tt>:enclosed_by</tt> -- The field enclosure def bulk_load(file, table_name, options={}) q = "LOAD DATA LOCAL INFILE '#{file}' INTO TABLE #{table_name}" if options[:fields] q << " FIELDS" q << " TERMINATED BY '#{options[:fields][:delimited_by]}'" if options[:fields][:delimited_by] q << " ENCLOSED BY '#{options[:fields][:enclosed_by]}'" if options[:fields][:enclosed_by] end q << " IGNORE #{options[:ignore]} LINES" if options[:ignore] q << " (#{options[:columns].join(',')})" if options[:columns] execute(q) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
activewarehouse-etl-0.4.0 | lib/etl/active_record_ext/connection_adapters/mysql_adapter.rb |