@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
| Parameter | Type |
|---|---|
handle | number |
Returns
Transaction
Overrides
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
| Parameter | Type | Description |
|---|---|---|
factory | () => T | Factory for creating a new instance of the document |
doc | string | Name of the document to retrieve |
key | number | Numeric ID of the document to retrieve |
Returns
T | null
Overrides
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
| Parameter | Type | Description |
|---|---|---|
factory | () => T | Factory for creating a new instance of the document |
doc | string | Name of the document |
index | string | Name of the index |
keys | number[] | 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
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
| Parameter | Type | Description |
|---|---|---|
doc | string | Name of the document to store |
value | T | Document instance to store in the database |
Returns
number
Overrides
remove()
ts
remove(doc: string, key: number): void;Defined in: database/transaction.ts:159
Remove a document from the database
Parameters
| Parameter | Type | Description |
|---|---|---|
doc | string | Name of the document to remove |
key | number | Numeric ID of the document to remove |
Returns
void
Overrides
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
| Parameter | Type | Description |
|---|---|---|
factory | () => T | Factory for creating a new instance of the document |
doc | string | Name of the document to seek |
key | number | Numeric ID of the document to seek from (inclusive) |
Returns
Overrides
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
| Parameter | Type | Description |
|---|---|---|
factory | () => T | Factory for creating a new instance of the document |
doc | string | Name of the document |
index | string | Name of the index |
keys | number[] | Hashed index values (1 to 4 entries, built with IndexKey) |
Returns
IndexCursor<T>
Overrides
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
| Parameter | Type | Description |
|---|---|---|
factory | () => T | Factory for creating a new instance of the document |
doc | string | Name of the document to seek |
keyStart | number | Numeric ID of the document to seek from (inclusive) |
keyEnd | number | Numeric ID of the document to seek to (inclusive) |
Returns
Overrides
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
| Parameter | Type | Description |
|---|---|---|
doc | string | Name of the document to update |
key | number | Numeric ID of the document to update |
value | T | Document instance to replace in the database |
Returns
boolean
Overrides
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
