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
TypeNameDescription
Datastoredatastore
TransactionOptionsoptions

Properties

modifiedEntities_

modifiedEntities_: ModifiedEntities;
Property Value
TypeDescription
ModifiedEntities

namespace

namespace?: string;
Property Value
TypeDescription
string

readOnly

readOnly: boolean;
Property Value
TypeDescription
boolean

request

request: Function;
Property Value
TypeDescription
Function

skipCommit

skipCommit?: boolean;
Property Value
TypeDescription
boolean

Methods

commit(gaxOptions)

commit(gaxOptions?: CallOptions): Promise<CommitResponse>;
Parameter
TypeNameDescription
CallOptionsgaxOptions
Returns
TypeDescription
Promise<CommitResponse>

commit(callback)

commit(callback: CommitCallback): void;
Parameter
TypeNameDescription
CommitCallbackcallback
Returns
TypeDescription
void

commit(gaxOptions, callback)

commit(gaxOptions: CallOptions, callback: CommitCallback): void;
Parameters
TypeNameDescription
CallOptionsgaxOptions
CommitCallbackcallback
Returns
TypeDescription
void

createQuery(kind)

createQuery(kind?: string): Query;
Parameter
TypeNameDescription
stringkind
Returns
TypeDescription
Query

createQuery(kind)

createQuery(kind?: string[]): Query;
Parameter
TypeNameDescription
string[]kind
Returns
TypeDescription
Query

createQuery(namespace, kind)

createQuery(namespace: string, kind: string): Query;
Parameters
TypeNameDescription
stringnamespace
stringkind
Returns
TypeDescription
Query

createQuery(namespace, kind)

createQuery(namespace: string, kind: string[]): Query;
Parameters
TypeNameDescription
stringnamespace
string[]kind
Returns
TypeDescription
Query

delete(entities)

delete(entities?: Entities): any;

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

Parameter
TypeNameDescription
Entitiesentities
Returns
TypeDescription
any

insert(entities)

insert(entities: Entities): void;

Maps to , forcing the method to be insert.

Parameter
TypeNameDescription
Entitiesentities

Datastore key object(s).

Returns
TypeDescription
void

rollback(callback)

rollback(callback: RollbackCallback): void;
Parameter
TypeNameDescription
RollbackCallbackcallback
Returns
TypeDescription
void

rollback(gaxOptions)

rollback(gaxOptions?: CallOptions): Promise<RollbackResponse>;
Parameter
TypeNameDescription
CallOptionsgaxOptions
Returns
TypeDescription
Promise<RollbackResponse>

rollback(gaxOptions, callback)

rollback(gaxOptions: CallOptions, callback: RollbackCallback): void;
Parameters
TypeNameDescription
CallOptionsgaxOptions
RollbackCallbackcallback
Returns
TypeDescription
void

run(options)

run(options?: RunOptions): Promise<RunResponse>;
Parameter
TypeNameDescription
RunOptionsoptions
Returns
TypeDescription
Promise<RunResponse>

run(callback)

run(callback: RunCallback): void;
Parameter
TypeNameDescription
RunCallbackcallback
Returns
TypeDescription
void

run(options, callback)

run(options: RunOptions, callback: RunCallback): void;
Parameters
TypeNameDescription
RunOptionsoptions
RunCallbackcallback
Returns
TypeDescription
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
TypeNameDescription
Entitiesentities

Datastore key object(s).

Returns
TypeDescription
void

update(entities)

update(entities: Entities): void;

Maps to , forcing the method to be update.

Parameter
TypeNameDescription
Entitiesentities

Datastore key object(s).

Returns
TypeDescription
void

upsert(entities)

upsert(entities: Entities): void;

Maps to , forcing the method to be upsert.

Parameter
TypeNameDescription
Entitiesentities

Datastore key object(s).

Returns
TypeDescription
void