modernize join

This commit is contained in:
nek0 2022-04-15 19:09:44 +02:00
parent 31f6c6d61e
commit 9752f27afb
1 changed files with 16 additions and 42 deletions

View File

@ -134,48 +134,22 @@ produceProductOverviews
)
produceProductOverviews refine =
proc () -> do
(p, i2, i6, i6a, i7, i8, i9, i11, i12, i13, a3, a4)
<- orderBy (asc (\(_, a2, _, _, _, _, _, _, _, _, _, _) -> a2)) (leftJoinF
(\(pid, pi2, pi6, pi6a, pi7, pi8, pi9, pi11, pi12, pi13)
(_, _, ai3, ai4, _) ->
(pid, pi2, pi6, pi6a, pi7, pi8, pi9, pi11, pi12, pi13, ai3, ai4)
)
(const
( toFields (0 :: Int) :: Column SqlInt4
, toFields ("ERROR PRODUCT" :: T.Text) :: Column SqlText
, toFields (0 :: Int) :: Column SqlInt4
, toFields (Just (0 :: Int)) :: Column (Nullable SqlInt4)
, toFields (Just (0 :: Int)) :: Column (Nullable SqlInt4)
, toFields (0 :: Int) :: Column SqlInt4
, toFields (0 :: Int) :: Column SqlInt4
, toFields (0 :: Int) :: Column SqlInt4
, toFields (Just (0 :: Int)) :: Column (Nullable SqlInt4)
, toFields (Just ("" :: T.Text)) :: Column (Nullable SqlText)
, toFields (0 :: Int) :: Column SqlInt4
, toFields (0 :: Int) :: Column SqlInt4
)
)
(\(pid, _, _, _, _, _, _, _, _, _)
(aid, _, _, _, _) ->
pid .== aid
)
(selectTable productTable)
(joinF
(\(_, _, a3, a4, a5) (b1, b2) ->
(b1, b2, a3, a4, a5)
)
(\(a1, a2, _, _, _) (b1, b2) ->
(a1 .== b1) .&& (a2 .== b2)
)
(selectTable amountTable)
(aggregate
((,)
<$> P.lmap fst O.groupBy
<*> P.lmap snd O.max
)
(arr (\(a, b, _, _, _) -> (a, b)) <<< selectTable amountTable))
)) -< ()
-- <<< arr (\_ -> (selectTable productTable, selectTable amountTable)) -< ()
(p, i2, i6, i6a, i7, i8, i9, i11, i12, i13) <-
selectTable productTable -< ()
(_, _, a3, a4, _) <- do
(a1, a2, a3, a4, a5) <- selectTable amountTable -< ()
(b1, b2) <- do
(ib1, ib2, _, _, _) <- selectTable amountTable -< ()
(laterally . aggregate)
(
(,)
<$> P.lmap fst O.groupBy
<*> P.lmap snd O.max
)
(arr (\(ib1, ib2, _, _, _) -> (ib1, ib2)) <<< selectTable amountTable ) -< ()
returnA -< (ib1, ib2)
restrict -< a1 .== b1 .&& a2 .== b2
returnA -< (b1, b2, a3, a4, a5)
restrict -< case refine of
AllProducts -> toFields True
AvailableProducts -> a3 ./= (toFields (0 :: Int) :: Column SqlInt4)