Class: Backfiller::Cursor::Postgresql

Inherits:
Object
  • Object
show all
Defined in:
lib/backfiller/cursor/postgresql.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#connectionObject (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

#closeObject



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

#openObject



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

#transactionObject

Open cursor, call black and close cursor in transaction.

Returns:

  • (Object)

    yielded block result.



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