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

{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
NameDescription
datastore Datastore
options TransactionOptions

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
NameDescription
gaxOptions CallOptions
Returns
TypeDescription
Promise<CommitResponse>

commit(callback)

commit(callback: CommitCallback): void;
Parameter
NameDescription
callback CommitCallback
Returns
TypeDescription
void

commit(gaxOptions, callback)

commit(gaxOptions: CallOptions, callback: CommitCallback): void;
Parameters
NameDescription
gaxOptions CallOptions
callback CommitCallback
Returns
TypeDescription
void

createQuery(kind)

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

createQuery(kind)

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

createQuery(namespace, kind)

createQuery(namespace: string, kind: string): Query;
Parameters
NameDescription
namespace string
kind string
Returns
TypeDescription
Query

createQuery(namespace, kind)

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

delete(entities)

delete(entities?: Entities): any;

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

Parameter
NameDescription
entities Entities
Returns
TypeDescription
any

insert(entities)

insert(entities: Entities): void;

Maps to , forcing the method to be insert.

Parameter
NameDescription
entities Entities

Datastore key object(s).

Returns
TypeDescription
void

rollback(callback)

rollback(callback: RollbackCallback): void;
Parameter
NameDescription
callback RollbackCallback
Returns
TypeDescription
void

rollback(gaxOptions)

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

rollback(gaxOptions, callback)

rollback(gaxOptions: CallOptions, callback: RollbackCallback): void;
Parameters
NameDescription
gaxOptions CallOptions
callback RollbackCallback
Returns
TypeDescription
void

run(options)

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

run(callback)

run(callback: RunCallback): void;
Parameter
NameDescription
callback RunCallback
Returns
TypeDescription
void

run(options, callback)

run(options: RunOptions, callback: RunCallback): void;
Parameters
NameDescription
options RunOptions
callback RunCallback
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
NameDescription
entities Entities

Datastore key object(s).

Returns
TypeDescription
void

update(entities)

update(entities: Entities): void;

Maps to , forcing the method to be update.

Parameter
NameDescription
entities Entities

Datastore key object(s).

Returns
TypeDescription
void

upsert(entities)

upsert(entities: Entities): void;

Maps to , forcing the method to be upsert.

Parameter
NameDescription
entities Entities

Datastore key object(s).

Returns
TypeDescription
void