on da76712 help sign in
rel8/src/Rel8/Query/Window.hs
26 lines 823 B history raw
1module Rel8.Query.Window
2 ( window
3 )
4where
6-- base
7import Prelude ()
9-- opaleye
10import qualified Opaleye.Window as Opaleye
12-- rel8
13import Rel8.Query ( Query )
14import Rel8.Query.Opaleye ( mapOpaleye )
15import Rel8.Window ( Window( Window ) )
18-- | 'window' runs a query composed of expressions containing
19-- [window functions](https://www.postgresql.org/docs/current/tutorial-window.html).
20-- 'window' is similar to 'Rel8.aggregate', with the main difference being
21-- that in a window query, each input row corresponds to one output row,
22-- whereas aggregation queries fold the entire input query down into a single
23-- row. To put this into a Haskell context, 'Rel8.aggregate' is to 'foldl' as
24-- 'window' is to 'scanl'.
25window :: Window a b -> Query a -> Query b
26window (Window a) = mapOpaleye (Opaleye.runWindows a)