Sha256: 3e4a7efd8cef4b32aacee5c935f71522e8d98f1b18715aea9d6ef0cab8338796
Contents?: true
Size: 961 Bytes
Versions: 6
Compression:
Stored size: 961 Bytes
Contents
require 'mysql' require 'mysql_blob_streaming' module RailsConnector module BlobMysql #:nodoc: 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
6 entries across 6 versions & 1 rubygems