-
Notifications
You must be signed in to change notification settings - Fork 301
Closed
Description
Some backends allow queries to check if there is a record fulfilling certain criteria.
In SQL, for example, you can write SELECT EXISTS(SELECT 1 FROM tbl WHERE criterion). The query will return True if and only if there is at least one row such that criterion is fulfilled.
The query is logically equivalent to doing SELECT COUNT(1) FROM tbl WHERE criterion and then checking if the result is non-zero, but the existence check can in some circumstances be much faster, especially on large amounts of data.
I'd like to add this type of queries. The type signature is the same as for the count function, except it returns Bool:
-- | Check if there is at least one record fulfilling the given criterion.
--
-- @since 2.11
exists :: (MonadIO m, PersistRecordBackend record backend)
=> [Filter record] -> ReaderT backend m Bool
For backends not providing optimized existence queries we can use a default implementation using count.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels