1module Rel8.Query.Indexed
7import Data.Int ( Int64 )
11import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
12import qualified Opaleye.Internal.PackMap as Opaleye
13import qualified Opaleye.Internal.PrimQuery as Opaleye
14import qualified Opaleye.Internal.QueryArr as Opaleye
15import qualified Opaleye.Internal.Tag as Opaleye
18import Rel8.Expr ( Expr )
19import Rel8.Expr.Opaleye ( fromPrimExpr )
20import Rel8.Query ( Query )
21import Rel8.Query.Opaleye ( mapOpaleye )
24-- | Pair each row of a query with its index within the query.
25indexed :: Query a -> Query (Expr Int64, a)
26indexed = mapOpaleye $ \(Opaleye.QueryArr f) -> Opaleye.QueryArr $ \(_, tag) ->
28 (a, query, tag') = f ((), tag)
29 tag'' = Opaleye.next tag'
30 window = Opaleye.ConstExpr $ Opaleye.OtherLit "ROW_NUMBER() OVER () - 1"
31 (index, bindings) = Opaleye.run $ Opaleye.extractAttr "index" tag' window
32 query' lateral = Opaleye.Rebind True bindings . query lateral
34 ((fromPrimExpr index, a), query', tag'')
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list