on master help sign in
More docs
3a54a58Oliver Charles
src/Rel8/Aggregate.hs+1−1
@@ -48,7 +48,7 @@ import Data.Functor.Apply ( Apply, WrappedApplicative(..) )
48
48
49
49
50-- | An @Aggregate a@ describes how to aggregate @Table@s of type @a@. You can
50-- | An @Aggregate a@ describes how to aggregate @Table@s of type @a@. You can
51−-- unpack an @Aggregate@ back to @a@ by running it with 'aggregate'. As
51+-- unpack an @Aggregate@ back to @a@ by running it with 'Rel8.aggregate'. As
52-- @Aggregate@ is almost an 'Applicative' functor - but there is no 'pure'
52-- @Aggregate@ is almost an 'Applicative' functor - but there is no 'pure'
53-- operation. This means 'Aggregate' is an instance of 'Apply', and you can
53-- operation. This means 'Aggregate' is an instance of 'Apply', and you can
54-- combine @Aggregate@s using the @<.>@ combinator.
54-- combine @Aggregate@s using the @<.>@ combinator.
src/Rel8/Expr/Bool.hs+2−2
@@ -79,8 +79,8 @@ caseExpr branches (Expr fallback) =
79
79
80
80
81-- | Convert a @Expr (Maybe Bool)@ to a @Expr Bool@ by treating @Nothing@ as
81-- | Convert a @Expr (Maybe Bool)@ to a @Expr Bool@ by treating @Nothing@ as
82−-- @False@. This can be useful when combined with 'where_', which expects a
82+-- @False@. This can be useful when combined with 'Rel8.where_', which expects
83−-- @Bool@, and produces expressions that optimize better than general case
83+-- a @Bool@, and produces expressions that optimize better than general case
84-- analysis.
84-- analysis.
85coalesce :: Expr (Maybe Bool) -> Expr Bool
85coalesce :: Expr (Maybe Bool) -> Expr Bool
86coalesce (Expr a) = Expr a &&. Expr (Opaleye.FunExpr "COALESCE" [a, untrue])
86coalesce (Expr a) = Expr a &&. Expr (Opaleye.FunExpr "COALESCE" [a, untrue])
src/Rel8/Expr/Null.hs+2−2
@@ -48,12 +48,12 @@ nullableOf :: DBType a => Maybe (Expr a) -> Expr (Maybe a)
48nullableOf = maybe null nullify
48nullableOf = maybe null nullify
49
49
50
50
51−-- | Like 'isNothing', but for @null@.
51+-- | Like 'Data.Maybe.isNothing', but for @null@.
52isNull :: Expr (Maybe a) -> Expr Bool
52isNull :: Expr (Maybe a) -> Expr Bool
53isNull = mapPrimExpr (Opaleye.UnExpr Opaleye.OpIsNull)
53isNull = mapPrimExpr (Opaleye.UnExpr Opaleye.OpIsNull)
54
54
55
55
56−-- | Like 'isJust', but for @null@.
56+-- | Like 'Data.Maybe.isJust', but for @null@.
57isNonNull :: Expr (Maybe a) -> Expr Bool
57isNonNull :: Expr (Maybe a) -> Expr Bool
58isNonNull = mapPrimExpr (Opaleye.UnExpr Opaleye.OpIsNotNull)
58isNonNull = mapPrimExpr (Opaleye.UnExpr Opaleye.OpIsNotNull)
59
59
src/Rel8/Expr/Serialize.hs+2−2
@@ -32,8 +32,8 @@ import Rel8.Type.Information ( TypeInformation(..) )
32
32
33-- | Produce an expression from a literal.
33-- | Produce an expression from a literal.
34--
34--
35−-- Note that you can usually use 'lit', but @litExpr@ can solve problems of
35+-- Note that you can usually use 'Rel8.lit', but @litExpr@ can solve problems
36−-- inference in polymorphic code.
36+-- of inference in polymorphic code.
37litExpr :: Sql DBType a => a -> Expr a
37litExpr :: Sql DBType a => a -> Expr a
38litExpr = slitExpr nullabilization typeInformation
38litExpr = slitExpr nullabilization typeInformation
39
39
src/Rel8/Order.hs+3−2
@@ -19,8 +19,9 @@ import Data.Functor.Contravariant.Divisible ( Decidable, Divisible )
19import qualified Opaleye.Internal.Order as Opaleye
19import qualified Opaleye.Internal.Order as Opaleye
20
20
21
21
22−-- | An ordering expression for @a@. Primitive orderings are defined with 'asc'
22+-- | An ordering expression for @a@. Primitive orderings are defined with
23−-- and 'desc', and you can combine @Order@ via its various instances.
23+-- 'Rel8.asc' and 'Rel8.desc', and you can combine @Order@ via its various
24+-- instances.
24--
25--
25-- A common pattern is to use '<>' to combine multiple orderings in sequence,
26-- A common pattern is to use '<>' to combine multiple orderings in sequence,
26-- and '>$<' (from 'Contravariant') to select individual columns.
27-- and '>$<' (from 'Contravariant') to select individual columns.
src/Rel8/Query/Maybe.hs+2−1
@@ -60,7 +60,8 @@ catMaybeTable ma@(MaybeTable _ a) = do
60
60
61-- | @bindMaybeTable f x@ is similar to the monadic bind (@>>=@) operation. It
61-- | @bindMaybeTable f x@ is similar to the monadic bind (@>>=@) operation. It
62-- allows you to "extend" an optional query with another query. If either the
62-- allows you to "extend" an optional query with another query. If either the
63−-- input or output are 'noTable', then the result is 'noTable'.
63+-- input or output are 'Rel8.nothingTable', then the result is
64+-- 'Rel8.nothingTable'.
64--
65--
65-- This is similar to 'traverseMaybeTable', followed by a @join@ on the
66-- This is similar to 'traverseMaybeTable', followed by a @join@ on the
66-- resulting @MaybeTable@s.
67-- resulting @MaybeTable@s.
src/Rel8/Query/Values.hs+1−1
@@ -21,7 +21,7 @@ import Rel8.Table.Opaleye ( valuesspec )
21
21
22
22
23-- | Construct a query that returns the given input list of rows. This is like
23-- | Construct a query that returns the given input list of rows. This is like
24−-- folding a list of 'return' statements under 'union', but uses the SQL
24+-- folding a list of 'return' statements under 'Rel8.union', but uses the SQL
25-- @VALUES@ expression for efficiency.
25-- @VALUES@ expression for efficiency.
26values :: (Table Expr a, Foldable f) => f a -> Query a
26values :: (Table Expr a, Foldable f) => f a -> Query a
27values = fromOpaleye . Opaleye.valuesExplicit valuesspec . toList
27values = fromOpaleye . Opaleye.valuesExplicit valuesspec . toList
src/Rel8/Table.hs+5−3
@@ -42,11 +42,13 @@ import Rel8.Type ( DBType )
42-- types that have a finite number of columns. Each of these columns contains
42-- types that have a finite number of columns. Each of these columns contains
43-- data under a shared context, and contexts describe how to interpret the
43-- data under a shared context, and contexts describe how to interpret the
44-- metadata about a column to a particular Haskell type. In Rel8, we have
44-- metadata about a column to a particular Haskell type. In Rel8, we have
45−-- contexts for expressions (the 'Expr' context), aggregations (the 'Aggregate'
45+-- contexts for expressions (the 'Rel8.Expr' context), aggregations (the
46−-- context), insert values (the 'Insert' contex), among others.
46+-- 'Rel8.Aggregate' context), insert values (the 'Rel8.Insert' contex), among
47+-- others.
47--
48--
48-- In typical usage of Rel8 you don't need to derive instances of 'Table'
49-- In typical usage of Rel8 you don't need to derive instances of 'Table'
49−-- yourself, as anything that's an instance of 'Rel8able' is always a 'Table'.
50+-- yourself, as anything that's an instance of 'Rel8.Rel8able' is always a
51+-- 'Table'.
50type Table :: K.Context -> Type -> Constraint
52type Table :: K.Context -> Type -> Constraint
51class (HTable (Columns a), context ~ Context a) => Table context a | a -> context where
53class (HTable (Columns a), context ~ Context a) => Table context a | a -> context where
52 -- | The 'HTable' functor that describes the schema of this table.
54 -- | The 'HTable' functor that describes the schema of this table.
src/Rel8/Table/Alternative.hs+2−2
@@ -20,8 +20,8 @@ import Rel8.Table ( Table )
20-- | Like 'Alt' in Haskell. This class is purely a Rel8 concept, and allows you
20-- | Like 'Alt' in Haskell. This class is purely a Rel8 concept, and allows you
21-- to take a choice between two tables. See also 'AlternativeTable'.
21-- to take a choice between two tables. See also 'AlternativeTable'.
22--
22--
23−-- For example, using '<|>:' on 'MaybeTable' allows you to combine two tables
23+-- For example, using '<|>:' on 'Rel8.MaybeTable' allows you to combine two
24−-- and to return the first one that is a "just" MaybeTable.
24+-- tables and to return the first one that is a "just" MaybeTable.
25type AltTable :: (Type -> Type) -> Constraint
25type AltTable :: (Type -> Type) -> Constraint
26class AltTable f where
26class AltTable f where
27 -- | An associative binary operation on 'Table's.
27 -- | An associative binary operation on 'Table's.
src/Rel8/Table/Insert.hs+5−5
@@ -22,9 +22,9 @@ import Rel8.Table ( fromColumns, toColumns )
22
22
23
23
24-- | @toInsert@ converts a 'Table' of 'Expr's into a 'Table' that can be used
24-- | @toInsert@ converts a 'Table' of 'Expr's into a 'Table' that can be used
25−-- with 'insert'. This will override any columns that have default values to
25+-- with 'Rel8.insert'. This will override any columns that have default values
26−-- use exactly what is given. If you want to use default values, you can either
26+-- to use exactly what is given. If you want to use default values, you can
27−-- override the result of @toInsert@, or use 'toInsertDefaults'.
27+-- either override the result of @toInsert@, or use 'toInsertDefaults'.
28toInsert :: Inserts exprs inserts => exprs -> inserts
28toInsert :: Inserts exprs inserts => exprs -> inserts
29toInsert (toColumns -> exprs) = fromColumns $ htabulate $ \field ->
29toInsert (toColumns -> exprs) = fromColumns $ htabulate $ \field ->
30 case hfield hspecs field of
30 case hfield hspecs field of
@@ -35,8 +35,8 @@ toInsert (toColumns -> exprs) = fromColumns $ htabulate $ \field ->
35
35
36
36
37-- | @toInsertDefaults@ converts a 'Table' of 'Expr's into a 'Table' that can
37-- | @toInsertDefaults@ converts a 'Table' of 'Expr's into a 'Table' that can
38−-- be used with 'insert'. Any columns that have a default value will override
38+-- be used with 'Rel8.insert'. Any columns that have a default value will
39−-- whatever is in the input expression.
39+-- override whatever is in the input expression.
40--
40--
41-- One example where this is useful is for any table that has a special @id@
41-- One example where this is useful is for any table that has a special @id@
42-- column, which has a default value to draw a new value from a sequence. If we
42-- column, which has a default value to draw a new value from a sequence. If we
src/Rel8/Table/List.hs+1−1
@@ -39,7 +39,7 @@ import Rel8.Table.Recontextualize ( Recontextualize )
39
39
40
40
41-- | A @ListTable@ value contains zero or more instances of @a@. You construct
41-- | A @ListTable@ value contains zero or more instances of @a@. You construct
42−-- @ListTable@s with 'many' or 'listAgg'.
42+-- @ListTable@s with 'Rel8.many' or 'Rel8.listAgg'.
43type ListTable :: Type -> Type
43type ListTable :: Type -> Type
44newtype ListTable a = ListTable (HListTable (Columns a) (Col (Context a)))
44newtype ListTable a = ListTable (HListTable (Columns a) (Col (Context a)))
45
45
src/Rel8/Table/Maybe.hs+4−4
@@ -91,7 +91,7 @@ instance Apply MaybeTable where
91
91
92
92
93-- | Has the same behavior as the @Applicative@ instance for @Maybe@. See also:
93-- | Has the same behavior as the @Applicative@ instance for @Maybe@. See also:
94−-- 'traverseMaybeTable'.
94+-- 'Rel8.traverseMaybeTable'.
95instance Applicative MaybeTable where
95instance Applicative MaybeTable where
96 (<*>) = (<.>)
96 (<*>) = (<.>)
97 pure = justTable
97 pure = justTable
@@ -103,7 +103,7 @@ instance Bind MaybeTable where
103
103
104
104
105-- | Has the same behavior as the @Monad@ instance for @Maybe@. See also:
105-- | Has the same behavior as the @Monad@ instance for @Maybe@. See also:
106−-- 'bindMaybeTable'.
106+-- 'Rel8.bindMaybeTable'.
107instance Monad MaybeTable where
107instance Monad MaybeTable where
108 (>>=) = (>>-)
108 (>>=) = (>>-)
109
109
@@ -182,12 +182,12 @@ instance OrdTable a => OrdTable (MaybeTable a) where
182 ordTable = toColumns1 (hlabel hlabeler) (justTable (ordTable @a))
182 ordTable = toColumns1 (hlabel hlabeler) (justTable (ordTable @a))
183
183
184
184
185−-- | Check if a @MaybeTable@ is absent of any row.. Like 'isNothing'.
185+-- | Check if a @MaybeTable@ is absent of any row. Like 'Data.Maybe.isNothing'.
186isNothingTable :: MaybeTable a -> Expr Bool
186isNothingTable :: MaybeTable a -> Expr Bool
187isNothingTable (MaybeTable tag _) = isNull (expr tag)
187isNothingTable (MaybeTable tag _) = isNull (expr tag)
188
188
189
189
190−-- | Check if a @MaybeTable@ contains a row. Like 'isJust'.
190+-- | Check if a @MaybeTable@ contains a row. Like 'Data.Maybe.isJust'.
191isJustTable :: MaybeTable a -> Expr Bool
191isJustTable :: MaybeTable a -> Expr Bool
192isJustTable (MaybeTable tag _) = isNonNull (expr tag)
192isJustTable (MaybeTable tag _) = isNonNull (expr tag)
193
193
src/Rel8/Table/NonEmpty.hs+1−1
@@ -38,7 +38,7 @@ import Rel8.Table.Recontextualize ( Recontextualize )
38
38
39
39
40-- | A @NonEmptyTable@ value contains one or more instances of @a@. You
40-- | A @NonEmptyTable@ value contains one or more instances of @a@. You
41−-- construct @NonEmptyTable@s with 'some' or 'nonEmptyAgg'.
41+-- construct @NonEmptyTable@s with 'Rel8.some' or 'nonEmptyAgg'.
42type NonEmptyTable :: Type -> Type
42type NonEmptyTable :: Type -> Type
43newtype NonEmptyTable a =
43newtype NonEmptyTable a =
44 NonEmptyTable (HNonEmptyTable (Columns a) (Col (Context a)))
44 NonEmptyTable (HNonEmptyTable (Columns a) (Col (Context a)))
src/Rel8/Tabulate.hs+7−13
@@ -177,13 +177,7 @@ ifilter f tabulation = snd <$> do
177 filter (uncurry f) `postbind` indexed tabulation
177 filter (uncurry f) `postbind` indexed tabulation
178
178
179
179
180−-- | Map a 'Query' over the input side of a 'Tabulation'. In particular, you
180+-- | Map a 'Query' over the input side of a 'Tabulation'.
181−-- can turn a @'Tabulation' k a@ into a @'Tabulation' k a@ (for use with
182−-- 'leftAlign' and friends) by 'prebind'ing with 'queryTable', like this:
183−--
184−-- @
185−-- tabulation `'prebind'` 'queryTable'
186−-- @
187prebind :: (a -> Tabulation k b) -> Query a -> Tabulation k b
181prebind :: (a -> Tabulation k b) -> Query a -> Tabulation k b
188prebind f as = Tabulation $ \k -> do
182prebind f as = Tabulation $ \k -> do
189 a <- as
183 a <- as
@@ -242,7 +236,7 @@ alignWith f kas kbs = do
242-- | If 'zip' makes an @INNER JOIN@, then 'leftAlign' makes a @LEFT JOIN@.
236-- | If 'zip' makes an @INNER JOIN@, then 'leftAlign' makes a @LEFT JOIN@.
243-- This means it will return at least one row for every row in the left
237-- This means it will return at least one row for every row in the left
244-- 'Tabulation', even if there is no corresponding row in the right (hence the
238-- 'Tabulation', even if there is no corresponding row in the right (hence the
245−-- 'MaybeTable').
239+-- 'Rel8.MaybeTable').
246--
240--
247-- Analagous to
241-- Analagous to
248-- [@rpadZip@](https://hackage.haskell.org/package/semialign/docs/Data-Semialign.html#v:rpadZip).
242-- [@rpadZip@](https://hackage.haskell.org/package/semialign/docs/Data-Semialign.html#v:rpadZip).
@@ -268,9 +262,9 @@ leftAlignWith f left right = liftA2 f left (optionalTabulation right)
268--
262--
269-- You can think of it as @'Data.Map.Strict.intersectionWith'
263-- You can think of it as @'Data.Map.Strict.intersectionWith'
270-- ('Control.Applicative.liftA2' (,))@. That is, @intersect@ the two
264-- ('Control.Applicative.liftA2' (,))@. That is, @intersect@ the two
271−-- `Tabulation`s by 'match'ing their keys together, and combine their values
265+-- `Tabulation`s by matching their keys together (with 'Rel8.==:'), and combine
272−-- (remembering that 'Tabulation' is a 'MultiMap' so that the values are keys)
266+-- their values (remembering that 'Tabulation' is a 'MultiMap' so that the
273−-- by getting their cartesian product.
267+-- values are keys) by getting their cartesian product.
274--
268--
275-- You can think of it as performing a cross product of the underlying 'Query's
269-- You can think of it as performing a cross product of the underlying 'Query's
276-- of the given 'Tabulation's and filtering the results for 'match'ing keys.
270-- of the given 'Tabulation's and filtering the results for 'match'ing keys.
@@ -305,7 +299,7 @@ zipWith = liftA2
305-- each entry would contain the /product/ of the number of rows of their
299-- each entry would contain the /product/ of the number of rows of their
306-- respective entries in @x@ and @y@.
300-- respective entries in @x@ and @y@.
307--
301--
308−-- See 'with'.
302+-- See 'Rel8.with'.
309similarity :: EqTable k => Tabulation k a -> Tabulation k b -> Tabulation k a
303similarity :: EqTable k => Tabulation k a -> Tabulation k b -> Tabulation k a
310similarity kas kbs = do
304similarity kas kbs = do
311 as <- toQuery kas
305 as <- toQuery kas
@@ -317,7 +311,7 @@ similarity kas kbs = do
317-- exist in the right 'Tabulation'. This corresponds to an antijoin in
311-- exist in the right 'Tabulation'. This corresponds to an antijoin in
318-- relational algebra.
312-- relational algebra.
319--
313--
320−-- See 'without'.
314+-- See 'Rel8.without'.
321difference :: EqTable k => Tabulation k a -> Tabulation k b -> Tabulation k a
315difference :: EqTable k => Tabulation k a -> Tabulation k b -> Tabulation k a
322difference kas kbs = do
316difference kas kbs = do
323 as <- toQuery kas
317 as <- toQuery kas
src/Rel8/Type/Information.hs+1−1
@@ -40,7 +40,7 @@ data TypeInformation a = TypeInformation
40
40
41-- | Simultaneously map over how a type is both encoded and decoded, while
41-- | Simultaneously map over how a type is both encoded and decoded, while
42-- retaining the name of the type. This operation is useful if you want to
42-- retaining the name of the type. This operation is useful if you want to
43−-- essentially @newtype@ another 'DBType'.
43+-- essentially @newtype@ another 'Rel8.DBType'.
44--
44--
45-- The mapping is required to be total. If you have a partial mapping, see
45-- The mapping is required to be total. If you have a partial mapping, see
46-- 'parseTypeInformation'.
46-- 'parseTypeInformation'.
src/Rel8/Type/JSONBEncoded.hs+1−1
@@ -19,7 +19,7 @@ import Rel8.Type.Information ( TypeInformation(..) )
19import Data.Text ( pack )
19import Data.Text ( pack )
20
20
21
21
22−-- | Like 'JSONEncoded', but works for @jsonb@ columns.
22+-- | Like 'Rel8.JSONEncoded', but works for @jsonb@ columns.
23newtype JSONBEncoded a = JSONBEncoded { fromJSONBEncoded :: a }
23newtype JSONBEncoded a = JSONBEncoded { fromJSONBEncoded :: a }
24
24
25
25
src/Rel8/Type/Monoid.hs+2−2
@@ -42,8 +42,8 @@ import qualified Data.Text.Lazy as Lazy ( Text )
42import Data.Time.LocalTime ( CalendarDiffTime( CalendarDiffTime ) )
42import Data.Time.LocalTime ( CalendarDiffTime( CalendarDiffTime ) )
43
43
44
44
45−-- | The class of 'DBType's that form a semigroup. This class is purely a Rel8
45+-- | The class of 'Rel8.DBType's that form a semigroup. This class is purely a
46−-- concept, and exists to mirror the 'Monoid' class.
46+-- Rel8 concept, and exists to mirror the 'Monoid' class.
47type DBMonoid :: Type -> Constraint
47type DBMonoid :: Type -> Constraint
48class DBSemigroup a => DBMonoid a where
48class DBSemigroup a => DBMonoid a where
49 -- The identity for '<>.'
49 -- The identity for '<>.'
src/Rel8/Type/Semigroup.hs+2−2
@@ -42,8 +42,8 @@ import qualified Data.Text.Lazy as Lazy ( Text )
42import Data.Time.LocalTime ( CalendarDiffTime )
42import Data.Time.LocalTime ( CalendarDiffTime )
43
43
44
44
45−-- | The class of 'DBType's that form a semigroup. This class is purely a Rel8
45+-- | The class of 'Rel8.DBType's that form a semigroup. This class is purely a
46−-- concept, and exists to mirror the 'Semigroup' class.
46+-- Rel8 concept, and exists to mirror the 'Semigroup' class.
47type DBSemigroup :: Type -> Constraint
47type DBSemigroup :: Type -> Constraint
48class DBType a => DBSemigroup a where
48class DBType a => DBSemigroup a where
49 -- | An associative operation.
49 -- | An associative operation.