Class: Google::Cloud::Spanner::Session
- Inherits:
-
Object
- Object
- Google::Cloud::Spanner::Session
- Defined in:
- lib/spanner_client_ext.rb
Class Method Summary collapse
-
.single_use_transaction(opts) ⇒ Object
Create a single-use transaction selector.
Instance Method Summary collapse
- #commit_transaction(transaction, mutations = []) ⇒ Object
- #create_pdml ⇒ Object
- #create_snapshot(strong: nil, timestamp: nil, read_timestamp: nil, staleness: nil, exact_staleness: nil) ⇒ Object
Class Method Details
.single_use_transaction(opts) ⇒ Object
Create a single-use transaction selector.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/spanner_client_ext.rb', line 39 def self.single_use_transaction opts return nil if opts.nil? || opts.empty? = Convert. opts[:read_timestamp] exact_staleness = Convert.number_to_duration opts[:exact_staleness] = Convert. 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_staleness: exact_staleness, min_read_timestamp: , max_staleness: max_staleness, return_read_timestamp: true }.delete_if { |_, v| v.nil? }))) end |
Instance Method Details
#commit_transaction(transaction, mutations = []) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# 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. resp. end |
#create_pdml ⇒ Object
79 80 81 82 83 |
# File 'lib/spanner_client_ext.rb', line 79 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) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# 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: , read_timestamp: , staleness: staleness, exact_staleness: exact_staleness ensure_service! snp_grpc = service.create_snapshot \ path, timestamp: ( || ), staleness: (staleness || exact_staleness) num_args = Snapshot.method(:from_grpc).arity if num_args == 3 Snapshot.from_grpc snp_grpc, self, nil else Snapshot.from_grpc snp_grpc, self end end |