findUnique method
T?
findUnique()
Finds the only object matching this query.
Returns the object if a single object matches. null
if no object matches.
Throws NonUniqueResultException if there are multiple objects matching the query.
Note: Because limit affects the number of matched objects, make sure to 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;
}