1{-# language FlexibleContexts #-}
3module Rel8.Query.Rebind
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
16import qualified Opaleye.Internal.Unpackspec as Opaleye
19import Rel8.Expr ( Expr )
20import Rel8.Query ( Query( Query ) )
21import Rel8.Table ( Table )
22import Rel8.Table.Opaleye ( unpackspec )
25-- | 'rebind' takes a variable name, some expressions, and binds each of them
26-- to a new variable in the SQL. The @a@ returned consists only of these
27-- variables. It's essentially a @let@ binding for Postgres expressions.
28rebind :: Table Expr a => String -> a -> Query a
29rebind prefix a = Query $ \_ -> Opaleye.QueryArr $ \(_, tag) ->
31 tag' = Opaleye.next tag
32 (a', bindings) = Opaleye.run $
33 Opaleye.runUnpackspec unpackspec (Opaleye.extractAttr prefix tag) a
35 ((mempty, a'), \_ -> Opaleye.Rebind True bindings, 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