class Google::Cloud::Spanner::Session
Public Class Methods
single_use_transaction(opts)
click to toggle source
Create a single-use transaction selector.
# File lib/spanner_client_ext.rb, line 39 def self.single_use_transaction opts return nil if opts.nil? || opts.empty? exact_timestamp = Convert.time_to_timestamp opts[:read_timestamp] exact_staleness = Convert.number_to_duration opts[:exact_staleness] min_read_timestamp = Convert.time_to_timestamp opts[:min_read_timestamp] max_staleness = Convert.number_to_duration opts[:max_staleness] V1::TransactionSelector.new(single_use: V1::TransactionOptions.new(read_only: V1::TransactionOptions::ReadOnly.new({ strong: opts[:strong], read_timestamp: exact_timestamp, exact_staleness: exact_staleness, min_read_timestamp: min_read_timestamp, max_staleness: max_staleness, return_read_timestamp: true }.delete_if { |_, v| v.nil? }))) end
Public Instance Methods
commit_transaction(transaction, mutations = [])
click to toggle source
# File lib/spanner_client_ext.rb, line 26 def commit_transaction transaction, mutations = [] ensure_service! resp = service.commit( path, mutations, transaction_id: transaction.transaction_id ) @last_updated_at = Time.now Convert.timestamp_to_time resp.commit_timestamp end
create_pdml()
click to toggle source
# File lib/spanner_client_ext.rb, line 74 def create_pdml ensure_service! pdml_grpc = service.create_pdml path Transaction.from_grpc pdml_grpc, self end
create_snapshot(strong: nil, timestamp: nil, read_timestamp: nil, staleness: nil, exact_staleness: nil)
click to toggle source
# File lib/spanner_client_ext.rb, line 59 def create_snapshot strong: nil, timestamp: nil, read_timestamp: nil, staleness: nil, exact_staleness: nil validate_snapshot_args! strong: strong, timestamp: timestamp, read_timestamp: read_timestamp, staleness: staleness, exact_staleness: exact_staleness ensure_service! snp_grpc = service.create_snapshot \ path, timestamp: (timestamp || read_timestamp), staleness: (staleness || exact_staleness) Snapshot.from_grpc snp_grpc, self end
Private Instance Methods
validate_snapshot_args!(strong: nil, timestamp: nil, read_timestamp: nil, staleness: nil, exact_staleness: nil)
click to toggle source
Check for valid snapshot arguments
# File lib/spanner_client_ext.rb, line 84 def validate_snapshot_args! strong: nil, timestamp: nil, read_timestamp: nil, staleness: nil, exact_staleness: nil valid_args_count = [ strong, timestamp, read_timestamp, staleness, exact_staleness ].compact.count return true if valid_args_count <= 1 raise ArgumentError, "Can only provide one of the following arguments: " \ "(strong, timestamp, read_timestamp, staleness, " \ "exact_staleness)" end