Class Transaction

A transaction is a set of Datastore operations on one or more entities. Each transaction is guaranteed to be atomic, which means that transactions are never partially applied. Either all of the operations in the transaction are applied, or none of them are applied.

[Transactions Reference]https://cloud.google.com/datastore/docs/concepts/transactions

{Request}

Inheritance

DatastoreRequest > Transaction

Package

@google-cloud/datastore!

Constructors

(constructor)(datastore, options)

constructor(datastore: Datastore, options?: TransactionOptions);

Constructs a new instance of the Transaction class

Parameters
Type Name Description
Datastore datastore
TransactionOptions options

Properties

modifiedEntities_

modifiedEntities_: ModifiedEntities;
Property Value
Type Description
ModifiedEntities

namespace

namespace?: string;
Property Value
Type Description
string

readOnly

readOnly: boolean;
Property Value
Type Description
boolean

request

request: Function;
Property Value
Type Description
Function

skipCommit

skipCommit?: boolean;
Property Value
Type Description
boolean

Methods

commit(gaxOptions)

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

commit(callback)

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

commit(gaxOptions, callback)

commit(gaxOptions: CallOptions, callback: CommitCallback): void;
Parameters
Type Name Description
CallOptions gaxOptions
CommitCallback callback
Returns
Type Description
void

createQuery(kind)

createQuery(kind?: string): Query;
Parameter
Type Name Description
string kind
Returns
Type Description
Query

createQuery(kind)

createQuery(kind?: string[]): Query;
Parameter
Type Name Description
string[] kind
Returns
Type Description
Query

createQuery(namespace, kind)

createQuery(namespace: string, kind: string): Query;
Parameters
Type Name Description
string namespace
string kind
Returns
Type Description
Query

createQuery(namespace, kind)

createQuery(namespace: string, kind: string[]): Query;
Parameters
Type Name Description
string namespace
string[] kind
Returns
Type Description
Query

delete(entities)

delete(entities?: Entities): any;

Delete all entities identified with the specified key(s) in the current transaction.

Parameter
Type Name Description
Entities entities
Returns
Type Description
any

insert(entities)

insert(entities: Entities): void;

Maps to , forcing the method to be insert.

Parameter
Type Name Description
Entities entities

Datastore key object(s).

Returns
Type Description
void

rollback(callback)

rollback(callback: RollbackCallback): void;
Parameter
Type Name Description
RollbackCallback callback
Returns
Type Description
void

rollback(gaxOptions)

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

rollback(gaxOptions, callback)

rollback(gaxOptions: CallOptions, callback: RollbackCallback): void;
Parameters
Type Name Description
CallOptions gaxOptions
RollbackCallback callback
Returns
Type Description
void

run(options)

run(options?: RunOptions): Promise<RunResponse>;
Parameter
Type Name Description
RunOptions options
Returns
Type Description
Promise<RunResponse>

run(callback)

run(callback: RunCallback): void;
Parameter
Type Name Description
RunCallback callback
Returns
Type Description
void

run(options, callback)

run(options: RunOptions, callback: RunCallback): void;
Parameters
Type Name Description
RunOptions options
RunCallback callback
Returns
Type Description
void

save(entities)

save(entities: Entities): void;

Insert or update the specified object(s) in the current transaction. If a key is incomplete, its associated object is inserted and the original Key object is updated to contain the generated ID.

This method will determine the correct Datastore method to execute (upsert, insert, or update) by using the key(s) provided. For example, if you provide an incomplete key (one without an ID), the request will create a new entity and have its ID automatically assigned. If you provide a complete key, the entity will be updated with the data specified.

By default, all properties are indexed. To prevent a property from being included in *all* indexes, you must supply an excludeFromIndexes array. See below for an example.

Parameter
Type Name Description
Entities entities

Datastore key object(s).

Returns
Type Description
void

update(entities)

update(entities: Entities): void;

Maps to , forcing the method to be update.

Parameter
Type Name Description
Entities entities

Datastore key object(s).

Returns
Type Description
void

upsert(entities)

upsert(entities: Entities): void;

Maps to , forcing the method to be upsert.

Parameter
Type Name Description
Entities entities

Datastore key object(s).

Returns
Type Description
void