Class: Seedy::DatabaseBuffer

Inherits:
AbstractBuffer show all
Defined in:
lib/seedy/buffer/database_buffer.rb

Constant Summary collapse

@@limit =
1000

Class Method Summary collapse

Methods inherited from AbstractBuffer

<<

Class Method Details

.begin_db_transactionObject

:nodoc:



13
14
15
16
17
# File 'lib/seedy/buffer/database_buffer.rb', line 13

def begin_db_transaction #:nodoc:
  execute "BEGIN"
rescue Exception
  # Transactions aren't supported
end

.commit_db_transactionObject

:nodoc:



19
20
21
22
23
# File 'lib/seedy/buffer/database_buffer.rb', line 19

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

.execute(sql) ⇒ Object



31
32
33
34
# File 'lib/seedy/buffer/database_buffer.rb', line 31

def execute(sql)
  puts sql
  Seedy.connection.query(sql) 
end

.flushObject



5
6
7
8
9
10
11
12
# File 'lib/seedy/buffer/database_buffer.rb', line 5

def flush
  begin_db_transaction
  @@buffer.length.times {
    record = @@buffer.shift
    execute(record.to_sql)
  }
  commit_db_transaction
end

.rollback_db_transactionObject

:nodoc:



25
26
27
28
29
# File 'lib/seedy/buffer/database_buffer.rb', line 25

def rollback_db_transaction #:nodoc:
  execute "ROLLBACK"
rescue Exception
  # Transactions aren't supported
end