I am trying to do a join on a list of values known beforehand. In the following example - to get prices for each sku in the list.
I have found a link suggesting a use of "with" function: https://funprog.srid.ca/haskell/values-in-esqueleto-persistent.html
But I am out of my depth here, don't know what to do. What is the simplest way to perform a join on a list of values? (Using CTE support and "with" - or in other way)
Here's my attempt (doesn't compile):
-- items :: [(SkuId, Int)]
-- itemsPrices :: [(SkuId, Int, Double)]
itemsPrices <- select $ do
cte <- with $ do
toAlias (val items)
(sku :& price) <-
from $ cte
`InnerJoin` Table @Price
`on` (\(sku :& price) ->
price ^. PriceSku ==. val (fst <$> sku))
pure (fst <$> sku, snd <$> sku, price ^. PriceValue)