mirror of
https://github.com/khibino/haskell-relational-record.git
synced 2024-12-15 06:43:04 +03:00
Update document of projection path objects.
This commit is contained in:
parent
08e2ee135c
commit
34fc566ab8
@ -1,12 +1,26 @@
|
|||||||
|
-- |
|
||||||
|
-- Module : Database.Relational.Query.Pi
|
||||||
|
-- Copyright : 2013 Kei Hibino
|
||||||
|
-- License : BSD3
|
||||||
|
--
|
||||||
|
-- Maintainer : ex8k.hibino@gmail.com
|
||||||
|
-- Stability : experimental
|
||||||
|
-- Portability : unknown
|
||||||
|
--
|
||||||
|
-- This module defines typed projection path objects.
|
||||||
|
-- Contains normal interfaces.
|
||||||
module Database.Relational.Query.Pi (
|
module Database.Relational.Query.Pi (
|
||||||
PiUnit,
|
-- * Projection path
|
||||||
pairPiFstUnit, pairPiSndUnit,
|
|
||||||
|
|
||||||
fst'', snd'',
|
|
||||||
fst', snd',
|
|
||||||
|
|
||||||
Pi((:*)),
|
Pi((:*)),
|
||||||
leafIndex,
|
leafIndex,
|
||||||
|
|
||||||
|
fst', snd',
|
||||||
|
|
||||||
|
-- * Projection path unit
|
||||||
|
PiUnit, offset,
|
||||||
|
pairPiFstUnit, pairPiSndUnit,
|
||||||
|
|
||||||
|
fst'', snd''
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Database.Record
|
import Database.Record
|
||||||
@ -18,30 +32,38 @@ import Database.Relational.Query.Pi.Unsafe
|
|||||||
(PiUnit, offset, Pi ((:*), Leaf), definePiUnit)
|
(PiUnit, offset, Pi ((:*), Leaf), definePiUnit)
|
||||||
|
|
||||||
|
|
||||||
|
-- | Get index of flat SQL value list from typed projection path.
|
||||||
leafIndex :: Pi r f -> Int
|
leafIndex :: Pi r f -> Int
|
||||||
leafIndex = rec where
|
leafIndex = rec where
|
||||||
rec :: Pi r f -> Int
|
rec :: Pi r f -> Int
|
||||||
rec (Leaf pi0) = offset pi0
|
rec (Leaf pi0) = offset pi0
|
||||||
rec (pi0 :* x) = offset pi0 + rec x
|
rec (pi0 :* x) = offset pi0 + rec x
|
||||||
|
|
||||||
|
-- | Projection path unit like fst of tuple.
|
||||||
pairPiFstUnit :: PiUnit (c a b) a
|
pairPiFstUnit :: PiUnit (c a b) a
|
||||||
pairPiFstUnit = definePiUnit 0
|
pairPiFstUnit = definePiUnit 0
|
||||||
|
|
||||||
|
-- | Devivation rule of projection path unit like snd of tuple.
|
||||||
pairPiSndUnit' :: PersistableRecordWidth a -> PiUnit (c a b) b
|
pairPiSndUnit' :: PersistableRecordWidth a -> PiUnit (c a b) b
|
||||||
pairPiSndUnit' pw = definePiUnit (runPersistableRecordWidth pw)
|
pairPiSndUnit' pw = definePiUnit (runPersistableRecordWidth pw)
|
||||||
|
|
||||||
|
-- | Devivated projection path unit like snd of tuple.
|
||||||
pairPiSndUnit :: PersistableWidth a => PiUnit (c a b) b
|
pairPiSndUnit :: PersistableWidth a => PiUnit (c a b) b
|
||||||
pairPiSndUnit = pairPiSndUnit' persistableWidth
|
pairPiSndUnit = pairPiSndUnit' persistableWidth
|
||||||
|
|
||||||
|
|
||||||
|
-- | Projection path unit for fst of tuple.
|
||||||
fst'' :: PiUnit (a, b) a
|
fst'' :: PiUnit (a, b) a
|
||||||
fst'' = pairPiFstUnit
|
fst'' = pairPiFstUnit
|
||||||
|
|
||||||
|
-- | Projection path unit for snd of tuple.
|
||||||
snd'' :: PersistableWidth a => PiUnit (a, b) b
|
snd'' :: PersistableWidth a => PiUnit (a, b) b
|
||||||
snd'' = pairPiSndUnit
|
snd'' = pairPiSndUnit
|
||||||
|
|
||||||
|
-- | Projection path for fst of tuple.
|
||||||
fst' :: Pi (a, b) a
|
fst' :: Pi (a, b) a
|
||||||
fst' = Leaf fst''
|
fst' = Leaf fst''
|
||||||
|
|
||||||
|
-- | Projection path for snd of tuple.
|
||||||
snd' :: PersistableWidth a => Pi (a, b) b
|
snd' :: PersistableWidth a => Pi (a, b) b
|
||||||
snd' = Leaf snd''
|
snd' = Leaf snd''
|
||||||
|
@ -1,30 +1,50 @@
|
|||||||
{-# LANGUAGE ExistentialQuantification #-}
|
{-# LANGUAGE ExistentialQuantification #-}
|
||||||
|
|
||||||
|
-- |
|
||||||
|
-- Module : Database.Relational.Query.Pi.Unsafe
|
||||||
|
-- Copyright : 2013 Kei Hibino
|
||||||
|
-- License : BSD3
|
||||||
|
--
|
||||||
|
-- Maintainer : ex8k.hibino@gmail.com
|
||||||
|
-- Stability : experimental
|
||||||
|
-- Portability : unknown
|
||||||
|
--
|
||||||
|
-- This module defines typed projection path objects.
|
||||||
|
-- Contains internal structure and unsafe interfaces.
|
||||||
module Database.Relational.Query.Pi.Unsafe (
|
module Database.Relational.Query.Pi.Unsafe (
|
||||||
|
-- * Projection path unit
|
||||||
PiUnit, offset, definePiUnit,
|
PiUnit, offset, definePiUnit,
|
||||||
|
|
||||||
|
-- * Projection path
|
||||||
Pi ((:*), Leaf),
|
Pi ((:*), Leaf),
|
||||||
|
|
||||||
defineColumn
|
defineColumn
|
||||||
) where
|
) where
|
||||||
|
|
||||||
newtype PiUnit r ft = PiUnit Int
|
-- | Projection path unit from record type 'r' into column type 'ct'.
|
||||||
-- data PiUnit r ft = PiUnit
|
newtype PiUnit r ct = PiUnit Int
|
||||||
|
-- data PiUnit r ct = PiUnit
|
||||||
-- { offset :: Int
|
-- { offset :: Int
|
||||||
-- , column :: Column r ft
|
-- , column :: Column r ct
|
||||||
-- }
|
-- }
|
||||||
|
|
||||||
offset :: PiUnit r ft -> Int
|
-- | Get index of flat SQL value list from typed projection path unit.
|
||||||
|
offset :: PiUnit r ct -> Int
|
||||||
offset (PiUnit off) = off
|
offset (PiUnit off) = off
|
||||||
|
|
||||||
data Pi r ft = forall r' . PiUnit r r' :* Pi r' ft
|
-- | Projection path from record type 'r' into column type 'ct'.
|
||||||
| Leaf (PiUnit r ft)
|
data Pi r ct = forall r' . PiUnit r r' :* Pi r' ct
|
||||||
|
| Leaf (PiUnit r ct)
|
||||||
|
|
||||||
infixr 9 :*
|
infixr 9 :*
|
||||||
|
|
||||||
|
|
||||||
defineColumn :: Int -> Pi r ft
|
-- | Unsafely define projection path from record type 'r' into column type 'ct'.
|
||||||
|
defineColumn :: Int -- ^ Index of flat SQL value list
|
||||||
|
-> Pi r ct -- ^ Result projection path
|
||||||
defineColumn = Leaf . PiUnit
|
defineColumn = Leaf . PiUnit
|
||||||
|
|
||||||
definePiUnit :: Int -> PiUnit r ft
|
-- | Unsafely define projection path unit from record type 'r' into column type 'ct'.
|
||||||
|
definePiUnit :: Int -- ^ Index of flat SQL value list
|
||||||
|
-> PiUnit r ct -- ^ Result projection path
|
||||||
definePiUnit = PiUnit
|
definePiUnit = PiUnit
|
||||||
|
Loading…
Reference in New Issue
Block a user