findUnique method
T?
findUnique()
Finds the only object matching the query. Returns null if there are no results or throws NonUniqueResultException if there are multiple objects matching.
Note: offset and limit are respected, if set. Because limit affects the number of matched objects, make sure you leave it at zero or set it higher than one, otherwise the check for non-unique result won't work.
Implementation
T? findUnique() {
T? result;
final errorWrapper = ObjectVisitorError();
visitCallback(Pointer<Uint8> data, int size) {
if (result == null) {
try {
result = _entity.objectFromData(_store, data, size);
return true;
} catch (e) {
errorWrapper.error = e;
return false;
}
} else {
errorWrapper.error = NonUniqueResultException(
'Query findUnique() matched more than one object');
return false;
}
}
visit(_ptr, visitCallback);
errorWrapper.throwIfError();
return result;
}