@@ -24,6 +24,7 @@ import Rel8.Expr.Aggregate ( listAggExpr, nonEmptyAggExpr )
24import Rel8.Expr.Opaleye ( mapPrimExpr )
24import Rel8.Expr.Opaleye ( mapPrimExpr )
25import Rel8.Query ( Query )
25import Rel8.Query ( Query )
26import Rel8.Query.Aggregate ( aggregate )
26import Rel8.Query.Aggregate ( aggregate )
27+import Rel8.Query.Evaluate ( rebind )
27import Rel8.Query.Maybe ( optional )
28import Rel8.Query.Maybe ( optional )
28import Rel8.Schema.HTable.Vectorize ( hunvectorize )
29import Rel8.Schema.HTable.Vectorize ( hunvectorize )
29import Rel8.Schema.Null ( Sql, Unnullify )
30import Rel8.Schema.Null ( Sql, Unnullify )
@@ -83,7 +84,7 @@ someExpr = aggregate . fmap nonEmptyAggExpr
84-- @catListTable@ is an inverse to 'many'.
85-- @catListTable@ is an inverse to 'many'.
85catListTable :: Table Expr a => ListTable a -> Query a
86catListTable :: Table Expr a => ListTable a -> Query a
86−catListTable (ListTable as) = pure $ fromColumns $ runIdentity $
87+catListTable (ListTable as) = rebind $ fromColumns $ runIdentity $
87 hunvectorize (\SSpec {info} -> pure . E . sunnest info . unE) as
88 hunvectorize (\SSpec {info} -> pure . E . sunnest info . unE) as
@@ -92,7 +93,7 @@ catListTable (ListTable as) = pure $ fromColumns $ runIdentity $
93-- @catNonEmptyTable@ is an inverse to 'some'.
94-- @catNonEmptyTable@ is an inverse to 'some'.
94catNonEmptyTable :: Table Expr a => NonEmptyTable a -> Query a
95catNonEmptyTable :: Table Expr a => NonEmptyTable a -> Query a
95−catNonEmptyTable (NonEmptyTable as) = pure $ fromColumns $ runIdentity $
96+catNonEmptyTable (NonEmptyTable as) = rebind $ fromColumns $ runIdentity $
96 hunvectorize (\SSpec {info} -> pure . E . sunnest info . unE) as
97 hunvectorize (\SSpec {info} -> pure . E . sunnest info . unE) as
@@ -101,7 +102,7 @@ catNonEmptyTable (NonEmptyTable as) = pure $ fromColumns $ runIdentity $
102-- @catList@ is an inverse to 'manyExpr'.
103-- @catList@ is an inverse to 'manyExpr'.
103catList :: Sql DBType a => Expr [a] -> Query (Expr a)
104catList :: Sql DBType a => Expr [a] -> Query (Expr a)
104−catList = pure . sunnest typeInformation
105+catList = rebind . sunnest typeInformation
107-- | Expand an expression that contains a non-empty list into a 'Query', where
108-- | Expand an expression that contains a non-empty list into a 'Query', where
@@ -109,7 +110,7 @@ catList = pure . sunnest typeInformation
110-- @catNonEmpty@ is an inverse to 'someExpr'.
111-- @catNonEmpty@ is an inverse to 'someExpr'.
111catNonEmpty :: Sql DBType a => Expr (NonEmpty a) -> Query (Expr a)
112catNonEmpty :: Sql DBType a => Expr (NonEmpty a) -> Query (Expr a)
112−catNonEmpty = pure . sunnest typeInformation
113+catNonEmpty = rebind . sunnest typeInformation
115sunnest :: TypeInformation (Unnullify a) -> Expr (list a) -> Expr a
116sunnest :: TypeInformation (Unnullify a) -> Expr (list a) -> Expr a