Sha256: 631dbe8e21d6b285dded4c1f0a169f56879d2a3189743ac54ee9d900f0b68e84
Contents?: true
Size: 952 Bytes
Versions: 12
Compression:
Stored size: 952 Bytes
Contents
require 'mysql' 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) mysql = connection.instance_variable_get '@connection' stmt = mysql.prepare("SELECT blob_data FROM #{self.class.table_name} WHERE #{self.class.primary_key}=?") class << stmt include MysqlBlobStreaming attr_accessor :file attr_accessor :logger def handle_data(data) @file << data data = nil GC.start end end stmt.logger = ActiveRecord::Base.logger stmt.logger.debug "Streaming blob from MySQL into #{file.path}" stmt.file = file stmt.execute(id) stmt.stream(1.megabyte) ensure stmt.close if stmt end end end
Version data entries
12 entries across 12 versions & 1 rubygems