diff --git a/src/Rel8.hs b/src/Rel8.hs index 93fe579..914cc25 100644 --- a/src/Rel8.hs +++ b/src/Rel8.hs @@ -251,6 +251,9 @@ module Rel8 , without , withoutBy + -- ** @WITH@ + , materialize + -- ** @WITH RECURSIVE@ , loop diff --git a/src/Rel8/Query/Materialize.hs b/src/Rel8/Query/Materialize.hs index 9e010d1..618d2d2 100644 --- a/src/Rel8/Query/Materialize.hs +++ b/src/Rel8/Query/Materialize.hs @@ -33,11 +33,12 @@ import Rel8.Table.Opaleye ( unpackspec ) -- 'materialize' to use the newer @WITH foo AS MATERIALIZED bar@ syntax -- introduced in PostgreSQL 12 in the future. Currently Rel8 does not use -- @AS MATERIALIZED@ to support earlier PostgreSQL versions. -materialize :: Table Expr a => Query a -> (Query a -> Query b) -> Query b +materialize :: (Table Expr a, Table Expr b) + => Query a -> (Query a -> Query b) -> Query b materialize query f = - fromOpaleye $ + (>>= rebind "with") . fromOpaleye $ withExplicit unpackspec (toOpaleye query') (toOpaleye . f . fromOpaleye) where - query' = query >>= rebind "with" + query' = query >>= rebind "materialize" diff --git a/src/Rel8/Tabulate.hs b/src/Rel8/Tabulate.hs index 82a8077..6c5883f 100644 --- a/src/Rel8/Tabulate.hs +++ b/src/Rel8/Tabulate.hs @@ -628,7 +628,7 @@ difference a b = a <* absent b -- | 'Q.materialize' for 'Tabulation's. -materialize :: (Table Expr k, Table Expr a) +materialize :: (Table Expr k, Table Expr a, Table Expr b) => Tabulation k a -> (Tabulation k a -> Query b) -> Query b materialize tabulation f = case peek tabulation of Tabulation query -> do