1{-# language DataKinds #-}
2{-# language DerivingStrategies #-}
3{-# language FlexibleInstances #-}
5{-# language GeneralizedNewtypeDeriving #-}
6{-# language ScopedTypeVariables #-}
7{-# language StandaloneDeriving #-}
8{-# language StandaloneKindSignatures #-}
9{-# language TypeApplications #-}
10{-# language TypeFamilies #-}
11{-# language UndecidableInstances #-}
13module Rel8.Schema.Context
14 ( Aggregation( Aggregation )
16 , Insertion( RequiredInsert, OptionalInsert )
24import Control.Applicative ( liftA2 )
25import Data.String ( IsString )
29import Rel8.Aggregate ( Aggregate )
30import Rel8.Expr ( Expr )
31import Rel8.Kind.Necessity
32 ( Necessity( Optional, Required )
33 , SNecessity( SOptional, SRequired )
34 , KnownNecessity, necessitySing
36import Rel8.Schema.Nullability ( Nullabilizes )
37import Rel8.Schema.Spec ( Context, Spec( Spec ) )
38import Rel8.Schema.Structure ( Structure )
39import Rel8.Type.Monoid ( DBMonoid )
40import Rel8.Type.Semigroup ( DBSemigroup )
43type Aggregation :: Context
44data Aggregation spec where
47 -> Aggregation ('Spec labels necessity dbType a)
54 -> DB ('Spec labels necessity dbType a)
55deriving stock instance Show (DB spec)
59 ( spec ~ 'Spec labels necessity dbType a
61 , Nullabilizes dbType a
65 DB a <> DB b = DB (a <> b)
69 ( spec ~ 'Spec labels necessity dbType a
71 , Nullabilizes dbType a
78type Insertion :: Context
79data Insertion spec where
82 -> Insertion ('Spec labels 'Required dbType a)
85 -> Insertion ('Spec labels 'Optional dbType a)
86deriving stock instance Show (Insertion spec)
90 ( spec ~ 'Spec labels necessity dbType a
92 , Nullabilizes dbType a
94 Semigroup (Insertion spec)
96 RequiredInsert a <> RequiredInsert b = RequiredInsert (a <> b)
97 OptionalInsert ma <> OptionalInsert mb = OptionalInsert (liftA2 (<>) ma mb)
101 ( spec ~ 'Spec labels necessity dbType a
102 , KnownNecessity necessity
104 , Nullabilizes dbType a
105 ) => Monoid (Insertion spec)
107 mempty = case necessitySing @necessity of
108 SRequired -> RequiredInsert mempty
109 SOptional -> OptionalInsert (Just mempty)
113newtype Name spec = Name String
115 deriving newtype (IsString, Monoid, Semigroup)
118type Result :: Context
119data Result spec where
120 Result :: a -> Result ('Spec labels necessity dbType a)
121deriving stock instance Show a =>
122 Show (Result ('Spec labels necessity dbType a))
125instance (spec ~ 'Spec labels necessity dbType a, Semigroup a) =>
126 Semigroup (Result spec)
128 Result a <> Result b = Result (a <> b)
131instance (spec ~ 'Spec labels necessity dbType a, Monoid a) =>
134 mempty = Result mempty
137type IsSpecialContext :: Context -> Bool
138type family IsSpecialContext context where
139 IsSpecialContext Aggregation = 'True
140 IsSpecialContext DB = 'True
141 IsSpecialContext Insertion = 'True
142 IsSpecialContext Result = 'True
143 IsSpecialContext Structure = 'True
144 IsSpecialContext _ = 'False
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list