Cloud Spanner API - Class Google::Cloud::Spanner::Data (v2.14.0)

Reference documentation and code samples for the Cloud Spanner API class Google::Cloud::Spanner::Data.

Data

Represents a row in a result from Cloud Spanner. Provides access to data in a hash-like structure. Values can be retrieved by name (String), or in cases in which values are unnamed, by zero-based index position (Integer).

Inherits

  • Object

Example

require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

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

results = db.execute_query "SELECT * FROM users"

results.rows.each do |row|
  puts "User #{row[:id]} is #{row[:name]}"
end

Methods

#[]

def [](key) -> Object, nil

Returns the value object for the provided name (String) or index (Integer). Do not pass a name to this method if the data has more than one member with the same name.

Parameter
  • key (String, Integer) — The name (String) or zero-based index position (Integer) of the value.
Returns
  • (Object, nil) — The value, or nil if no value is found.
Raises

#fields

def fields() -> Array<Array>

Returns the configuration object (Fields) of the names and types of the data.

Returns
  • (Array<Array>) — An array containing name and value pairs.

#keys

def keys() -> Array<(String,Integer)>

Returns the names of values, or in cases in which values are unnamed, the zero-based index position of values.

Returns
  • (Array<(String,Integer)>) — An array containing the names (String) or position (Integer) for the corresponding values of the data.

#pairs

def pairs() -> Array<Array>

Returns the names or positions and their corresponding values as an array of arrays.

Returns
  • (Array<Array>) — An array containing name/position and value pairs.

#to_a

def to_a(skip_dup_check: nil) -> Array<Object>

Returns the values as an array. This method will raise DuplicateNameError if nested data has more than one member with the same name, unless skip_dup_check is set to true, in which case it will lose values.

Parameter
  • skip_dup_check (Boolean) (defaults to: nil) — Skip the check for whether nested data contains duplicate names, which will improve performance. When skipped, the nested hash may lose values. Default is false. Optional.
Returns
  • (Array<Object>) — An array containing the values of the data.
Raises

#to_h

def to_h(skip_dup_check: nil) -> Hash<(String,Integer)=>Object>

Returns the names or indexes and corresponding values of the data as a hash. This method will raise DuplicateNameError if the data has more than one member with the same name, unless skip_dup_check is set to true, in which case it will lose values.

Parameter
  • skip_dup_check (Boolean) (defaults to: nil) — Skip the check for whether the data contains duplicate names, which will improve performance. When skipped, the returned hash may lose values. Default is false. Optional.
Returns
  • (Hash<(String,Integer)=>Object>) — A hash containing the names or indexes and corresponding values.
Raises

#types

def types() -> Array<Symbol>

Returns the types of the data.

See Data types.

Returns
  • (Array<Symbol>) — An array containing the types of the values.

#values

def values() -> Array<Object>

Returns the values of the data.

Returns
  • (Array<Object>) — An array containing the values.