Sha256: 351b14ba4f1a1a4999a3af81e911aefde08a50bf8ffa77009948ba8e3822ba90
Contents?: true
Size: 1.5 KB
Versions: 2
Compression:
Stored size: 1.5 KB
Contents
# Source code for the PostgreSQLAdapter extensions. module ActiveRecord #:nodoc: module ConnectionAdapters #:nodoc: # Adds new functionality to ActiveRecord PostgreSQLAdapter. class PostgreSQLAdapter < AbstractAdapter protected # Call +bulk_load+, as that method wraps this method. # # Bulk load the data in the specified file. # # Options: # * <tt>:ignore</tt> -- Ignore the specified number of lines from the source file. In the case of PostgreSQL # only the first line will be ignored from the source file regardless of the number of lines specified. # * <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 do_bulk_load(file, table_name, options={}) q = "COPY #{table_name} " q << "(#{options[:columns].join(',')}) " if options[:columns] q << "FROM '#{File.expand_path(file)}' " if options[:fields] q << "WITH " q << "DELIMITER '#{options[:fields][:delimited_by]}' " if options[:fields][:delimited_by] if options[:fields][:enclosed_by] q << "CSV " q << "HEADER " if options[:ignore] > 0 q << "QUOTE '#{options[:fields][:enclosed_by]}' " if options[:fields][:enclosed_by] end end execute(q) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
adapter_extensions-0.3.0 | lib/adapter_extensions/connection_adapters/postgresql_adapter.rb |
adapter_extensions-0.3.1 | lib/adapter_extensions/connection_adapters/postgresql_adapter.rb |