Skip to content

@temporary-escape/mod-sdk / Transaction

Class: Transaction ​

Defined in: database/transaction.ts:89

Database transaction that uses a snapshot of the database at the time of the creation of the transaction. Any changes made to the database are not persisted until the transaction is committed.

You MUST commit or abort. Not calling commit() or abort() will result in a memory leak!!!

Extends ​

Constructors ​

Constructor ​

ts
new Transaction(handle: number): Transaction;

Defined in: database/transaction.ts:90

Parameters ​

ParameterType
handlenumber

Returns ​

Transaction

Overrides ​

Database.constructor

Methods ​

abort() ​

ts
abort(): void;

Defined in: database/transaction.ts:187

Aborts the transaction, discarding any changes made to the database.

The transaction object becomes invalid after this function returns.

Returns ​

void


commit() ​

ts
commit(): boolean;

Defined in: database/transaction.ts:173

Commits the transaction, persisting any changes made to the database.

Returns true if the transaction was successfully committed. Returns false if there was a conflict. The transaction object becomes invalid after this function returns.

Returns ​

boolean


get() ​

ts
get<T extends Serializable>(
   factory: () => T, 
   doc: string, 
   key: number
): T | null;

Defined in: database/transaction.ts:101

Returns a document from the database, or null if not found.

Type Parameters ​

Type Parameter
T extends Serializable

Parameters ​

ParameterTypeDescription
factory() => TFactory for creating a new instance of the document
docstringName of the document to retrieve
keynumberNumeric ID of the document to retrieve

Returns ​

T | null

Overrides ​

Database.get


getByIndex() ​

ts
getByIndex<T extends Serializable>(
   factory: () => T, 
   doc: string, 
   index: string, 
   keys: number[]
): IndexResult<T> | null;

Defined in: database/transaction.ts:242

Looks up a single document by one of its indexes.

Type Parameters ​

Type Parameter
T extends Serializable

Parameters ​

ParameterTypeDescription
factory() => TFactory for creating a new instance of the document
docstringName of the document
indexstringName of the index
keysnumber[]Hashed index values (1 to 4 entries, built with IndexKey)

Returns ​

IndexResult<T> | null

The matching document and its id, or null if nothing matches

Overrides ​

Database.getByIndex


insert() ​

ts
insert<T extends Serializable>(doc: string, value: T): number;

Defined in: database/transaction.ts:130

Inserts a new document into the database, returning its new unique numeric ID

Type Parameters ​

Type Parameter
T extends Serializable

Parameters ​

ParameterTypeDescription
docstringName of the document to store
valueTDocument instance to store in the database

Returns ​

number

Overrides ​

Database.insert


remove() ​

ts
remove(doc: string, key: number): void;

Defined in: database/transaction.ts:159

Remove a document from the database

Parameters ​

ParameterTypeDescription
docstringName of the document to remove
keynumberNumeric ID of the document to remove

Returns ​

void

Overrides ​

Database.remove


seek() ​

ts
seek<T extends Serializable>(
   factory: () => T, 
   doc: string, 
   key: number
): DocumentCursor<T>;

Defined in: database/transaction.ts:210

Creates a document cursor for seeking through the database

Type Parameters ​

Type Parameter
T extends Serializable

Parameters ​

ParameterTypeDescription
factory() => TFactory for creating a new instance of the document
docstringName of the document to seek
keynumberNumeric ID of the document to seek from (inclusive)

Returns ​

DocumentCursor<T>

Overrides ​

Database.seek


seekIndex() ​

ts
seekIndex<T extends Serializable>(
   factory: () => T, 
   doc: string, 
   index: string, 
   keys: number[]
): IndexCursor<T>;

Defined in: database/transaction.ts:290

Creates a cursor over every document whose index key begins with keys.

Type Parameters ​

Type Parameter
T extends Serializable

Parameters ​

ParameterTypeDescription
factory() => TFactory for creating a new instance of the document
docstringName of the document
indexstringName of the index
keysnumber[]Hashed index values (1 to 4 entries, built with IndexKey)

Returns ​

IndexCursor<T>

Overrides ​

Database.seekIndex


seekRange() ​

ts
seekRange<T extends Serializable>(
   factory: () => T, 
   doc: string, 
   keyStart: number, 
   keyEnd: number
): DocumentCursor<T>;

Defined in: database/transaction.ts:224

Creates a document cursor for seeking through the database in a specific range

Type Parameters ​

Type Parameter
T extends Serializable

Parameters ​

ParameterTypeDescription
factory() => TFactory for creating a new instance of the document
docstringName of the document to seek
keyStartnumberNumeric ID of the document to seek from (inclusive)
keyEndnumberNumeric ID of the document to seek to (inclusive)

Returns ​

DocumentCursor<T>

Overrides ​

Database.seekRange


update() ​

ts
update<T extends Serializable>(
   doc: string, 
   key: number, 
   value: T
): boolean;

Defined in: database/transaction.ts:145

Updates an existing document in the database, returning true if the document exists

Type Parameters ​

Type Parameter
T extends Serializable

Parameters ​

ParameterTypeDescription
docstringName of the document to update
keynumberNumeric ID of the document to update
valueTDocument instance to replace in the database

Returns ​

boolean

Overrides ​

Database.update


valid() ​

ts
valid(): boolean;

Defined in: database/transaction.ts:200

Returns true if the transaction object is valid.

The transaction object is invalid after calling commit() or abort().

Returns ​

boolean