Sha256: b89d7859f3e0685e332c573c433292913edb4fb48425172dbee232187dbaf795

Contents?: true

Size: 880 Bytes

Versions: 11

Compression:

Stored size: 880 Bytes

Contents

require "mysql2"
require "mysql_blob_streaming"

module RailsConnector
  module BlobMysql
    def self.included(base)
      base.instance_eval do
        define_method :store_data do
          store_data_atomically { |f| fetch_into_file(f) }
        end
      end
    end

    def fetch_into_file(file)
      mysql2_client = self.class.connection.raw_connection
      ActiveRecord::Base.logger.debug "Streaming blob from MySQL2 into #{file.path}"

      table_name = mysql2_client.escape(self.class.table_name)
      primary_key = mysql2_client.escape(self.class.primary_key)
      escaped_id = mysql2_client.escape(id)
      query = "SELECT `blob_data` FROM `#{table_name}` WHERE `#{primary_key}`='#{escaped_id}'"

      MysqlBlobStreaming.stream(mysql2_client, query, 1.megabyte) do |chunk|
        file << chunk
        chunk = nil
        GC.start
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
infopark_fiona_connector-7.0.1.6.1.6.rc4 lib/rails_connector/blob_mysql.rb
infopark_fiona_connector-7.0.1.6.1.6.rc3 lib/rails_connector/blob_mysql.rb
infopark_fiona_connector-7.0.1.6.1.6.rc2 lib/rails_connector/blob_mysql.rb
infopark_fiona_connector-7.0.1.6.1.6.rc1 lib/rails_connector/blob_mysql.rb
infopark_fiona_connector-7.0.1.5.2.7.rc1 lib/rails_connector/blob_mysql.rb
infopark_fiona_connector-7.0.1.5.2.4.rc2 lib/rails_connector/blob_mysql.rb
infopark_fiona_connector-7.0.1.5.2.4.rc1 lib/rails_connector/blob_mysql.rb
infopark_fiona_connector-7.0.1.5.2.3.rc8 lib/rails_connector/blob_mysql.rb
infopark_fiona_connector-7.0.1.5.2.3.rc7 lib/rails_connector/blob_mysql.rb
infopark_fiona_connector-7.0.1.5.2.3.rc6 lib/rails_connector/blob_mysql.rb
infopark_fiona_connector-7.0.1.5.2.3.rc5 lib/rails_connector/blob_mysql.rb