on master help sign in
Document various catList operations
7568c75Ollie Charles
src/Rel8/Query/List.hs+17−1
@@ -42,7 +42,7 @@ import Rel8.Type.Information ( TypeInformation )
42-- rows, this function will produce a 'Query' that returns one row containing
42-- rows, this function will produce a 'Query' that returns one row containing
43-- the empty @ListTable@. If the supplied @Query@ does return rows, @many@ will
43-- the empty @ListTable@. If the supplied @Query@ does return rows, @many@ will
44-- return exactly one row, with a @ListTable@ collecting all returned rows.
44-- return exactly one row, with a @ListTable@ collecting all returned rows.
45−--
45+--
46-- @many@ is analogous to 'Control.Applicative.many' from
46-- @many@ is analogous to 'Control.Applicative.many' from
47-- @Control.Applicative@.
47-- @Control.Applicative@.
48many :: Table Expr a => Query a -> Query (ListTable a)
48many :: Table Expr a => Query a -> Query (ListTable a)
@@ -78,20 +78,36 @@ someExpr :: Sql DBType a => Query (Expr a) -> Query (Expr (NonEmpty a))
78someExpr = aggregate . fmap nonEmptyAggExpr
78someExpr = aggregate . fmap nonEmptyAggExpr
79
79
80
80
81+-- | Expand a 'ListTable' into a 'Query', where each row in the query is an
82+-- element of the given @ListTable@.
83+--
84+-- @catListTable@ is an inverse to 'many'.
81catListTable :: Table Expr a => ListTable a -> Query a
85catListTable :: Table Expr a => ListTable a -> Query a
82catListTable (ListTable as) = pure $ fromColumns $ runIdentity $
86catListTable (ListTable as) = pure $ fromColumns $ runIdentity $
83 hunvectorize (\SSpec {info} -> pure . E . sunnest info . unE) as
87 hunvectorize (\SSpec {info} -> pure . E . sunnest info . unE) as
84
88
85
89
90+-- | Expand a 'NonEmptyTable' into a 'Query', where each row in the query is an
91+-- element of the given @NonEmptyTable@.
92+--
93+-- @catNonEmptyTable@ is an inverse to 'some'.
86catNonEmptyTable :: Table Expr a => NonEmptyTable a -> Query a
94catNonEmptyTable :: Table Expr a => NonEmptyTable a -> Query a
87catNonEmptyTable (NonEmptyTable as) = pure $ fromColumns $ runIdentity $
95catNonEmptyTable (NonEmptyTable as) = pure $ fromColumns $ runIdentity $
88 hunvectorize (\SSpec {info} -> pure . E . sunnest info . unE) as
96 hunvectorize (\SSpec {info} -> pure . E . sunnest info . unE) as
89
97
90
98
99+-- | Expand an expression that contains a list into a 'Query', where each row
100+-- in the query is an element of the given list.
101+--
102+-- @catList@ is an inverse to 'manyExpr'.
91catList :: Sql DBType a => Expr [a] -> Query (Expr a)
103catList :: Sql DBType a => Expr [a] -> Query (Expr a)
92catList = pure . sunnest typeInformation
104catList = pure . sunnest typeInformation
93
105
94
106
107+-- | Expand an expression that contains a non-empty list into a 'Query', where
108+-- each row in the query is an element of the given list.
109+--
110+-- @catNonEmpty@ is an inverse to 'someExpr'.
95catNonEmpty :: Sql DBType a => Expr (NonEmpty a) -> Query (Expr a)
111catNonEmpty :: Sql DBType a => Expr (NonEmpty a) -> Query (Expr a)
96catNonEmpty = pure . sunnest typeInformation
112catNonEmpty = pure . sunnest typeInformation
97
113