Skip to content

@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 ​

Database.constructor

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 ​

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/transactional-database.ts:169

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/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 ​

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/transactional-database.ts:126

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/transactional-database.ts:144

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/transactional-database.ts:214

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/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 ​

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


transaction() ​

ts
transaction(): Transaction;

Defined in: database/transactional-database.ts:134

Creates a new database transaction and starts it immediately

Returns ​

Transaction


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 ​

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