Sha256: 85f2fdcdd867655d719750691345521463ee391b7edc0f4f3cd8342aae02fd3d

Contents?: true

Size: 911 Bytes

Versions: 3

Compression:

Stored size: 911 Bytes

Contents

require_relative './queryable'

module CsvFastImporter
  module Database
    class Mysql < Queryable
      identifier_quote_character '`'

      def verify_compatibility(configuration)
        raise 'Transactional not supported with MySQL database' if configuration.transactional_forced?
      end

      def bulk_import(file, table, columns, row_index_column: nil, column_separator:, encoding:)
        columns_list_query = columns.map { |column| identify(column) }.join(',')
        execute <<-SQL
            LOAD DATA LOCAL INFILE '#{File.expand_path(file)}'
            INTO TABLE #{identify(table)}
            CHARACTER SET UTF8
            FIELDS TERMINATED BY '#{column_separator}' OPTIONALLY ENCLOSED BY '"'
            LINES TERMINATED BY '\\n'
            IGNORE 1 LINES
            (#{columns_list_query})
            ;
          SQL
        query('SELECT ROW_COUNT()')
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
csv_fast_importer-1.2.0 lib/csv_fast_importer/database/mysql.rb
csv_fast_importer-1.1.0 lib/csv_fast_importer/database/mysql.rb
csv_fast_importer-1.0.0 lib/csv_fast_importer/database/mysql.rb