Sha256: ae951a146169ac56280e6973fdc9a80a092e401f16082e63400f116d2c152b9d

Contents?: true

Size: 828 Bytes

Versions: 3

Compression:

Stored size: 828 Bytes

Contents

module Seedy
  class DatabaseBuffer < AbstractBuffer
    @@limit  = 1000
    class << self
      def flush
        begin_db_transaction
        @@buffer.length.times {
          record = @@buffer.shift
          execute(record.to_sql)
        }
        commit_db_transaction
      end
      def begin_db_transaction #:nodoc:
        execute "BEGIN"
      rescue Exception
        # Transactions aren't supported
      end

      def commit_db_transaction #:nodoc:
        execute "COMMIT"
      rescue Exception
        # Transactions aren't supported
      end

      def rollback_db_transaction #:nodoc:
        execute "ROLLBACK"
      rescue Exception
        # Transactions aren't supported
      end
      
      def execute(sql)
        puts sql
        Seedy.connection.query(sql) 
      end      
    end
    
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
seedy-0.6.6 lib/seedy/buffer/database_buffer.rb
seedy-0.6.5 lib/seedy/buffer/database_buffer.rb
seedy-0.6.4 lib/seedy/buffer/database_buffer.rb