Skip to content

Commit

Permalink
loop
Browse files Browse the repository at this point in the history
  • Loading branch information
shane-circuithub committed Jun 11, 2022
1 parent 4b4cce9 commit e88ff0a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions rel8.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ library
Rel8.Query.Indexed
Rel8.Query.Limit
Rel8.Query.List
Rel8.Query.Loop
Rel8.Query.Maybe
Rel8.Query.Null
Rel8.Query.Opaleye
Expand Down
4 changes: 4 additions & 0 deletions src/Rel8.hs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ module Rel8
, without
, withoutBy

-- ** @WITH RECURSIVE@
, loop

-- ** Aggregation
, Aggregate
, Aggregates
Expand Down Expand Up @@ -359,6 +362,7 @@ import Rel8.Query.Filter
import Rel8.Query.Indexed
import Rel8.Query.Limit
import Rel8.Query.List
import Rel8.Query.Loop
import Rel8.Query.Maybe
import Rel8.Query.Null
import Rel8.Query.Order
Expand Down
27 changes: 27 additions & 0 deletions src/Rel8/Query/Loop.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{-# language FlexibleContexts #-}

module Rel8.Query.Loop
( loop
) where

-- base
import Prelude

-- opaleye
import Opaleye.Lateral ( lateral )
import Opaleye.WithRecursive ( withRecursiveExplicit )

-- rel8
import Rel8.Expr ( Expr )
import Rel8.Query ( Query )
import Rel8.Query.Opaleye ( fromOpaleye, toOpaleye )
import Rel8.Table ( Table )
import Rel8.Table.Opaleye ( binaryspec )


loop :: Table Expr a => Query a -> (a -> Query a) -> Query a
loop base recurse =
fromOpaleye $ withRecursiveExplicit binaryspec base' recurse'
where
base' = toOpaleye base
recurse' = lateral $ toOpaleye . recurse

0 comments on commit e88ff0a

Please sign in to comment.