Class: Google::Cloud::Spanner::BatchWriteResults

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/google/cloud/spanner/batch_write_results.rb

Overview

Results of a batch write.

This is a stream of BatchResult objects, each of which represents a set of mutation groups applied together.

Use the Ruby Enumerable module to iterate over the results.

Defined Under Namespace

Classes: BatchResult

Instance Method Summary collapse

Instance Method Details

#each {|::Google::Cloud::Spanner::BatchWriteResults::BatchResult| ... } ⇒ Object

Iterate over the results.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/google/cloud/spanner/batch_write_results.rb', line 95

def each &block
  if defined? @results
    @results.each(&block)
  else
    results = []
    @enumerable.each do |grpc|
      result = BatchResult.new grpc
      results << result
      yield result
    end
    @results = results
  end
rescue GRPC::BadStatus => e
  raise Google::Cloud::Error.from_error(e)
end

#error?::Boolean

Whether at least one mutation group encountered an error.

Returns:

  • (::Boolean)


127
128
129
# File 'lib/google/cloud/spanner/batch_write_results.rb', line 127

def error?
  !ok?
end

#ok?::Boolean

Whether all mutation groups were successful.

Returns:

  • (::Boolean)


118
119
120
# File 'lib/google/cloud/spanner/batch_write_results.rb', line 118

def ok?
  all?(&:ok?)
end

#successful_indexes::Array<::Integer>

A list of the indexes of successful mutation groups.

Returns:

  • (::Array<::Integer>)


136
137
138
# File 'lib/google/cloud/spanner/batch_write_results.rb', line 136

def successful_indexes
  flat_map { |batch_result| batch_result.ok? ? batch_result.indexes : [] }
end