Skip to main content

Interface: WriteTransaction

WriteTransactions are used with mutators which are registered using ReplicacheOptions.mutators and allows read and write operations on the database.

Extends​

Properties​

clientID​

readonly clientID: string

Inherited from​

ReadTransaction.clientID


environment​

readonly environment: TransactionEnvironment

Deprecated​

Use ReadTransaction.location instead.

Inherited from​

ReadTransaction.environment


location​

readonly location: TransactionEnvironment

Inherited from​

ReadTransaction.location


mutationID​

readonly mutationID: number

The ID of the mutation that is being applied.


reason​

readonly reason: TransactionReason

The reason for the transaction. This can be initial, rebase or authoriative.

Methods​

del()​

del(key): Promise<boolean>

Removes a key and its value from the database. Returns true if there was a key to remove.

Parameters​

key​

string

Returns​

Promise<boolean>


get()​

Call Signature​

get(key): Promise<ReadonlyJSONValue | undefined>

Get a single value from the database. If the key is not present this returns undefined.

Important: The returned JSON is readonly and should not be modified. This is only enforced statically by TypeScript and there are no runtime checks for performance reasons. If you mutate the return value you will get undefined behavior.

Parameters​
key​

string

Returns​

Promise<ReadonlyJSONValue | undefined>

Inherited from​

ReadTransaction.get

Call Signature​

get<T>(key): Promise<DeepReadonly<T> | undefined>

Type Parameters​
T​

T extends JSONValue

Parameters​
key​

string

Returns​

Promise<DeepReadonly<T> | undefined>

Inherited from​

ReadTransaction.get


has()​

has(key): Promise<boolean>

Determines if a single key is present in the database.

Parameters​

key​

string

Returns​

Promise<boolean>

Inherited from​

ReadTransaction.has


isEmpty()​

isEmpty(): Promise<boolean>

Whether the database is empty.

Returns​

Promise<boolean>

Inherited from​

ReadTransaction.isEmpty


put()​

put(key, value): Promise<void>

Parameters​

key​

string

value​

ReadonlyJSONValue

Returns​

Promise<void>

Deprecated​

Use WriteTransaction.set instead.


scan()​

Call Signature​

scan(options): ScanResult<IndexKey, ReadonlyJSONValue>

Gets many values from the database. This returns a ScanResult which implements AsyncIterable. It also has methods to iterate over the keys and entries.

If options has an indexName, then this does a scan over an index with that name. A scan over an index uses a tuple for the key consisting of [secondary: string, primary: string].

If the ScanResult is used after the ReadTransaction has been closed it will throw a TransactionClosedError.

Important: The returned JSON is readonly and should not be modified. This is only enforced statically by TypeScript and there are no runtime checks for performance reasons. If you mutate the return value you will get undefined behavior.

Parameters​
options​

ScanIndexOptions

Returns​

ScanResult<IndexKey, ReadonlyJSONValue>

Inherited from​

ReadTransaction.scan

Call Signature​

scan(options?): ScanResult<string, ReadonlyJSONValue>

Parameters​
options?​

ScanNoIndexOptions

Returns​

ScanResult<string, ReadonlyJSONValue>

Inherited from​

ReadTransaction.scan

Call Signature​

scan(options?): ScanResult<string | IndexKey, ReadonlyJSONValue>

Parameters​
options?​

ScanOptions

Returns​

ScanResult<string | IndexKey, ReadonlyJSONValue>

Inherited from​

ReadTransaction.scan

Call Signature​

scan<V>(options): ScanResult<IndexKey, DeepReadonly<V>>

Type Parameters​
V​

V extends ReadonlyJSONValue

Parameters​
options​

ScanIndexOptions

Returns​

ScanResult<IndexKey, DeepReadonly<V>>

Inherited from​

ReadTransaction.scan

Call Signature​

scan<V>(options?): ScanResult<string, DeepReadonly<V>>

Type Parameters​
V​

V extends ReadonlyJSONValue

Parameters​
options?​

ScanNoIndexOptions

Returns​

ScanResult<string, DeepReadonly<V>>

Inherited from​

ReadTransaction.scan

Call Signature​

scan<V>(options?): ScanResult<string | IndexKey, DeepReadonly<V>>

Type Parameters​
V​

V extends ReadonlyJSONValue

Parameters​
options?​

ScanOptions

Returns​

ScanResult<string | IndexKey, DeepReadonly<V>>

Inherited from​

ReadTransaction.scan


set()​

set(key, value): Promise<void>

Sets a single value in the database. The value will be frozen (using Object.freeze) in debug mode.

Parameters​

key​

string

value​

ReadonlyJSONValue

Returns​

Promise<void>