Skip to content

Instantly share code, notes, and snippets.

@khibino
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khibino/57405584b168d98fd1e8 to your computer and use it in GitHub Desktop.
Save khibino/57405584b168d98fd1e8 to your computer and use it in GitHub Desktop.
{-# LANGUAGE FlexibleContexts #-}
module ArrowQuery (
module Database.Relational.Query,
query, queryMaybe, query', queryMaybe', wheres, having, groupBy, placeholder,
relation, relation', aggregateRelation, aggregateRelation',
QuerySimple, QueryAggregate,
) where
import Control.Arrow
import Database.Record
import Database.Relational.Query hiding
(query, queryMaybe, query', queryMaybe', wheres, having, groupBy, placeholder,
relation, relation', aggregateRelation, aggregateRelation',
QuerySimple, QueryAggregate)
import qualified Database.Relational.Query as Query
type QuerySimple = Kleisli Query.QuerySimple
type QueryAggregate = Kleisli Query.QueryAggregate
query :: MonadQualify ConfigureQuery m =>
Kleisli m (Query.Relation () r) (Projection Flat r)
query = Kleisli Query.query
queryMaybe :: MonadQualify ConfigureQuery m =>
Kleisli m (Query.Relation () r) (Projection Flat (Maybe r))
queryMaybe = Kleisli Query.queryMaybe
query' :: MonadQualify ConfigureQuery m =>
Kleisli m (Query.Relation p r) (PlaceHolders p, Projection Flat r)
query' = Kleisli Query.query'
queryMaybe' :: MonadQualify ConfigureQuery m =>
Kleisli m (Query.Relation p r) (PlaceHolders p, Projection Flat (Maybe r))
queryMaybe' = Kleisli Query.queryMaybe'
wheres :: MonadRestrict Flat m =>
Kleisli m (Projection Flat (Maybe Bool)) ()
wheres = Kleisli Query.wheres
having :: MonadRestrict Aggregated m =>
Kleisli m (Projection Aggregated (Maybe Bool)) ()
having = Kleisli Query.having
groupBy :: MonadAggregate m =>
Kleisli m (Projection Flat r) (Projection Aggregated r)
groupBy = Kleisli Query.groupBy
placeholder :: (PersistableWidth t, SqlProjectable p, Monad m) =>
Kleisli m (Kleisli m (p t) a) (PlaceHolders t, a)
placeholder = Kleisli $ Query.placeholder . runKleisli
relation :: QuerySimple () (Projection Flat r) -> Relation () r
relation = Query.relation . (`runKleisli` ())
relation' :: QuerySimple () (PlaceHolders p, Projection Flat r)
-> Relation p r
relation' = Query.relation' . (`runKleisli` ())
aggregateRelation :: QueryAggregate () (Projection Aggregated r)
-> Relation () r
aggregateRelation = Query.aggregateRelation . (`runKleisli` ())
aggregateRelation' :: QueryAggregate () (PlaceHolders p, Projection Aggregated r)
-> Relation p r
aggregateRelation' = Query.aggregateRelation' . (`runKleisli` ())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment