Class: Google::Cloud::Spanner::ColumnValue

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

Overview

# ColumnValue

Represents a change to be made to a row’s column value by the Spanner API.

Examples:

require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

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

# create column value object
commit_timestamp = db.commit_timestamp

db.commit do |c|
  c.insert "users", [
    { id: 5, name: "Murphy", updated_at: commit_timestamp }
  ]
end

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ ColumnValue

fields in document data.



45
46
47
# File 'lib/google/cloud/spanner/column_value.rb', line 45

def initialize type
  @type = type
end

Class Method Details

.commit_timestampColumnValue

Creates a column value object representing setting a field’s value to the timestamp of the commit. (See Google::Cloud::Spanner::Client#commit_timestamp and Transaction#commit_timestamp)

This placeholder value can only be used for timestamp columns that have set the option “(allow_commit_timestamp=true)” in the schema.

Examples:

require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

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

# create column value object
commit_timestamp = \
  Google::Cloud::Spanner::ColumnValue.commit_timestamp

db.commit do |c|
  c.insert "users", [
    { id: 5, name: "Murphy", updated_at: commit_timestamp }
  ]
end

Returns:

  • (ColumnValue)

    The commit timestamp column value object.



102
103
104
# File 'lib/google/cloud/spanner/column_value.rb', line 102

def self.commit_timestamp
  new :commit_timestamp
end

Instance Method Details

#to_column_valueObject



108
109
110
111
# File 'lib/google/cloud/spanner/column_value.rb', line 108

def to_column_value
  # We only have one ColumnValue, so hard-code this for now.
  "spanner.commit_timestamp()"
end

#typeSymbol

The type of change to make to a row’s column value.

Examples:

require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

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

# create column value object
commit_timestamp = db.commit_timestamp

db.commit do |c|
  c.insert "users", [
    { id: 5, name: "Murphy", updated_at: commit_timestamp }
  ]
end

Returns:

  • (Symbol)

    The type of the column value.



71
72
73
# File 'lib/google/cloud/spanner/column_value.rb', line 71

def type
  @type
end