Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type application to selectList documentation. #1392

Merged
merged 5 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions persistent/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## (unreleased)

* [#1392](https://github.com/yesodweb/persistent/pull/1392)
* Enhance `selectList` documentation with TypeApplications examples.
* Clarify `selectSource` documentation wording.
* [#1391](https://github.com/yesodweb/persistent/pull/1391)
* Increasing quasi module test coverage, improve error assertions

Expand Down
19 changes: 18 additions & 1 deletion persistent/Database/Persist/Class/PersistQuery.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class (PersistQueryRead backend, PersistStoreWrite backend) => PersistQueryWrite
-- | Get all records matching the given criterion in the specified order.
-- Returns also the identifiers.
--
-- WARNING: This function returns a 'ConduitM', which implies that it streams
-- WARNING: This function returns a 'ConduitM', which suggests that it streams
-- the results. It does not stream results on most backends. If you need
-- streaming, see @persistent-pagination@ for a means of chunking results based
-- on indexed ranges.
Expand Down Expand Up @@ -143,6 +143,23 @@ selectKeys filts opts = do
--
-- <https://use-the-index-luke.com/sql/partial-results/fetch-next-page Warning that LIMIT/OFFSET is bad for pagination!>
--
-- The type of record can usually be infered from the types of the provided filters
-- and select options. In the previous two examples, though, you'll notice that the
-- select options are polymorphic, applying to any record type. In order to help
-- type inference in such situations, or simply as an enhancement to readability,
-- you might find type application useful, illustrated below.
--
-- @
-- {-# LANGUAGE TypeApplications #-}
-- ...
--
-- firstTenUsers =
-- 'selectList' @User [] ['LimitTo' 10]
--
-- secondTenUsers =
-- 'selectList' @User [] ['LimitTo' 10, 'OffsetBy' 10]
-- @
--
-- With 'Asc' and 'Desc', we can provide the field we want to sort on. We can
-- provide multiple sort orders - later ones are used to sort records that are
-- equal on the first field.
Expand Down