on da76712 help sign in
rel8/src/Rel8/Query/Rebind.hs
27 lines 735 B history raw
1{-# language FlexibleContexts #-}
3module Rel8.Query.Rebind
4 ( rebind
5 )
6where
8-- base
9import Prelude
10import Control.Arrow ((<<<))
12-- opaleye
13import qualified Opaleye.Internal.Rebind as Opaleye
15-- rel8
16import Rel8.Expr ( Expr )
17import Rel8.Query ( Query )
18import Rel8.Table ( Table )
19import Rel8.Table.Opaleye ( unpackspec )
20import Rel8.Query.Opaleye (fromOpaleye)
23-- | 'rebind' takes a variable name, some expressions, and binds each of them
24-- to a new variable in the SQL. The @a@ returned consists only of these
25-- variables. It's essentially a @let@ binding for Postgres expressions.
26rebind :: Table Expr a => String -> a -> Query a
27rebind prefix a = fromOpaleye (Opaleye.rebindExplicitPrefix prefix unpackspec <<< pure a)