Class: Google::Cloud::Spanner::BatchWrite

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/spanner/batch_write.rb

Overview

Part of the BatchWrite DSL.

This object is passed as a parameter to the block passed to Client#batch_write. Use this parameter to add mutation groups to the batch.

Instance Method Summary collapse

Instance Method Details

#mutation_group {|mg| ... } ⇒ Object

Adds a group of mutations

Examples:

require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

db = spanner.client "my-instance", "my-database"

results = db.batch_write do |b|
  # First mutation group
  b.mutation_group do |mg|
    mg.upsert "Singers", [{ SingerId: 16, FirstName: "Charlie", LastName: "Terry" }]
  end

  # Second mutation group
  b.mutation_group do |mg|
    mg.upsert "Singers", [{ SingerId: 17, FirstName: "Catalina", LastName: "Smith" }]
    mg.update "Albums", [{ SingerId: 17, AlbumId: 1, AlbumTitle: "Go Go Go" }]
  end
end

Yields:

  • (mg)


57
58
59
60
61
# File 'lib/google/cloud/spanner/batch_write.rb', line 57

def mutation_group
  mg = MutationGroup.new
  yield mg
  @mutation_groups << mg
end