on f3daaff help sign in
rel8/src/Rel8/Schema/Context.hs
75 lines 2.0 kB history raw
1{-# language DataKinds #-}
2{-# language DerivingStrategies #-}
3{-# language GADTs #-}
4{-# language GeneralizedNewtypeDeriving #-}
5{-# language StandaloneKindSignatures #-}
6{-# language TypeFamilies #-}
8module Rel8.Schema.Context
9 ( Interpretation, Col(..)
10 , Insertion(..)
11 , Name(..)
12 )
13where
15-- base
16import Data.Functor.Identity ( Identity )
17import Data.Kind ( Constraint )
18import Data.String ( IsString )
19import Prelude
21-- rel8
22import Rel8.Aggregate ( Aggregate )
23import Rel8.Expr ( Expr )
24import Rel8.Kind.Necessity ( Necessity( Optional, Required ) )
25import qualified Rel8.Schema.Kind as K
26import Rel8.Schema.Spec ( Spec( Spec ) )
29type Interpretation :: K.Context -> Constraint
30class Interpretation context where
31 data Col context :: K.HContext
34instance Interpretation Aggregate where
35 data Col Aggregate _spec where
36 Aggregation :: ()
37 => Aggregate (Expr a)
38 -> Col Aggregate ('Spec labels necessity db a)
41instance Interpretation Expr where
42 data Col Expr _spec where
43 DB :: ()
44 => { unDB :: Expr a }
45 -> Col Expr ('Spec labels necessity db a)
48instance Interpretation Identity where
49 data Col Identity _spec where
50 Result :: a -> Col Identity ('Spec labels necessity db a)
53instance Interpretation Insertion where
54 data Col Insertion _spec where
55 RequiredInsert :: Expr a -> Col Insertion ('Spec labels 'Required db a)
56 OptionalInsert :: Maybe (Expr a) -> Col Insertion ('Spec labels 'Optional db a)
59instance Interpretation Name where
60 data Col Name _spec where
61 NameCol :: String -> Col Name ('Spec labels necessity db a)
64type Insertion :: K.Context
65newtype Insertion a = Insertion (Expr a)
68-- | A @Name@ is the name of a column, as it would be defined in a table's
69-- schema definition. You can construct names by using the @OverloadedStrings@
70-- extension and writing string literals. This is typically done when providing
71-- a 'TableSchema' value.
72type Name :: K.Context
73newtype Name a = Name String
74 deriving stock Show
75 deriving newtype (IsString, Monoid, Semigroup)