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 > TransactionPackage
@google-cloud/spanner!Constructors
(constructor)(session, options, queryOptions, requestOptions)
constructor
(
session
:
Session
,
options
?:
spannerClient
.
spanner
.
v1
.
TransactionOptions
.
ReadWrite
,
queryOptions
?:
IQueryOptions
,
requestOptions
?:
Pick<IRequestOptions
,
'transactionTag'
> );
Execute a DML statement and get the affected row count.
Transaction#runUpdate
Type | Name | Description |
---|---|---|
session | ||
spannerClient.spanner.v1.TransactionOptions.ReadWrite
|
options | |
spannerClient.spanner.v1.ExecuteSqlRequest.IQueryOptions
|
queryOptions | |
Pick
< google.spanner.v1.IRequestOptions
, 'transactionTag'>
|
requestOptions |
Properties
commitTimestamp
commitTimestamp
?:
PreciseDate
;
Type | Description |
---|---|
PreciseDate |
commitTimestampProto
commitTimestampProto
?:
spannerClient
.
protobuf
.
ITimestamp
;
Type | Description |
---|---|
ITimestamp |
Methods
batchUpdate(queries, options)
batchUpdate
(
queries
:
Array<string
|
Statement
> ,
options
?:
BatchUpdateOptions
|
CallOptions
)
:
Promise<BatchUpdateResponse>
;
Type | Name | Description |
---|---|---|
Array
<string | Statement
>
|
queries | |
BatchUpdateOptions
| CallOptions
|
options |
Type | Description |
---|---|
Promise < BatchUpdateResponse > |
batchUpdate(queries, callback)
batchUpdate
(
queries
:
Array<string
|
Statement
> ,
callback
:
BatchUpdateCallback
)
:
void
;
Type | Name | Description |
---|---|---|
Array
<string | Statement
>
|
queries | |
BatchUpdateCallback
|
callback |
Type | Description |
---|---|
void |
batchUpdate(queries, options, callback)
batchUpdate
(
queries
:
Array<string
|
Statement
> ,
options
:
BatchUpdateOptions
|
CallOptions
,
callback
:
BatchUpdateCallback
)
:
void
;
Type | Name | Description |
---|---|---|
Array
<string | Statement
>
|
queries | |
BatchUpdateOptions
| CallOptions
|
options | |
BatchUpdateCallback
|
callback |
Type | Description |
---|---|
void |
commit(options)
commit
(
options
?:
CommitOptions
|
CallOptions
)
:
Promise<CommitResponse>
;
Type | Name | Description |
---|---|---|
CommitOptions
| CallOptions
|
options |
Type | Description |
---|---|
Promise < CommitResponse > |
commit(callback)
commit
(
callback
:
CommitCallback
)
:
void
;
Type | Name | Description |
---|---|---|
CommitCallback
|
callback |
Type | Description |
---|---|
void |
commit(options, callback)
commit
(
options
:
CommitOptions
|
CallOptions
,
callback
:
CommitCallback
)
:
void
;
Type | Name | Description |
---|---|---|
CommitOptions
| CallOptions
|
options | |
CommitCallback
|
callback |
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)
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. |
Type | Description |
---|---|
void |
getUniqueKeys(rows)
static
getUniqueKeys
(
rows
:
object
[])
:
string
[];
Takes a list of rows and returns all unique column names.
Type | Name | Description |
---|---|---|
object[]
|
rows | The rows. |
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)
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. |
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)
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. |
Type | Description |
---|---|
void |
rollback(gaxOptions)
rollback
(
gaxOptions
?:
CallOptions
)
:
Promise<void>
;
Type | Name | Description |
---|---|---|
CallOptions
|
gaxOptions |
Type | Description |
---|---|
Promise <void> |
rollback(callback)
rollback
(
callback
:
spannerClient
.
spanner
.
v1
.
Spanner
.
RollbackCallback
)
:
void
;
Type | Name | Description |
---|---|---|
google.spanner.v1.Spanner.RollbackCallback
|
callback |
Type | Description |
---|---|
void |
rollback(gaxOptions, callback)
rollback
(
gaxOptions
:
CallOptions
,
callback
:
spannerClient
.
spanner
.
v1
.
Spanner
.
RollbackCallback
)
:
void
;
Type | Name | Description |
---|---|---|
CallOptions
|
gaxOptions | |
google.spanner.v1.Spanner.RollbackCallback
|
callback |
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)
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. |
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)
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. |
Type | Description |
---|---|
void |