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