fetchKey method
Fetches a key in the store by name.
Throws an AskarSessionException if the session is closed. Returns a KeyEntryObject if the key is found, otherwise returns null.
Implementation
Future<KeyEntryObject?> fetchKey({required String name, bool forUpdate = false}) async {
_throwOnNullHandle('Cannot fetch a key with a closed session');
KeyEntryListHandle? keyEntryListHandle;
try {
final fetchKeyResult = await askarSessionFetchKey(handle!, name, forUpdate);
if (!fetchKeyResult.errorCode.isSuccess()) return null;
keyEntryListHandle = fetchKeyResult.value;
final keyEntryObject =
KeyEntryList(handle: keyEntryListHandle).getEntryByIndex(0).toJson();
return keyEntryObject;
} catch (e) {
throw AskarSessionException('Failed to fetch key on session: $e');
} finally {
if (keyEntryListHandle != null) keyEntryListHandle.free();
}
}