on eb180fa help sign in
rel8/src/Rel8/Query/Limit.hs
33 lines 749 B history raw
1module Rel8.Query.Limit
2 ( limit
3 , offset
4 )
5where
7-- base
8import Prelude
10-- opaleye
11import qualified Opaleye
13-- rel8
14import Rel8.Query ( Query )
15import Rel8.Query.Opaleye ( mapOpaleye )
18-- | @limit n@ select at most @n@ rows from a query. @limit n@ is equivalent
19-- to the SQL @LIMIT n@.
20--
21-- >>> select c $ limit 3 $ values [ lit x | x <- [ 1..5 :: Int32 ] ]
22-- [1,2,3]
23limit :: Word -> Query a -> Query a
24limit = mapOpaleye . Opaleye.limit . fromIntegral
27-- | @offset n@ drops the first @n@ rows from a query. @offset n@ is equivalent
28-- to the SQL @OFFSET n@.
29--
30-- >>> select c $ offset 3 $ values [ lit x | x <- [ 1..5 :: Int32 ] ]
31-- [4,5]
32offset :: Word -> Query a -> Query a
33offset = mapOpaleye . Opaleye.offset . fromIntegral