transact
Call Signature
Section titled “Call Signature”transact<
T>(fn):Promise<number>
Defined in: .work/repos/olmdb/src/olmdb.ts:294
Executes a function within a database transaction context.
All database operations (get, put, del) must be performed within a transaction. Transactions are automatically committed if the function completes successfully, or aborted if an error occurs. Failed transactions may be automatically retried up to 6 times in case of validation conflicts.
Type Parameters
Section titled “Type Parameters”T
The return type of the transaction function.
Parameters
Section titled “Parameters”() => Promise<typeof RETURN_COMMIT_SEQ>
The (optionally asynchronous) function to execute within the transaction context.
Returns
Section titled “Returns”Promise<number>
A promise that resolves with the function’s return value. If the function returns the special symbol RETURN_COMMIT_SEQ, the promise resolves with the commit sequence number instead.
Throws
Section titled “Throws”If nested transactions are attempted.
Throws
Section titled “Throws”With code “RACING_TRANSACTION” if the transaction fails after retries due to conflicts.
Throws
Section titled “Throws”With code “TRANSACTION_FAILED” if the transaction fails for other reasons.
Throws
Section titled “Throws”With code “TXN_LIMIT” if maximum number of transactions is reached.
Throws
Section titled “Throws”With code “LMDB-{code}” for LMDB-specific errors.
Example
Section titled “Example”const result = await transact(() => { const value = get(keyBytes); if (value) { put(keyBytes, newValueBytes); } return value;});Call Signature
Section titled “Call Signature”transact<
T>(fn):Promise<number>
Defined in: .work/repos/olmdb/src/olmdb.ts:295
Executes a function within a database transaction context.
All database operations (get, put, del) must be performed within a transaction. Transactions are automatically committed if the function completes successfully, or aborted if an error occurs. Failed transactions may be automatically retried up to 6 times in case of validation conflicts.
Type Parameters
Section titled “Type Parameters”T
The return type of the transaction function.
Parameters
Section titled “Parameters”() => typeof RETURN_COMMIT_SEQ
The (optionally asynchronous) function to execute within the transaction context.
Returns
Section titled “Returns”Promise<number>
A promise that resolves with the function’s return value. If the function returns the special symbol RETURN_COMMIT_SEQ, the promise resolves with the commit sequence number instead.
Throws
Section titled “Throws”If nested transactions are attempted.
Throws
Section titled “Throws”With code “RACING_TRANSACTION” if the transaction fails after retries due to conflicts.
Throws
Section titled “Throws”With code “TRANSACTION_FAILED” if the transaction fails for other reasons.
Throws
Section titled “Throws”With code “TXN_LIMIT” if maximum number of transactions is reached.
Throws
Section titled “Throws”With code “LMDB-{code}” for LMDB-specific errors.
Example
Section titled “Example”const result = await transact(() => { const value = get(keyBytes); if (value) { put(keyBytes, newValueBytes); } return value;});Call Signature
Section titled “Call Signature”transact<
T>(fn):Promise<T>
Defined in: .work/repos/olmdb/src/olmdb.ts:296
Executes a function within a database transaction context.
All database operations (get, put, del) must be performed within a transaction. Transactions are automatically committed if the function completes successfully, or aborted if an error occurs. Failed transactions may be automatically retried up to 6 times in case of validation conflicts.
Type Parameters
Section titled “Type Parameters”T
The return type of the transaction function.
Parameters
Section titled “Parameters”() => Promise<T>
The (optionally asynchronous) function to execute within the transaction context.
Returns
Section titled “Returns”Promise<T>
A promise that resolves with the function’s return value. If the function returns the special symbol RETURN_COMMIT_SEQ, the promise resolves with the commit sequence number instead.
Throws
Section titled “Throws”If nested transactions are attempted.
Throws
Section titled “Throws”With code “RACING_TRANSACTION” if the transaction fails after retries due to conflicts.
Throws
Section titled “Throws”With code “TRANSACTION_FAILED” if the transaction fails for other reasons.
Throws
Section titled “Throws”With code “TXN_LIMIT” if maximum number of transactions is reached.
Throws
Section titled “Throws”With code “LMDB-{code}” for LMDB-specific errors.
Example
Section titled “Example”const result = await transact(() => { const value = get(keyBytes); if (value) { put(keyBytes, newValueBytes); } return value;});Call Signature
Section titled “Call Signature”transact<
T>(fn):Promise<T>
Defined in: .work/repos/olmdb/src/olmdb.ts:297
Executes a function within a database transaction context.
All database operations (get, put, del) must be performed within a transaction. Transactions are automatically committed if the function completes successfully, or aborted if an error occurs. Failed transactions may be automatically retried up to 6 times in case of validation conflicts.
Type Parameters
Section titled “Type Parameters”T
The return type of the transaction function.
Parameters
Section titled “Parameters”() => T
The (optionally asynchronous) function to execute within the transaction context.
Returns
Section titled “Returns”Promise<T>
A promise that resolves with the function’s return value. If the function returns the special symbol RETURN_COMMIT_SEQ, the promise resolves with the commit sequence number instead.
Throws
Section titled “Throws”If nested transactions are attempted.
Throws
Section titled “Throws”With code “RACING_TRANSACTION” if the transaction fails after retries due to conflicts.
Throws
Section titled “Throws”With code “TRANSACTION_FAILED” if the transaction fails for other reasons.
Throws
Section titled “Throws”With code “TXN_LIMIT” if maximum number of transactions is reached.
Throws
Section titled “Throws”With code “LMDB-{code}” for LMDB-specific errors.
Example
Section titled “Example”const result = await transact(() => { const value = get(keyBytes); if (value) { put(keyBytes, newValueBytes); } return value;});