on 29cdfdb help sign in
rel8/src/Rel8/Schema/Field.hs
50 lines 1.4 kB history raw
1{-# language DataKinds #-}
2{-# language FlexibleContexts #-}
3{-# language MultiParamTypeClasses #-}
4{-# language StandaloneKindSignatures #-}
5{-# language TypeFamilies #-}
7module Rel8.Schema.Field
8 ( Field(..)
9 , fields
10 )
11where
13-- base
14import Data.Functor.Identity ( Identity( Identity ) )
15import Data.Kind ( Type )
16import Prelude
18-- rel8
19import Rel8.Schema.HTable ( HField, htabulate )
20import Rel8.Schema.HTable.Identity ( HIdentity( HIdentity ) )
21import Rel8.Schema.Kind as K
22import Rel8.Schema.Null ( Sql )
23import Rel8.Table
24 ( Table, Columns, Context, fromColumns, toColumns
25 , FromExprs, fromResult, toResult
26 , Transpose
27 )
28import Rel8.Table.Transpose ( Transposes )
29import Rel8.Type ( DBType )
32-- | A special context used in the construction of 'Rel8.Projection's.
33type Field :: Type -> K.Context
34newtype Field table a = Field (HField (Columns table) a)
37instance Sql DBType a => Table (Field table) (Field table a) where
38 type Columns (Field table a) = HIdentity a
39 type Context (Field table a) = Field table
40 type FromExprs (Field table a) = a
41 type Transpose to (Field table a) = to a
43 toColumns = HIdentity
44 fromColumns (HIdentity a) = a
45 toResult a = HIdentity (Identity a)
46 fromResult (HIdentity (Identity a)) = a
49fields :: Transposes context (Field table) table fields => fields
50fields = fromColumns $ htabulate Field