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.
- key (String, Integer) — The name (String) or zero-based index position (Integer) of the value.
- (Object, nil) — The value, or nil if no value is found.
- (Google::Cloud::Spanner::DuplicateNameError) — if the data contains duplicate names.
#fields
def fields() -> Array<Array>
Returns the configuration object (Fields) of the names and types of the data.
- (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.
- (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.
- (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.
-
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.
- (Array<Object>) — An array containing the values of the data.
- (Google::Cloud::Spanner::DuplicateNameError) — if nested data contains duplicate names.
#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.
-
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.
- (Hash<(String,Integer)=>Object>) — A hash containing the names or indexes and corresponding values.
- (Google::Cloud::Spanner::DuplicateNameError) — if the data contains duplicate names.
#types
def types() -> Array<Symbol>
- (Array<Symbol>) — An array containing the types of the values.
#values
def values() -> Array<Object>
Returns the values of the data.
- (Array<Object>) — An array containing the values.