Class: Backfiller::Cursor::Postgresql
- Inherits:
-
Object
- Object
- Backfiller::Cursor::Postgresql
- Defined in:
- lib/backfiller/cursor/postgresql.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #close ⇒ Object
- #fetch(count) ⇒ Object
-
#initialize(connection, name, query) ⇒ Postgresql
constructor
A new instance of Postgresql.
- #open ⇒ Object
-
#transaction ⇒ Object
Open cursor, call black and close cursor in transaction.
Constructor Details
#initialize(connection, name, query) ⇒ Postgresql
Returns a new instance of Postgresql.
8 9 10 11 12 |
# File 'lib/backfiller/cursor/postgresql.rb', line 8 def initialize(connection, name, query) @connection = connection @name = name @query = query end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
6 7 8 |
# File 'lib/backfiller/cursor/postgresql.rb', line 6 def connection @connection end |
Instance Method Details
#close ⇒ Object
41 42 43 |
# File 'lib/backfiller/cursor/postgresql.rb', line 41 def close @connection.execute "CLOSE #{@name}" end |
#fetch(count) ⇒ Object
37 38 39 |
# File 'lib/backfiller/cursor/postgresql.rb', line 37 def fetch(count) @connection.select_all "FETCH #{count} FROM #{@name}" end |
#open ⇒ Object
33 34 35 |
# File 'lib/backfiller/cursor/postgresql.rb', line 33 def open @connection.execute "DECLARE #{@name} NO SCROLL CURSOR WITHOUT HOLD FOR #{@query}" end |
#transaction ⇒ Object
Open cursor, call black and close cursor in transaction.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/backfiller/cursor/postgresql.rb', line 17 def transaction result = nil @connection.transaction do Backfiller.log 'Open cursor' open result = yield Backfiller.log 'Close cursor' close end result end |