module Database.Relational.Query.Arrow (
module Database.Relational.Query,
all', distinct,
query, queryMaybe, query', queryMaybe',
queryList, queryList', queryExists, queryExists', queryListU, queryListU',
queryScalar, queryScalar', queryScalarU, queryScalarU',
uniqueQuery', uniqueQueryMaybe',
on, wheres, having, groupBy, placeholder,
relation, relation', aggregateRelation, aggregateRelation',
uniqueRelation',
groupBy', key, key', set, bkey, rollup, cube, groupingSets,
orderBy', orderBy, asc, desc,
partitionBy, over,
assign,
derivedUpdate', derivedUpdate,
derivedInsertValue', derivedInsertValue,
derivedDelete', derivedDelete,
QueryA,
QuerySimple, QueryAggregate, QueryUnique,
AggregatingSet, AggregatingSetList, AggregatingPowerSet,
Orderings, Window, Assignings,
AssignStatement, Register, RestrictedStatement,
) where
import Control.Category (Category)
import Control.Arrow (Arrow, Kleisli (..))
import Database.Record
import Database.Relational.Query hiding
(all', distinct,
query, queryMaybe, query', queryMaybe',
queryList, queryList', queryScalar, queryScalar',
uniqueQuery', uniqueQueryMaybe',
on, wheres, having, groupBy, placeholder,
relation, relation', aggregateRelation, aggregateRelation', uniqueRelation',
groupBy', key, key', set, bkey, rollup, cube, groupingSets,
orderBy', orderBy, asc, desc, partitionBy, over,
derivedUpdate', derivedUpdate,
derivedInsertValue', derivedInsertValue,
derivedDelete', derivedDelete,
QuerySimple, QueryAggregate, QueryUnique, Window, Register)
import qualified Database.Relational.Query as Monadic
import Database.Relational.Query.Projection (ListProjection)
import qualified Database.Relational.Query.Monad.Trans.Aggregating as Monadic
import qualified Database.Relational.Query.Monad.Trans.Ordering as Monadic
import qualified Database.Relational.Query.Monad.Trans.Assigning as Monadic
newtype QueryA m a b = QueryA (Kleisli m a b) deriving (Category, Arrow)
queryA :: (a -> m b) -> QueryA m a b
queryA = QueryA . Kleisli
runQueryA :: QueryA m a b -> a -> m b
runQueryA (QueryA k) = runKleisli k
runAofM :: (m b -> c) -> QueryA m () b -> c
runAofM = (. (`runQueryA` ()))
type QuerySimple = QueryA Monadic.QuerySimple
type QueryAggregate = QueryA Monadic.QueryAggregate
type QueryUnique = QueryA Monadic.QueryUnique
type AggregatingSet = QueryA Monadic.AggregatingSet
type AggregatingSetList = QueryA Monadic.AggregatingSetList
type AggregatingPowerSet = QueryA Monadic.AggregatingPowerSet
type Orderings c m = QueryA (Monadic.Orderings c m)
type Window c = QueryA (Monadic.Window c)
type Assignings r m = QueryA (Monadic.Assignings r m)
type AssignStatement r a = Assignings r Restrict (Projection Flat r) a
type Register r a = QueryA (Monadic.Register r) () a
type RestrictedStatement r a = QueryA Monadic.Restrict (Projection Flat r) a
all' :: MonadQuery m => QueryA m () ()
all' = queryA $ \() -> Monadic.all'
distinct :: MonadQuery m => QueryA m () ()
distinct = queryA $ \() -> Monadic.distinct
query :: (MonadQualify ConfigureQuery m, MonadQuery m)
=> Relation () r -> QueryA m () (Projection Flat r)
query r = queryA $ \() -> Monadic.query r
queryMaybe :: (MonadQualify ConfigureQuery m, MonadQuery m)
=> Relation () r -> QueryA m () (Projection Flat (Maybe r))
queryMaybe r = queryA $ \() -> Monadic.queryMaybe r
query' :: (MonadQualify ConfigureQuery m, MonadQuery m)
=> Relation p r -> QueryA m () (PlaceHolders p, Projection Flat r)
query' r = queryA $ \() -> Monadic.query' r
queryMaybe' :: (MonadQualify ConfigureQuery m, MonadQuery m)
=> Relation p r -> QueryA m () (PlaceHolders p, Projection Flat (Maybe r))
queryMaybe' r = queryA $ \() -> Monadic.queryMaybe' r
unsafeQueryList :: MonadQualify ConfigureQuery m
=> (a -> Relation () r)
-> QueryA m a (ListProjection (Projection c) r)
unsafeQueryList rf = queryA $ Monadic.queryList . rf
unsafeQueryList' :: MonadQualify ConfigureQuery m
=> (a -> Relation p r)
-> QueryA m a (PlaceHolders p, ListProjection (Projection c) r)
unsafeQueryList' rf = queryA $ Monadic.queryList' . rf
queryList :: MonadQualify ConfigureQuery m
=> (Projection c a -> Relation () r)
-> QueryA m (Projection c a) (ListProjection (Projection c) r)
queryList = unsafeQueryList
queryList' :: MonadQualify ConfigureQuery m
=> (Projection c a -> Relation p r)
-> QueryA m (Projection c a) (PlaceHolders p, ListProjection (Projection c) r)
queryList' = unsafeQueryList'
queryExists :: MonadQualify ConfigureQuery m
=> (Projection c a -> Relation () r)
-> QueryA m (Projection c a) (ListProjection (Projection Exists) r)
queryExists = unsafeQueryList
queryExists' :: MonadQualify ConfigureQuery m
=> (Projection c a -> Relation p r)
-> QueryA m (Projection c a) (PlaceHolders p, ListProjection (Projection Exists) r)
queryExists' = unsafeQueryList'
queryListU :: MonadQualify ConfigureQuery m
=> Relation () r
-> QueryA m () (ListProjection (Projection c) r)
queryListU r = unsafeQueryList $ \() -> r
queryListU' :: MonadQualify ConfigureQuery m
=> Relation p r
-> QueryA m () (PlaceHolders p, ListProjection (Projection c) r)
queryListU' r = unsafeQueryList' $ \() -> r
unsafeQueryScalar :: (MonadQualify ConfigureQuery m, ScalarDegree r)
=> (a -> UniqueRelation () c r)
-> QueryA m a (Projection c (Maybe r))
unsafeQueryScalar rf = queryA $ Monadic.queryScalar . rf
unsafeQueryScalar' :: (MonadQualify ConfigureQuery m, ScalarDegree r)
=> (a -> UniqueRelation p c r)
-> QueryA m a (PlaceHolders p, Projection c (Maybe r))
unsafeQueryScalar' rf = queryA $ Monadic.queryScalar' . rf
queryScalar :: (MonadQualify ConfigureQuery m, ScalarDegree r)
=> (Projection c a -> UniqueRelation () c r)
-> QueryA m (Projection c a) (Projection c (Maybe r))
queryScalar = unsafeQueryScalar
queryScalar' :: (MonadQualify ConfigureQuery m, ScalarDegree r)
=> (Projection c a -> UniqueRelation p c r)
-> QueryA m (Projection c a) (PlaceHolders p, Projection c (Maybe r))
queryScalar' = unsafeQueryScalar'
queryScalarU :: (MonadQualify ConfigureQuery m, ScalarDegree r)
=> UniqueRelation () c r
-> QueryA m () (Projection c (Maybe r))
queryScalarU r = unsafeQueryScalar $ \() -> r
queryScalarU' :: (MonadQualify ConfigureQuery m, ScalarDegree r)
=> UniqueRelation p c r
-> QueryA m () (PlaceHolders p, Projection c (Maybe r))
queryScalarU' r = unsafeQueryScalar' $ \() -> r
uniqueQuery' :: UniqueRelation p c r
-> QueryA Monadic.QueryUnique () (PlaceHolders p, Projection c r)
uniqueQuery' r = queryA $ \() -> Monadic.uniqueQuery' r
uniqueQueryMaybe' :: UniqueRelation p c r
-> QueryA Monadic.QueryUnique () (PlaceHolders p, Projection c (Maybe r))
uniqueQueryMaybe' r = queryA $ \() -> Monadic.uniqueQueryMaybe' r
on :: MonadQuery m
=> QueryA m (Projection Flat (Maybe Bool)) ()
on = queryA Monadic.on
wheres :: MonadRestrict Flat m
=> QueryA m (Projection Flat (Maybe Bool)) ()
wheres = queryA Monadic.wheres
having :: MonadRestrict Aggregated m
=> QueryA m (Projection Aggregated (Maybe Bool)) ()
having = queryA Monadic.having
groupBy :: MonadAggregate m
=> QueryA m (Projection Flat r) (Projection Aggregated r)
groupBy = queryA Monadic.groupBy
placeholder :: (PersistableWidth t, SqlProjectable p, Monad m)
=> QueryA m (QueryA m (p t) a) (PlaceHolders t, a)
placeholder = queryA $ Monadic.placeholder . runQueryA
relation :: QuerySimple () (Projection Flat r)
-> Relation () r
relation = runAofM Monadic.relation
relation' :: QuerySimple () (PlaceHolders p, Projection Flat r)
-> Relation p r
relation' = runAofM Monadic.relation'
aggregateRelation :: QueryAggregate () (Projection Aggregated r)
-> Relation () r
aggregateRelation = runAofM Monadic.aggregateRelation
aggregateRelation' :: QueryAggregate () (PlaceHolders p, Projection Aggregated r)
-> Relation p r
aggregateRelation' = runAofM Monadic.aggregateRelation'
uniqueRelation' :: QueryUnique () (PlaceHolders p, Projection c r)
-> UniqueRelation p c r
uniqueRelation' = runAofM Monadic.uniqueRelation'
groupBy' :: MonadAggregate m => QueryA m (AggregateKey (Projection Aggregated r)) (Projection Aggregated r)
groupBy' = queryA Monadic.groupBy'
key :: AggregatingSet (Projection Flat r) (Projection Aggregated (Maybe r))
key = queryA Monadic.key
key' :: AggregatingSet (AggregateKey a) a
key' = queryA Monadic.key'
set :: AggregatingSetList (AggregatingSet () a) a
set = queryA $ runAofM Monadic.set
bkey :: AggregatingPowerSet (Projection Flat r) (Projection Aggregated (Maybe r))
bkey = queryA Monadic.bkey
rollup :: AggregatingPowerSet () a -> AggregateKey a
rollup = runAofM Monadic.rollup
cube :: AggregatingPowerSet () a -> AggregateKey a
cube = runAofM Monadic.cube
groupingSets :: AggregatingSetList () a -> AggregateKey a
groupingSets = runAofM Monadic.groupingSets
orderBy' :: Monad m
=> Order
-> Nulls
-> Orderings c m (Projection c t) ()
orderBy' o n = queryA $ \p -> Monadic.orderBy' p o n
orderBy :: Monad m
=> Order
-> Orderings c m (Projection c t) ()
orderBy o = queryA (`Monadic.orderBy` o)
asc :: Monad m
=> Orderings c m (Projection c t) ()
asc = queryA Monadic.asc
desc :: Monad m
=> Orderings c m (Projection c t) ()
desc = queryA Monadic.desc
partitionBy :: Window c (Projection c r) ()
partitionBy = queryA Monadic.partitionBy
over :: SqlProjectable (Projection c)
=> Projection OverWindow a -> Window c () () -> Projection c a
over po = runAofM $ Monadic.over po
infix 8 `over`
assign :: Monad m
=> Monadic.AssignTarget r v
-> Assignings r m (Projection Flat v) ()
assign t = queryA (`Monadic.assignTo` t)
derivedUpdate' :: TableDerivable r => Config -> AssignStatement r (PlaceHolders p) -> Update p
derivedUpdate' config = Monadic.derivedUpdate' config . runQueryA
derivedUpdate :: TableDerivable r => AssignStatement r (PlaceHolders p) -> Update p
derivedUpdate = Monadic.derivedUpdate . runQueryA
derivedInsertValue' :: TableDerivable r => Config -> Register r (PlaceHolders p) -> Insert p
derivedInsertValue' config = Monadic.derivedInsertValue' config . ($ ()) . runQueryA
derivedInsertValue :: TableDerivable r => Register r (PlaceHolders p) -> Insert p
derivedInsertValue = Monadic.derivedInsertValue . ($ ()) . runQueryA
derivedDelete' :: TableDerivable r => Config -> RestrictedStatement r (PlaceHolders p) -> Delete p
derivedDelete' config = Monadic.derivedDelete' config . runQueryA
derivedDelete :: TableDerivable r => RestrictedStatement r (PlaceHolders p) -> Delete p
derivedDelete = Monadic.derivedDelete . runQueryA