@temporary-escape/mod-sdk / TransactionalDatabase
Class: TransactionalDatabase
Defined in: database/transactional-database.ts:67
The shared document-database API, implemented by TransactionalDatabase and Transaction.
AssemblyScript forbids type parameters on interface and abstract methods (the generic T on get/insert/seek/...), so this is a concrete base class whose methods throw; the two implementations override every method. Treat it as the Database interface.
Extends
Constructors
Constructor
ts
new TransactionalDatabase(): TransactionalDatabase;Returns
TransactionalDatabase
Inherited from
Methods
get()
ts
get<T extends Serializable>(
factory: () => T,
doc: string,
key: number
): T | null;Defined in: database/transactional-database.ts:74
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/transactional-database.ts:169
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/transactional-database.ts:101
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/transactional-database.ts:126
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/transactional-database.ts:144
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/transactional-database.ts:214
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/transactional-database.ts:156
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
transaction()
ts
transaction(): Transaction;Defined in: database/transactional-database.ts:134
Creates a new database transaction and starts it immediately
Returns
update()
ts
update<T extends Serializable>(
doc: string,
key: number,
value: T
): boolean;Defined in: database/transactional-database.ts:114
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
