Skip to content

Commit

Permalink
Add Rel8.Tabulate, a complementary API for writing queries (circuith…
Browse files Browse the repository at this point in the history
  • Loading branch information
shane-circuithub authored Jul 15, 2021
1 parent 5d2b9e4 commit b4f0e23
Show file tree
Hide file tree
Showing 4 changed files with 654 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rel8.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ library
build-depends:
aeson
, base ^>= 4.14 || ^>=4.15
, bifunctors
, bytestring
, case-insensitive
, comonad
Expand All @@ -29,6 +30,7 @@ library
, opaleye ^>= 0.7.3.0
, pretty
, profunctors
, product-profunctors
, scientific
, semialign
, semigroupoids
Expand All @@ -52,6 +54,7 @@ library
Rel8.Expr.Num
Rel8.Expr.Text
Rel8.Expr.Time
Rel8.Tabulate

other-modules:
Rel8.Aggregate
Expand Down
6 changes: 6 additions & 0 deletions src/Rel8/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ import qualified Opaleye.Internal.Tag as Opaleye
import Rel8.Query.Set ( unionAll )
import Rel8.Query.Opaleye ( fromOpaleye )
import Rel8.Query.Values ( values )
import Rel8.Table ( fromColumns, toColumns )
import Rel8.Table.Alternative
( AltTable, (<|>:)
, AlternativeTable, emptyTable
)
import Rel8.Table.Projection ( Projectable, apply, project )

-- semigroupoids
import Data.Functor.Apply ( Apply, (<.>) )
Expand Down Expand Up @@ -151,6 +153,10 @@ newtype Query a =
)


instance Projectable Query where
project f = fmap (fromColumns . apply f . toColumns)


instance Functor Query where
fmap f (Query a) = Query (fmap (fmap (fmap f)) a)

Expand Down
8 changes: 8 additions & 0 deletions src/Rel8/Query/Opaleye.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Rel8.Query.Opaleye
, toOpaleye
, mapOpaleye
, zipOpaleyeWith
, unsafePeekQuery
)
where

Expand All @@ -14,6 +15,7 @@ import Prelude

-- opaleye
import qualified Opaleye.Internal.QueryArr as Opaleye
import qualified Opaleye.Internal.Tag as Opaleye

-- rel8
import {-# SOURCE #-} Rel8.Query ( Query( Query ) )
Expand All @@ -37,6 +39,12 @@ zipOpaleyeWith :: ()
zipOpaleyeWith f (Query a) (Query b) = Query $ liftA2 (zipping f) a b


unsafePeekQuery :: Query a -> a
unsafePeekQuery (Query q) = case q mempty of
Opaleye.QueryArr f -> case f ((), Opaleye.start) of
((_, a), _, _) -> a


mapping :: ()
=> (Opaleye.Select a -> Opaleye.Select b)
-> Opaleye.Select (m, a) -> Opaleye.Select (m, b)
Expand Down
Loading

0 comments on commit b4f0e23

Please sign in to comment.