Class: Google::Cloud::Spanner::CommitResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/spanner/commit_response.rb,
lib/google/cloud/spanner/commit_response/commit_stats.rb

Overview

CommitResponse is a timestamp at which the transaction committed with additional attributes of commit stats.

Examples:

require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

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

timestamp = db.commit do |c|
  c.update "users", [{ id: 1, name: "Charlie", active: false }]
  c.insert "users", [{ id: 2, name: "Harvey",  active: true }]
end

puts timestamp

With commit stats.

require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

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

commit_options = { return_commit_stats: true }
commit_resp = db.commit commit_options: commit_options do |c|
  c.update "users", [{ id: 1, name: "Charlie", active: false }]
  c.insert "users", [{ id: 2, name: "Harvey",  active: true }]
end

puts commit_resp.timestamp
puts commit_resp.stats.mutation_count

Defined Under Namespace

Classes: CommitStats

Instance Method Summary collapse

Instance Method Details

#statsCommitStats?

Additional statistics about a commit.

Returns:

  • (CommitStats, nil)

    Commit stats or nil if not stats not present.


73
74
75
# File 'lib/google/cloud/spanner/commit_response.rb', line 73

def stats
  CommitStats.from_grpc @grpc.commit_stats if @grpc.commit_stats
end

#timestampTime

The timestamp at which the transaction committed.

Returns:

  • (Time)

65
66
67
# File 'lib/google/cloud/spanner/commit_response.rb', line 65

def timestamp
  Convert.timestamp_to_time @grpc.commit_timestamp
end