Sha256: cfdb0d9ab714f9a5d095d6109514fa652b6e156adf7ed414f5d81a556088fe3a

Contents?: true

Size: 890 Bytes

Versions: 15

Compression:

Stored size: 890 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 = connection.instance_variable_get '@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

15 entries across 15 versions & 1 rubygems

Version Path
infopark_fiona_connector-6.9.4 lib/rails_connector/blob_mysql.rb
infopark_fiona_connector-6.9.3.1.36404185 lib/rails_connector/blob_mysql.rb
infopark_fiona_connector-6.9.2.1.125136549 lib/rails_connector/blob_mysql.rb
infopark_fiona_connector-6.9.1.3.22208381 lib/rails_connector/blob_mysql.rb
infopark_fiona_connector-6.9.0.3.197272233 lib/rails_connector/blob_mysql.rb
infopark_fiona_connector-6.8.3.174.51542603 lib/rails_connector/blob_mysql.rb
infopark_fiona_connector-6.8.3.115.227021242 lib/rails_connector/blob_mysql.rb
infopark_fiona_connector-6.8.3.73.75172665 lib/rails_connector/blob_mysql.rb
infopark_fiona_connector-6.8.3.2.153416031 lib/rails_connector/blob_mysql.rb
infopark_fiona_connector-6.8.3.67.110847540 lib/rails_connector/blob_mysql.rb
infopark_fiona_connector-6.8.3.1.23895778 lib/rails_connector/blob_mysql.rb
infopark_fiona_connector-6.8.2.36.82613853 lib/rails_connector/blob_mysql.rb
infopark_fiona_connector-6.8.2.7.128454143 lib/rails_connector/blob_mysql.rb
infopark_fiona_connector-6.8.1.26.236500544 lib/rails_connector/blob_mysql.rb
infopark_fiona_connector-6.8.1 lib/rails_connector/blob_mysql.rb