1{-# language FlexibleContexts #-}
2{-# language MonoLocalBinds #-}
11import Data.List.NonEmpty ( NonEmpty )
15import Rel8.Expr ( Expr )
16import Rel8.Expr.Aggregate ( listAggExpr, nonEmptyAggExpr )
17import Rel8.Query ( Query )
18import Rel8.Query.Aggregate ( aggregate )
19import Rel8.Query.Maybe ( optional )
20import Rel8.Schema.Null ( Sql )
21import Rel8.Table ( Table )
22import Rel8.Table.Aggregate ( listAgg, nonEmptyAgg )
23import Rel8.Table.List ( ListTable )
24import Rel8.Table.Maybe ( maybeTable )
25import Rel8.Table.NonEmpty ( NonEmptyTable )
26import Rel8.Type ( DBType )
29-- | Aggregate a 'Query' into a 'NonEmptyTable'. If the supplied query returns
30-- 0 rows, this function will produce a 'Query' that is empty - that is, will
31-- produce zero @NonEmptyTable@s. If the supplied @Query@ does return rows,
32-- @some@ will return exactly one row, with a @NonEmptyTable@ collecting all
35-- @some@ is analogous to 'Control.Applicative.some' from
36-- @Control.Applicative@.
37some :: Table Expr a => Query a -> Query (NonEmptyTable a)
38some = aggregate . fmap nonEmptyAgg
41-- | Aggregate a 'Query' into a 'ListTable'. If the supplied query returns 0
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
44-- return exactly one row, with a @ListTable@ collecting all returned rows.
46-- @many@ is analogous to 'Control.Applicative.many' from
47-- @Control.Applicative@.
48many :: Table Expr a => Query a -> Query (ListTable a)
49many = fmap (maybeTable mempty id) . optional . aggregate . fmap listAgg
52-- | A version of 'many' specialised to single expressions.
53manyExpr :: Sql DBType a => Query (Expr a) -> Query (Expr [a])
54manyExpr = fmap (maybeTable mempty id) . optional . aggregate . fmap listAggExpr
57-- | A version of 'many' specialised to single expressions.
58someExpr :: Sql DBType a => Query (Expr a) -> Query (Expr (NonEmpty a))
59someExpr = aggregate . fmap nonEmptyAggExpr
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list