mirror of
https://github.com/khibino/haskell-relational-record.git
synced 2024-12-01 13:52:12 +03:00
specialize product-tree type.
This commit is contained in:
parent
c64d20f5e9
commit
bd4ca68d73
@ -18,34 +18,34 @@ import Control.Applicative (pure, empty)
|
||||
import Data.Monoid ((<>))
|
||||
|
||||
import Database.Relational.Query.Context (Flat)
|
||||
import Database.Relational.Query.Internal.Sub (NodeAttr (..), ProductTree (..), Node (..), Projection)
|
||||
import Database.Relational.Query.Internal.Sub (NodeAttr (..), ProductTree (..), Node (..), Projection, Qualified, SubQuery)
|
||||
|
||||
|
||||
-- | Push new tree into product right term.
|
||||
growRight :: Maybe (Node q) -- ^ Current tree
|
||||
-> (NodeAttr, ProductTree q) -- ^ New tree to push into right
|
||||
-> Node q -- ^ Result node
|
||||
growRight :: Maybe Node -- ^ Current tree
|
||||
-> (NodeAttr, ProductTree) -- ^ New tree to push into right
|
||||
-> Node -- ^ Result node
|
||||
growRight = d where
|
||||
d Nothing (naR, q) = Node naR q
|
||||
d (Just l) (naR, q) = Node Just' $ Join l (Node naR q) empty
|
||||
|
||||
-- | Push new leaf node into product right term.
|
||||
growProduct :: Maybe (Node q) -- ^ Current tree
|
||||
-> (NodeAttr, q) -- ^ New leaf to push into right
|
||||
-> Node q -- ^ Result node
|
||||
growProduct :: Maybe Node -- ^ Current tree
|
||||
-> (NodeAttr, Qualified SubQuery) -- ^ New leaf to push into right
|
||||
-> Node -- ^ Result node
|
||||
growProduct = match where
|
||||
match t (na, q) = growRight t (na, Leaf q)
|
||||
|
||||
-- | Add restriction into top product of product tree.
|
||||
restrictProduct' :: ProductTree q -- ^ Product to restrict
|
||||
restrictProduct' :: ProductTree -- ^ Product to restrict
|
||||
-> Projection Flat (Maybe Bool) -- ^ Restriction to add
|
||||
-> ProductTree q -- ^ Result product
|
||||
-> ProductTree -- ^ Result product
|
||||
restrictProduct' = d where
|
||||
d (Join lp rp rs) rs' = Join lp rp (rs <> pure rs')
|
||||
d leaf'@(Leaf _) _ = leaf' -- or error on compile
|
||||
|
||||
-- | Add restriction into top product of product tree node.
|
||||
restrictProduct :: Node q -- ^ Target node which has product to restrict
|
||||
restrictProduct :: Node -- ^ Target node which has product to restrict
|
||||
-> Projection Flat (Maybe Bool) -- ^ Restriction to add
|
||||
-> Node q -- ^ Result node
|
||||
-> Node -- ^ Result node
|
||||
restrictProduct (Node a t) e = Node a (restrictProduct' t e)
|
||||
|
@ -73,18 +73,20 @@ type UntypedProjection = [ProjectionUnit]
|
||||
-- | node attribute for product.
|
||||
data NodeAttr = Just' | Maybe deriving Show
|
||||
|
||||
type QS = Qualified SubQuery
|
||||
|
||||
-- | Product tree type. Product tree is constructed by left node and right node.
|
||||
data ProductTree q = Leaf q
|
||||
| Join !(Node q) !(Node q) !(DList (Projection Context.Flat (Maybe Bool)))
|
||||
data ProductTree = Leaf QS
|
||||
| Join !Node !Node !(DList (Projection Context.Flat (Maybe Bool)))
|
||||
deriving Show
|
||||
|
||||
-- | Product node. node attribute and product tree.
|
||||
data Node q = Node !NodeAttr !(ProductTree q) deriving Show
|
||||
data Node = Node !NodeAttr !ProductTree deriving Show
|
||||
|
||||
-- | Product tree specialized by 'SubQuery'.
|
||||
type QueryProduct = ProductTree (Qualified SubQuery)
|
||||
type QueryProduct = ProductTree
|
||||
-- | Product node specialized by 'SubQuery'.
|
||||
type QueryProductNode = Node (Qualified SubQuery)
|
||||
type QueryProductNode = Node
|
||||
|
||||
-- | Type for join product of query.
|
||||
type JoinProduct = Maybe QueryProduct
|
||||
|
@ -326,11 +326,11 @@ unsafeProjectFromColumns = typedProjection . untypedProjectionFromColumns
|
||||
|
||||
|
||||
-- | Get node attribute.
|
||||
nodeAttr :: Node q -> NodeAttr
|
||||
nodeAttr :: Node -> NodeAttr
|
||||
nodeAttr (Node a _) = a where
|
||||
|
||||
-- | Get tree from node.
|
||||
nodeTree :: Node q -> ProductTree q
|
||||
nodeTree :: Node -> ProductTree
|
||||
nodeTree (Node _ t) = t
|
||||
|
||||
-- | Show product tree of query into SQL. StringSQL result.
|
||||
|
Loading…
Reference in New Issue
Block a user