Class Transaction

This type of transaction is the only way to write data into Cloud Spanner. These transactions rely on pessimistic locking and, if necessary, two-phase commit. Locking read-write transactions may abort, requiring the application to retry.

Calling either or signals that the transaction is finished and no further requests will be made. If for some reason you decide not to call one of the aformentioned methods, call to release the underlying Session .

Running a transaction via or automatically re-runs the transaction on ABORTED errors.

returns a plain Transaction object, requiring the user to retry manually.

Snapshot

Inheritance

Dml > Transaction

Package

@google-cloud/spanner!

Constructors

(constructor)(session, options, queryOptions)

  constructor 
 ( 
 session 
 : 
  
 Session 
 , 
  
 options 
 ?: 
  
 spannerClient 
 . 
 spanner 
 . 
 v1 
 . 
 TransactionOptions 
 . 
 ReadWrite 
 , 
  
 queryOptions 
 ?: 
  
 IQueryOptions 
 ); 
 

Execute a DML statement and get the affected row count.

Transaction#runUpdate

Parameters
Type Name Description
session
spannerClient.spanner.v1.TransactionOptions.ReadWrite
options
google.spanner.v1.ExecuteSqlRequest.IQueryOptions
queryOptions

Properties

commitTimestamp

  commitTimestamp 
 ?: 
  
 PreciseDate 
 ; 
 
Property Value
Type Description
PreciseDate

commitTimestampProto

  commitTimestampProto 
 ?: 
  
 spannerClient 
 . 
 protobuf 
 . 
 ITimestamp 
 ; 
 
Property Value
Type Description
ITimestamp

Methods

batchUpdate(queries, options)

  batchUpdate 
 ( 
 queries 
 : 
  
 Array<string 
  
 | 
  
 Statement 
> , 
  
 options 
 ?: 
  
 BatchUpdateOptions 
  
 | 
  
 CallOptions 
 ) 
 : 
  
 Promise<BatchUpdateResponse> 
 ; 
 
Parameters
Type Name Description
Array <string | Statement >
queries
BatchUpdateOptions | CallOptions
options
Returns
Type Description
Promise < BatchUpdateResponse >

batchUpdate(queries, callback)

  batchUpdate 
 ( 
 queries 
 : 
  
 Array<string 
  
 | 
  
 Statement 
> , 
  
 callback 
 : 
  
 BatchUpdateCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameters
Type Name Description
Array <string | Statement >
queries
BatchUpdateCallback
callback
Returns
Type Description
void

batchUpdate(queries, options, callback)

  batchUpdate 
 ( 
 queries 
 : 
  
 Array<string 
  
 | 
  
 Statement 
> , 
  
 options 
 : 
  
 BatchUpdateOptions 
  
 | 
  
 CallOptions 
 , 
  
 callback 
 : 
  
 BatchUpdateCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameters
Type Name Description
Array <string | Statement >
queries
BatchUpdateOptions | CallOptions
options
BatchUpdateCallback
callback
Returns
Type Description
void

commit(options)

  commit 
 ( 
 options 
 ?: 
  
 CommitOptions 
  
 | 
  
 CallOptions 
 ) 
 : 
  
 Promise<CommitResponse> 
 ; 
 
Parameter
Type Name Description
CommitOptions | CallOptions
options
Returns
Type Description
Promise < CommitResponse >

commit(callback)

  commit 
 ( 
 callback 
 : 
  
 CommitCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameter
Type Name Description
CommitCallback
callback
Returns
Type Description
void

commit(options, callback)

  commit 
 ( 
 options 
 : 
  
 CommitOptions 
  
 | 
  
 CallOptions 
 , 
  
 callback 
 : 
  
 CommitCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameters
Type Name Description
CommitOptions | CallOptions
options
CommitCallback
callback
Returns
Type Description
void

deleteRows(table, keys)

  deleteRows 
 ( 
 table 
 : 
  
 string 
 , 
  
 keys 
 : 
  
 Key 
 []) 
 : 
  
 void 
 ; 
 

Delete rows from a table.

[Commit API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.Commit)

Parameters
Type Name Description
string
table

The name of the table.

Key []
keys

The keys for the rows to delete. If using a composite key, provide an array within this array. See the example below.

Returns
Type Description
void

getUniqueKeys(rows)

  static 
  
 getUniqueKeys 
 ( 
 rows 
 : 
  
 object 
 []) 
 : 
  
 string 
 []; 
 

Takes a list of rows and returns all unique column names.

Parameter
Type Name Description
object[]
rows

The rows.

Returns
Type Description
string[]

{string[]}

insert(table, rows)

  insert 
 ( 
 table 
 : 
  
 string 
 , 
  
 rows 
 : 
  
 object 
  
 | 
  
 object 
 []) 
 : 
  
 void 
 ; 
 

Insert rows of data into this table.

[Commit API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.Commit)

Parameters
Type Name Description
string
table

The name of the table.

object | object[]
rows

A map of names to values of data to insert into this table.

Returns
Type Description
void

replace(table, rows)

  replace 
 ( 
 table 
 : 
  
 string 
 , 
  
 rows 
 : 
  
 object 
  
 | 
  
 object 
 []) 
 : 
  
 void 
 ; 
 

Replace rows of data within a table.

[Commit API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.Commit)

Parameters
Type Name Description
string
table

The table to read from.

object | object[]
rows

A map of names to values of data to insert into this table.

Returns
Type Description
void

rollback(gaxOptions)

  rollback 
 ( 
 gaxOptions 
 ?: 
  
 CallOptions 
 ) 
 : 
  
 Promise<void> 
 ; 
 
Parameter
Type Name Description
CallOptions
gaxOptions
Returns
Type Description
Promise <void>

rollback(callback)

  rollback 
 ( 
 callback 
 : 
  
 spannerClient 
 . 
 spanner 
 . 
 v1 
 . 
 Spanner 
 . 
 RollbackCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameter
Type Name Description
google.spanner.v1.Spanner.RollbackCallback
callback
Returns
Type Description
void

rollback(gaxOptions, callback)

  rollback 
 ( 
 gaxOptions 
 : 
  
 CallOptions 
 , 
  
 callback 
 : 
  
 spannerClient 
 . 
 spanner 
 . 
 v1 
 . 
 Spanner 
 . 
 RollbackCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameters
Type Name Description
CallOptions
gaxOptions
google.spanner.v1.Spanner.RollbackCallback
callback
Returns
Type Description
void

update(table, rows)

  update 
 ( 
 table 
 : 
  
 string 
 , 
  
 rows 
 : 
  
 object 
  
 | 
  
 object 
 []) 
 : 
  
 void 
 ; 
 

Update rows of data within a table.

[Commit API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.Commit)

Parameters
Type Name Description
string
table

The table to read from.

object | object[]
rows

A map of names to values of data to insert into this table.

Returns
Type Description
void

upsert(table, rows)

  upsert 
 ( 
 table 
 : 
  
 string 
 , 
  
 rows 
 : 
  
 object 
  
 | 
  
 object 
 []) 
 : 
  
 void 
 ; 
 

Insert or update rows of data within a table.

[Commit API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.Commit)

Parameters
Type Name Description
string
table

The table to read from.

object | object[]
rows

A map of names to values of data to insert into this table.

Returns
Type Description
void
Design a Mobile Site
View Site in Mobile | Classic
Share by: