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