Class: SpannerLib::Rows

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/spannerlib/rows.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, rows_id) ⇒ Rows

Returns a new instance of Rows.



23
24
25
26
27
# File 'lib/spannerlib/rows.rb', line 23

def initialize(connection, rows_id)
  @connection = connection
  @id = rows_id
  @closed = false
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



21
22
23
# File 'lib/spannerlib/rows.rb', line 21

def connection
  @connection
end

#idObject (readonly)

Returns the value of attribute id.



21
22
23
# File 'lib/spannerlib/rows.rb', line 21

def id
  @id
end

Instance Method Details

#closeObject



60
61
62
63
64
65
# File 'lib/spannerlib/rows.rb', line 60

def close
  return if @closed

  SpannerLib.close_rows(connection.pool_id, connection.conn_id, id)
  @closed = true
end

#eachObject



29
30
31
32
33
34
35
36
37
# File 'lib/spannerlib/rows.rb', line 29

def each
  return enum_for(:each) unless block_given?

  while (row = self.next)
    yield row
  end
ensure
  close
end

#metadataObject



52
53
54
# File 'lib/spannerlib/rows.rb', line 52

def 
  SpannerLib.(connection.pool_id, connection.conn_id, id)
end

#nextObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/spannerlib/rows.rb', line 39

def next
  return nil if @closed

  row_data = SpannerLib.next(connection.pool_id, connection.conn_id, id, 1, 0)

  if row_data.nil? || row_data.empty? || (row_data.respond_to?(:values) && row_data.values.empty?)
    close
    return nil
  end

  row_data
end

#result_set_statsObject



56
57
58
# File 'lib/spannerlib/rows.rb', line 56

def result_set_stats
  SpannerLib.result_set_stats(connection.pool_id, connection.conn_id, id)
end