{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
module Opaleye.Join where
import qualified Opaleye.Field as F
import qualified Opaleye.Internal.Unpackspec as U
import qualified Opaleye.Internal.Join as J
import qualified Opaleye.Internal.PrimQuery as PQ
import qualified Opaleye.Map as Map
import qualified Opaleye.Select as S
import qualified Opaleye.SqlTypes as T
import qualified Data.Profunctor.Product.Default as D
leftJoin :: (D.Default U.Unpackspec fieldsL fieldsL,
D.Default U.Unpackspec fieldsR fieldsR,
D.Default J.NullMaker fieldsR nullableFieldsR)
=> S.Select fieldsL
-> S.Select fieldsR
-> ((fieldsL, fieldsR) -> F.Field T.SqlBool)
-> S.Select (fieldsL, nullableFieldsR)
leftJoin = leftJoinExplicit D.def D.def D.def
leftJoinA :: (D.Default U.Unpackspec fieldsR fieldsR,
D.Default J.NullMaker fieldsR nullableFieldsR)
=> S.Select fieldsR
-> S.SelectArr (fieldsR -> F.Field T.SqlBool) nullableFieldsR
leftJoinA = leftJoinAExplict D.def D.def
rightJoin :: (D.Default U.Unpackspec fieldsL fieldsL,
D.Default U.Unpackspec fieldsR fieldsR,
D.Default J.NullMaker fieldsL nullableFieldsL)
=> S.Select fieldsL
-> S.Select fieldsR
-> ((fieldsL, fieldsR) -> F.Field T.SqlBool)
-> S.Select (nullableFieldsL, fieldsR)
rightJoin = rightJoinExplicit D.def D.def D.def
fullJoin :: (D.Default U.Unpackspec fieldsL fieldsL,
D.Default U.Unpackspec fieldsR fieldsR,
D.Default J.NullMaker fieldsL nullableFieldsL,
D.Default J.NullMaker fieldsR nullableFieldsR)
=> S.Select fieldsL
-> S.Select fieldsR
-> ((fieldsL, fieldsR) -> F.Field T.SqlBool)
-> S.Select (nullableFieldsL, nullableFieldsR)
fullJoin = fullJoinExplicit D.def D.def D.def D.def
leftJoinExplicit :: U.Unpackspec fieldsL fieldsL
-> U.Unpackspec fieldsR fieldsR
-> J.NullMaker fieldsR nullableFieldsR
-> S.Select fieldsL -> S.Select fieldsR
-> ((fieldsL, fieldsR) -> F.Field T.SqlBool)
-> S.Select (fieldsL, nullableFieldsR)
leftJoinExplicit uA uB nullmaker =
J.joinExplicit uA uB id (J.toNullable nullmaker) PQ.LeftJoin
leftJoinAExplict :: U.Unpackspec fieldsR fieldsR
-> J.NullMaker fieldsR nullableFieldsR
-> S.Select fieldsR
-> S.SelectArr (fieldsR -> F.Field T.SqlBool) nullableFieldsR
leftJoinAExplict = J.leftJoinAExplicit
rightJoinExplicit :: U.Unpackspec fieldsL fieldsL
-> U.Unpackspec fieldsR fieldsR
-> J.NullMaker fieldsL nullableFieldsL
-> S.Select fieldsL -> S.Select fieldsR
-> ((fieldsL, fieldsR) -> F.Field T.SqlBool)
-> S.Select (nullableFieldsL, fieldsR)
rightJoinExplicit uA uB nullmaker =
J.joinExplicit uA uB (J.toNullable nullmaker) id PQ.RightJoin
fullJoinExplicit :: U.Unpackspec fieldsL fieldsL
-> U.Unpackspec fieldsR fieldsR
-> J.NullMaker fieldsL nullableFieldsL
-> J.NullMaker fieldsR nullableFieldsR
-> S.Select fieldsL -> S.Select fieldsR
-> ((fieldsL, fieldsR) -> F.Field T.SqlBool)
-> S.Select (nullableFieldsL, nullableFieldsR)
fullJoinExplicit uA uB nullmakerA nullmakerB =
J.joinExplicit uA uB (J.toNullable nullmakerA) (J.toNullable nullmakerB) PQ.FullJoin
leftJoinInferrable :: (D.Default U.Unpackspec fieldsL fieldsL,
D.Default U.Unpackspec fieldsR fieldsR,
D.Default J.NullMaker fieldsR nullableFieldsR,
Map.Map J.Nulled fieldsR ~ nullableFieldsR)
=> S.Select fieldsL
-> S.Select fieldsR
-> ((fieldsL, fieldsR) -> F.Field T.SqlBool)
-> S.Select (fieldsL, nullableFieldsR)
leftJoinInferrable = leftJoin
rightJoinInferrable :: (D.Default U.Unpackspec fieldsL fieldsL,
D.Default U.Unpackspec fieldsR fieldsR,
D.Default J.NullMaker fieldsL nullableFieldsL,
Map.Map J.Nulled fieldsL ~ nullableFieldsL)
=> S.Select fieldsL
-> S.Select fieldsR
-> ((fieldsL, fieldsR) -> F.Field T.SqlBool)
-> S.Select (nullableFieldsL, fieldsR)
rightJoinInferrable = rightJoin
fullJoinInferrable :: (D.Default U.Unpackspec fieldsL fieldsL,
D.Default U.Unpackspec fieldsR fieldsR,
D.Default J.NullMaker fieldsL nullableFieldsL,
D.Default J.NullMaker fieldsR nullableFieldsR,
Map.Map J.Nulled fieldsL ~ nullableFieldsL,
Map.Map J.Nulled fieldsR ~ nullableFieldsR)
=> S.Select fieldsL
-> S.Select fieldsR
-> ((fieldsL, fieldsR) -> F.Field T.SqlBool)
-> S.Select (nullableFieldsL, nullableFieldsR)
fullJoinInferrable = fullJoin