Rename necessity (back) to defaulting

This commit is contained in:
Shane O'Brien 2021-06-16 22:51:15 +01:00
parent 99d0021032
commit 0b071aeca7
No known key found for this signature in database
GPG Key ID: 35A00ED1B695C1A1
28 changed files with 236 additions and 236 deletions

View File

@ -70,8 +70,8 @@ library
Rel8.Kind.Algebra
Rel8.Kind.Context
Rel8.Kind.Defaulting
Rel8.Kind.Labels
Rel8.Kind.Necessity
Rel8.Generic.Construction
Rel8.Generic.Construction.ADT

View File

@ -32,7 +32,7 @@ module Rel8
-- * Tables and higher-kinded tables
, Rel8able, KRel8able
, Column, Field, Necessity( Required, Optional )
, Column, Field, Defaulting( NoDefault, HasDefault )
, Default
, HADT
, HEither
@ -310,7 +310,7 @@ import Rel8.Expr.Ord
import Rel8.Expr.Order
import Rel8.Expr.Serialize
import Rel8.Generic.Rel8able ( KRel8able, Rel8able )
import Rel8.Kind.Necessity
import Rel8.Kind.Defaulting
import Rel8.Order
import Rel8.Query
import Rel8.Query.Aggregate

View File

@ -62,7 +62,7 @@ instance Interpretation Aggregate where
data Col Aggregate _spec where
A :: ()
=> { unA :: !(Aggregate a) }
-> Col Aggregate ('Spec labels necessity a)
-> Col Aggregate ('Spec labels defaulting a)
instance Sql DBType a => Table Aggregate (Aggregate a) where

View File

@ -15,7 +15,7 @@ import Prelude ()
-- rel8
import Rel8.Column.Field ( Field )
import Rel8.FCF ( Eval, Exp )
import Rel8.Kind.Necessity ( Necessity( Required, Optional ) )
import Rel8.Kind.Defaulting ( Defaulting( NoDefault, HasDefault ) )
import qualified Rel8.Schema.Kind as K
@ -24,11 +24,11 @@ import qualified Rel8.Schema.Kind as K
-- support when a query is executed, allowing you to use a single data type for
-- both query data and rows decoded to Haskell.
type Column :: K.Context -> Type -> Type
type Column context a = Field context 'Required a
type Column context a = Field context 'NoDefault a
type Default :: K.Context -> Type -> Type
type Default context a = Field context 'Optional a
type Default context a = Field context 'HasDefault a
data TColumn :: K.Context -> Type -> Exp Type

View File

@ -18,7 +18,7 @@ import Prelude
import Rel8.Aggregate ( Aggregate, Col( A ) )
import Rel8.Expr ( Expr, Col( E ) )
import Rel8.Kind.Context ( SContext(..), Reifiable( contextSing ) )
import Rel8.Kind.Necessity ( Necessity, KnownNecessity )
import Rel8.Kind.Defaulting ( Defaulting, KnownDefaulting )
import Rel8.Schema.HTable.Identity ( HIdentity( HIdentity ) )
import Rel8.Schema.Insert ( Col( I ), Create(..), Insert )
import qualified Rel8.Schema.Kind as K
@ -35,26 +35,26 @@ import Rel8.Table.Recontextualize ( Recontextualize )
import Rel8.Type ( DBType )
type Field :: K.Context -> Necessity -> Type -> Type
type family Field context necessity a where
Field (Reify context) necessity a = AField context necessity a
Field Aggregate _necessity a = Aggregate a
Field Expr _necessity a = Expr a
Field Insert necessity a = Create necessity a
Field Name _necessity a = Name a
Field Result _necessity a = a
type Field :: K.Context -> Defaulting -> Type -> Type
type family Field context defaulting a where
Field (Reify context) defaulting a = AField context defaulting a
Field Aggregate _defaulting a = Aggregate a
Field Expr _defaulting a = Expr a
Field Insert defaulting a = Create defaulting a
Field Name _defaulting a = Name a
Field Result _defaulting a = a
type AField :: K.Context -> Necessity -> Type -> Type
newtype AField context necessity a = AField (Field context necessity a)
type AField :: K.Context -> Defaulting -> Type -> Type
newtype AField context defaulting a = AField (Field context defaulting a)
instance (Reifiable context, KnownNecessity necessity, Sql DBType a) =>
Table (Reify context) (AField context necessity a)
instance (Reifiable context, KnownDefaulting defaulting, Sql DBType a) =>
Table (Reify context) (AField context defaulting a)
where
type Context (AField context necessity a) = Reify context
type Columns (AField context necessity a) = HIdentity ('Spec '[] necessity a)
type Unreify (AField context necessity a) = Field context necessity a
type Context (AField context defaulting a) = Reify context
type Columns (AField context defaulting a) = HIdentity ('Spec '[] defaulting a)
type Unreify (AField context defaulting a) = Field context defaulting a
fromColumns (HIdentity (Reify a)) = sfromColumn contextSing a
toColumns = HIdentity . Reify . stoColumn contextSing
@ -64,19 +64,19 @@ instance (Reifiable context, KnownNecessity necessity, Sql DBType a) =>
instance
( Reifiable context, Reifiable context'
, KnownNecessity necessity, Sql DBType a
, KnownDefaulting defaulting, Sql DBType a
) =>
Recontextualize
(Reify context)
(Reify context')
(AField context necessity a)
(AField context' necessity a)
(AField context defaulting a)
(AField context' defaulting a)
sfromColumn :: ()
=> SContext context
-> Col context ('Spec labels necessity a)
-> AField context necessity a
-> Col context ('Spec labels defaulting a)
-> AField context defaulting a
sfromColumn = \case
SAggregate -> \(A a) -> AField a
SExpr -> \(E a) -> AField a
@ -88,8 +88,8 @@ sfromColumn = \case
stoColumn :: ()
=> SContext context
-> AField context necessity a
-> Col context ('Spec labels necessity a)
-> AField context defaulting a
-> Col context ('Spec labels defaulting a)
stoColumn = \case
SAggregate -> \(AField a) -> A a
SExpr -> \(AField a) -> E a

View File

@ -128,7 +128,7 @@ instance Sql DBFloating a => Floating (Expr a) where
instance Interpretation Expr where
data Col Expr _spec where
E :: {unE :: !(Expr a)} -> Col Expr ('Spec labels necessity a)
E :: {unE :: !(Expr a)} -> Col Expr ('Spec labels defaulting a)
instance Sql DBType a => Table Expr (Expr a) where

View File

@ -64,23 +64,23 @@ import Data.Text ( pack )
type Null :: K.HContext -> Type
type Null context = forall labels necessity a. ()
=> SSpec ('Spec labels necessity a)
-> context ('Spec labels necessity (Nullify a))
type Null context = forall labels defaulting a. ()
=> SSpec ('Spec labels defaulting a)
-> context ('Spec labels defaulting (Nullify a))
type Nullifier :: K.HContext -> Type
type Nullifier context = forall labels necessity a. ()
=> SSpec ('Spec labels necessity a)
-> context ('Spec labels necessity a)
-> context ('Spec labels necessity (Nullify a))
type Nullifier context = forall labels defaulting a. ()
=> SSpec ('Spec labels defaulting a)
-> context ('Spec labels defaulting a)
-> context ('Spec labels defaulting (Nullify a))
type Unnullifier :: K.HContext -> Type
type Unnullifier context = forall labels necessity a. ()
=> SSpec ('Spec labels necessity a)
-> context ('Spec labels necessity (Nullify a))
-> context ('Spec labels necessity a)
type Unnullifier context = forall labels defaulting a. ()
=> SSpec ('Spec labels defaulting a)
-> context ('Spec labels defaulting (Nullify a))
-> context ('Spec labels defaulting a)
type NoConstructor :: Symbol -> Symbol -> ErrorMessage

View File

@ -148,10 +148,10 @@ ggtable :: forall algebra _Table _Columns rep context.
, Eval (GGTable algebra _Table _Columns context rep)
)
=> (forall a proxy. Eval (_Table a) => proxy a -> Eval (_Columns a) context)
-> (forall a labels necessity. ()
=> SSpec ('Spec labels necessity a)
-> context ('Spec labels necessity a)
-> context ('Spec labels necessity (Nullify a)))
-> (forall a labels defaulting. ()
=> SSpec ('Spec labels defaulting a)
-> context ('Spec labels defaulting a)
-> context ('Spec labels defaulting (Nullify a)))
-> Eval (GGColumns algebra _Columns rep) context
ggtable = case algebraSing @algebra of
SProduct -> \table _ -> gtable @_Table @_Columns @_ @rep table

View File

@ -96,10 +96,10 @@ class GTableADT _Table _Columns context rep where
gtableADT :: ()
=> (forall a proxy. Eval (_Table a) => proxy a -> Eval (_Columns a) context)
-> (forall a labels necessity. ()
=> SSpec ('Spec labels necessity a)
-> context ('Spec labels necessity a)
-> context ('Spec labels necessity (Nullify a)))
-> (forall a labels defaulting. ()
=> SSpec ('Spec labels defaulting a)
-> context ('Spec labels defaulting a)
-> context ('Spec labels defaulting (Nullify a)))
-> GColumnsADT _Columns rep context
@ -136,10 +136,10 @@ type GTableADT'
class GTableADT' _Table _Columns htable context rep where
gtableADT' :: ()
=> (forall a proxy. Eval (_Table a) => proxy a -> Eval (_Columns a) context)
-> (forall a labels necessity. ()
=> SSpec ('Spec labels necessity a)
-> context ('Spec labels necessity a)
-> context ('Spec labels necessity (Nullify a)))
-> (forall a labels defaulting. ()
=> SSpec ('Spec labels defaulting a)
-> context ('Spec labels defaulting a)
-> context ('Spec labels defaulting (Nullify a)))
-> htable context
-> GColumnsADT' _Columns htable rep context

View File

@ -0,0 +1,38 @@
{-# language DataKinds #-}
{-# language FlexibleContexts #-}
{-# language GADTs #-}
{-# language StandaloneKindSignatures #-}
module Rel8.Kind.Defaulting
( Defaulting( HasDefault, NoDefault )
, SDefaulting( SHasDefault, SNoDefault )
, KnownDefaulting( defaultingSing )
)
where
-- base
import Data.Kind ( Constraint, Type )
import Prelude ()
type Defaulting :: Type
data Defaulting = HasDefault | NoDefault
type SDefaulting :: Defaulting -> Type
data SDefaulting defaulting where
SHasDefault :: SDefaulting 'HasDefault
SNoDefault :: SDefaulting 'NoDefault
type KnownDefaulting :: Defaulting -> Constraint
class KnownDefaulting defaulting where
defaultingSing :: SDefaulting defaulting
instance KnownDefaulting 'HasDefault where
defaultingSing = SHasDefault
instance KnownDefaulting 'NoDefault where
defaultingSing = SNoDefault

View File

@ -1,38 +0,0 @@
{-# language DataKinds #-}
{-# language FlexibleContexts #-}
{-# language GADTs #-}
{-# language StandaloneKindSignatures #-}
module Rel8.Kind.Necessity
( Necessity( Optional, Required )
, SNecessity( SOptional, SRequired )
, KnownNecessity( necessitySing )
)
where
-- base
import Data.Kind ( Constraint, Type )
import Prelude ()
type Necessity :: Type
data Necessity = Optional | Required
type SNecessity :: Necessity -> Type
data SNecessity necessity where
SOptional :: SNecessity 'Optional
SRequired :: SNecessity 'Required
type KnownNecessity :: Necessity -> Constraint
class KnownNecessity necessity where
necessitySing :: SNecessity necessity
instance KnownNecessity 'Optional where
necessitySing = SOptional
instance KnownNecessity 'Required where
necessitySing = SRequired

View File

@ -26,12 +26,12 @@ import Rel8.Schema.Spec.ConstrainDBType ( ConstrainDBType )
type Labelable :: Context -> Constraint
class Interpretation context => Labelable context where
labeler :: ()
=> Col context ('Spec labels necessity a)
-> Col context ('Spec (label ': labels) necessity a)
=> Col context ('Spec labels defaulting a)
-> Col context ('Spec (label ': labels) defaulting a)
unlabeler :: ()
=> Col context ('Spec (label ': labels) necessity a)
-> Col context ('Spec labels necessity a)
=> Col context ('Spec (label ': labels) defaulting a)
-> Col context ('Spec labels defaulting a)
instance Labelable Result where
@ -42,12 +42,12 @@ instance Labelable Result where
type HLabelable :: HContext -> Constraint
class HLabelable context where
hlabeler :: ()
=> context ('Spec labels necessity a)
-> context ('Spec (label ': labels) necessity a)
=> context ('Spec labels defaulting a)
-> context ('Spec (label ': labels) defaulting a)
hunlabeler :: ()
=> context ('Spec (label ': labels) necessity a)
-> context ('Spec labels necessity a)
=> context ('Spec (label ': labels) defaulting a)
-> context ('Spec labels defaulting a)
instance Labelable context => HLabelable (Col context) where

View File

@ -33,7 +33,7 @@ import Rel8.Expr ( Expr, Col( E ) )
import Rel8.Expr.Bool ( boolExpr )
import Rel8.Expr.Null ( nullify, unsafeUnnullify )
import Rel8.Expr.Opaleye ( fromPrimExpr, toPrimExpr )
import Rel8.Kind.Necessity ( Necessity( Required ) )
import Rel8.Kind.Defaulting ( Defaulting( NoDefault ) )
import Rel8.Schema.Context ( Interpretation )
import qualified Rel8.Schema.Kind as K
import Rel8.Schema.Name ( Name( Name ), Col( N ) )
@ -56,27 +56,27 @@ class Interpretation context => Nullifiable context where
, Taggable a
)
=> Tag label a
-> Col context ('Spec labels 'Required a)
-> Col context ('Spec labels 'NoDefault a)
decodeTag ::
( Sql (ConstrainTag context) a
, KnownSymbol label
, Taggable a
)
=> Col context ('Spec labels 'Required a)
=> Col context ('Spec labels 'NoDefault a)
-> Tag label a
nullifier :: ()
=> Tag label a
-> (Expr a -> Expr Bool)
-> SSpec ('Spec labels necessity x)
-> Col context ('Spec labels necessity x)
-> Col context ('Spec labels necessity (Nullify x))
-> SSpec ('Spec labels defaulting x)
-> Col context ('Spec labels defaulting x)
-> Col context ('Spec labels defaulting (Nullify x))
unnullifier :: ()
=> SSpec ('Spec labels necessity x)
-> Col context ('Spec labels necessity (Nullify x))
-> Col context ('Spec labels necessity x)
=> SSpec ('Spec labels defaulting x)
-> Col context ('Spec labels defaulting (Nullify x))
-> Col context ('Spec labels defaulting x)
instance Nullifiable Aggregate where
@ -148,23 +148,23 @@ class HNullifiable context where
hencodeTag :: (Sql (HConstrainTag context) a, KnownSymbol label, Taggable a)
=> Tag label a
-> context ('Spec labels 'Required a)
-> context ('Spec labels 'NoDefault a)
hdecodeTag :: (Sql (HConstrainTag context) a, KnownSymbol label, Taggable a)
=> context ('Spec labels 'Required a)
=> context ('Spec labels 'NoDefault a)
-> Tag label a
hnullifier :: ()
=> Tag label a
-> (Expr a -> Expr Bool)
-> SSpec ('Spec labels necessity x)
-> context ('Spec labels necessity x)
-> context ('Spec labels necessity (Nullify x))
-> SSpec ('Spec labels defaulting x)
-> context ('Spec labels defaulting x)
-> context ('Spec labels defaulting (Nullify x))
hunnullifier :: ()
=> SSpec ('Spec labels necessity x)
-> context ('Spec labels necessity (Nullify x))
-> context ('Spec labels necessity x)
=> SSpec ('Spec labels defaulting x)
-> context ('Spec labels defaulting (Nullify x))
-> context ('Spec labels defaulting x)
instance Nullifiable context => HNullifiable (Col context) where

View File

@ -14,7 +14,7 @@ import GHC.Generics ( Generic )
import Prelude ()
-- rel8
import Rel8.Kind.Necessity ( Necessity( Required ) )
import Rel8.Kind.Defaulting ( Defaulting( NoDefault ) )
import Rel8.Schema.HTable ( HTable )
import Rel8.Schema.HTable.Identity ( HIdentity(..) )
import Rel8.Schema.HTable.Label ( HLabel )
@ -26,7 +26,7 @@ import Rel8.Type.Tag ( EitherTag )
type HEitherTable :: K.HTable -> K.HTable -> K.HTable
data HEitherTable left right context = HEitherTable
{ htag :: HIdentity ('Spec '["isRight"] 'Required EitherTag) context
{ htag :: HIdentity ('Spec '["isRight"] 'NoDefault EitherTag) context
, hleft :: HLabel "Left" (HNullify left) context
, hright :: HLabel "Right" (HNullify right) context
}

View File

@ -15,7 +15,7 @@ import Data.Kind ( Type )
import Prelude
-- rel8
import Rel8.Kind.Necessity ( Necessity( Required ) )
import Rel8.Kind.Defaulting ( Defaulting( NoDefault ) )
import Rel8.Schema.Dict ( Dict( Dict ) )
import Rel8.Schema.HTable
( HTable, HConstrainTable, HField
@ -26,10 +26,10 @@ import Rel8.Schema.Spec ( Spec( Spec ), KnownSpec, specSing )
type HType :: Type -> K.HTable
type HType a = HIdentity ('Spec '[] 'Required a)
type HType a = HIdentity ('Spec '[] 'NoDefault a)
pattern HType :: context ('Spec '[] 'Required a) -> HType a context
pattern HType :: context ('Spec '[] 'NoDefault a) -> HType a context
pattern HType a = HIdentity a
{-# COMPLETE HType #-}

View File

@ -49,7 +49,7 @@ newtype HLabel label table context = HLabel (HMapTable (Label label) table conte
data Label :: Symbol -> Spec -> Exp Spec
type instance Eval (Label label ('Spec labels necessity a)) = 'Spec (label : labels) necessity a
type instance Eval (Label label ('Spec labels defaulting a)) = 'Spec (label : labels) defaulting a
instance KnownSymbol l => MapSpec (Label l) where
@ -58,9 +58,9 @@ instance KnownSymbol l => MapSpec (Label l) where
hlabel :: (HTable t, KnownSymbol label)
=> (forall labels necessity a. ()
=> context ('Spec labels necessity a)
-> context ('Spec (label ': labels) necessity a))
=> (forall labels defaulting a. ()
=> context ('Spec labels defaulting a)
-> context ('Spec (label ': labels) defaulting a))
-> t context
-> HLabel label t context
hlabel labeler a = HLabel $ htabulate $ \(HMapTableField field) ->
@ -70,9 +70,9 @@ hlabel labeler a = HLabel $ htabulate $ \(HMapTableField field) ->
hunlabel :: (HTable t, KnownSymbol label)
=> (forall labels necessity a. ()
=> context ('Spec (label ': labels) necessity a)
-> context ('Spec labels necessity a))
=> (forall labels defaulting a. ()
=> context ('Spec (label ': labels) defaulting a)
-> context ('Spec labels defaulting a))
-> HLabel label t context
-> t context
hunlabel unlabler (HLabel as) =

View File

@ -14,7 +14,7 @@ import GHC.Generics ( Generic )
import Prelude
-- rel8
import Rel8.Kind.Necessity ( Necessity( Required ) )
import Rel8.Kind.Defaulting ( Defaulting( NoDefault ) )
import Rel8.Schema.HTable ( HTable )
import Rel8.Schema.HTable.Identity ( HIdentity(..) )
import Rel8.Schema.HTable.Label ( HLabel )
@ -26,7 +26,7 @@ import Rel8.Type.Tag ( MaybeTag )
type HMaybeTable :: K.HTable -> K.HTable
data HMaybeTable table context = HMaybeTable
{ htag :: HIdentity ('Spec '["isJust"] 'Required (Maybe MaybeTag)) context
{ htag :: HIdentity ('Spec '["isJust"] 'NoDefault (Maybe MaybeTag)) context
, hjust :: HLabel "Just" (HNullify table) context
}
deriving stock Generic

View File

@ -50,15 +50,15 @@ newtype HNullify table context = HNullify (HMapTable Nullify table context)
data Nullify :: Spec -> Exp Spec
type instance Eval (Nullify ('Spec labels necessity a)) =
'Spec labels necessity (Type.Nullify a)
type instance Eval (Nullify ('Spec labels defaulting a)) =
'Spec labels defaulting (Type.Nullify a)
instance MapSpec Nullify where
mapInfo = \case
SSpec{labels, necessity, info, nullity} -> SSpec
SSpec{labels, defaulting, info, nullity} -> SSpec
{ labels
, necessity
, defaulting
, info
, nullity = case nullity of
Null -> Null
@ -67,9 +67,9 @@ instance MapSpec Nullify where
hnulls :: HTable t
=> (forall labels necessity a. ()
=> SSpec ('Spec labels necessity a)
-> context ('Spec labels necessity (Type.Nullify a)))
=> (forall labels defaulting a. ()
=> SSpec ('Spec labels defaulting a)
-> context ('Spec labels defaulting (Type.Nullify a)))
-> HNullify t context
hnulls null = HNullify $ htabulate $ \(HMapTableField field) -> case hfield hspecs field of
spec@SSpec {} -> null spec
@ -77,10 +77,10 @@ hnulls null = HNullify $ htabulate $ \(HMapTableField field) -> case hfield hspe
hnullify :: HTable t
=> (forall labels necessity a. ()
=> SSpec ('Spec labels necessity a)
-> context ('Spec labels necessity a)
-> context ('Spec labels necessity (Type.Nullify a)))
=> (forall labels defaulting a. ()
=> SSpec ('Spec labels defaulting a)
-> context ('Spec labels defaulting a)
-> context ('Spec labels defaulting (Type.Nullify a)))
-> t context
-> HNullify t context
hnullify nullifier a = HNullify $ htabulate $ \(HMapTableField field) ->
@ -90,10 +90,10 @@ hnullify nullifier a = HNullify $ htabulate $ \(HMapTableField field) ->
hunnullify :: (HTable t, Apply m)
=> (forall labels necessity a. ()
=> SSpec ('Spec labels necessity a)
-> context ('Spec labels necessity (Type.Nullify a))
-> m (context ('Spec labels necessity a)))
=> (forall labels defaulting a. ()
=> SSpec ('Spec labels defaulting a)
-> context ('Spec labels defaulting (Type.Nullify a))
-> m (context ('Spec labels defaulting a)))
-> HNullify t context
-> m (t context)
hunnullify unnullifier (HNullify as) =

View File

@ -14,7 +14,7 @@ import GHC.Generics ( Generic )
import Prelude
-- rel8
import Rel8.Kind.Necessity ( Necessity( Required ) )
import Rel8.Kind.Defaulting ( Defaulting( NoDefault ) )
import Rel8.Schema.HTable ( HTable )
import Rel8.Schema.HTable.Identity ( HIdentity )
import Rel8.Schema.HTable.Label ( HLabel )
@ -26,9 +26,9 @@ import Rel8.Type.Tag ( MaybeTag )
type HTheseTable :: K.HTable -> K.HTable -> K.HTable
data HTheseTable here there context = HTheseTable
{ hhereTag :: HIdentity ('Spec '["hasHere"] 'Required (Maybe MaybeTag)) context
{ hhereTag :: HIdentity ('Spec '["hasHere"] 'NoDefault (Maybe MaybeTag)) context
, hhere :: HLabel "Here" (HNullify here) context
, hthereTag :: HIdentity ('Spec '["hasThere"] 'Required (Maybe MaybeTag)) context
, hthereTag :: HIdentity ('Spec '["hasThere"] 'NoDefault (Maybe MaybeTag)) context
, hthere :: HLabel "There" (HNullify there) context
}
deriving stock Generic

View File

@ -32,7 +32,7 @@ import Data.List.NonEmpty ( NonEmpty )
import Prelude
-- rel8
import Rel8.Kind.Necessity ( Necessity( Required ), SNecessity( SRequired ) )
import Rel8.Kind.Defaulting ( Defaulting( NoDefault ), SDefaulting( SNoDefault ) )
import Rel8.Schema.Context.Label ( HLabelable, hlabeler, hunlabeler )
import Rel8.Schema.Dict ( Dict( Dict ) )
import qualified Rel8.Schema.Kind as K
@ -79,14 +79,14 @@ newtype HVectorize list table context = HVectorize (HMapTable (Vectorize list) t
data Vectorize :: (Type -> Type) -> Spec -> Exp Spec
type instance Eval (Vectorize list ('Spec labels _necessity a)) = 'Spec labels 'Required (list a)
type instance Eval (Vectorize list ('Spec labels _defaulting a)) = 'Spec labels 'NoDefault (list a)
instance Vector list => MapSpec (Vectorize list) where
mapInfo = \case
SSpec {..} -> case listNotNull @list nullity of
Dict -> SSpec
{ necessity = SRequired
{ defaulting = SNoDefault
, nullity = NotNull
, info = vectorTypeInformation nullity info
, ..
@ -94,10 +94,10 @@ instance Vector list => MapSpec (Vectorize list) where
hvectorize :: (HTable t, Unzip f, Vector list)
=> (forall labels necessity a. ()
=> SSpec ('Spec labels necessity a)
-> f (context ('Spec labels necessity a))
-> context' ('Spec labels 'Required (list a)))
=> (forall labels defaulting a. ()
=> SSpec ('Spec labels defaulting a)
-> f (context ('Spec labels defaulting a))
-> context' ('Spec labels 'NoDefault (list a)))
-> f (t context)
-> HVectorize list t context'
hvectorize vectorizer as = HVectorize $ htabulate $ \(HMapTableField field) ->
@ -107,10 +107,10 @@ hvectorize vectorizer as = HVectorize $ htabulate $ \(HMapTableField field) ->
hunvectorize :: (HTable t, Zip f, Vector list)
=> (forall labels necessity a. ()
=> SSpec ('Spec labels necessity a)
-> context ('Spec labels 'Required (list a))
-> f (context' ('Spec labels necessity a)))
=> (forall labels defaulting a. ()
=> SSpec ('Spec labels defaulting a)
-> context ('Spec labels 'NoDefault (list a))
-> f (context' ('Spec labels defaulting a)))
-> HVectorize list t context
-> f (t context')
hunvectorize unvectorizer (HVectorize table) =
@ -121,12 +121,12 @@ hunvectorize unvectorizer (HVectorize table) =
happend :: (HTable t, Vector list) =>
( forall labels necessity a. ()
( forall labels defaulting a. ()
=> Nullity a
-> TypeInformation (Unnullify a)
-> context ('Spec labels necessity (list a))
-> context ('Spec labels necessity (list a))
-> context ('Spec labels necessity (list a))
-> context ('Spec labels defaulting (list a))
-> context ('Spec labels defaulting (list a))
-> context ('Spec labels defaulting (list a))
)
-> HVectorize list t context
-> HVectorize list t context
@ -138,10 +138,10 @@ happend append (HVectorize as) (HVectorize bs) = HVectorize $
hempty :: HTable t =>
( forall labels necessity a. ()
( forall labels defaulting a. ()
=> Nullity a
-> TypeInformation (Unnullify a)
-> context ('Spec labels necessity [a])
-> context ('Spec labels defaulting [a])
)
-> HVectorize [] t context
hempty empty = HVectorize $ htabulate $ \(HMapTableField field) -> case hfield hspecs field of

View File

@ -30,7 +30,7 @@ import Prelude
-- rel8
import Rel8.Aggregate ( Aggregate )
import Rel8.Expr ( Expr )
import Rel8.Kind.Necessity ( Necessity(Optional, Required), KnownNecessity )
import Rel8.Kind.Defaulting ( Defaulting(HasDefault, NoDefault), KnownDefaulting )
import Rel8.Schema.Context ( Interpretation(..) )
import Rel8.Schema.Context.Label ( Labelable(..) )
import Rel8.Schema.Context.Nullify
@ -80,24 +80,24 @@ data Insert a where
instance Interpretation Insert where
data Col Insert _spec where
I :: {unI :: !(Create necessity a)} -> Col Insert ('Spec labels necessity a)
I :: {unI :: !(Create defaulting a)} -> Col Insert ('Spec labels defaulting a)
type Create :: Necessity -> Type -> Type
data Create necessity a where
Default :: Create 'Optional a
Value :: Expr a -> Create necessity a
type Create :: Defaulting -> Type -> Type
data Create defaulting a where
Default :: Create 'HasDefault a
Value :: Expr a -> Create defaulting a
unValue :: Create 'Required a -> Expr a
unValue :: Create 'NoDefault a -> Expr a
unValue (Value a) = a
instance (KnownNecessity necessity, Sql DBType a) =>
Table Insert (Create necessity a)
instance (KnownDefaulting defaulting, Sql DBType a) =>
Table Insert (Create defaulting a)
where
type Columns (Create necessity a) = HIdentity ('Spec '[] necessity a)
type Context (Create necessity a) = Insert
type Columns (Create defaulting a) = HIdentity ('Spec '[] defaulting a)
type Context (Create defaulting a) = Insert
toColumns = HIdentity . I
fromColumns (HIdentity (I a)) = a
@ -106,34 +106,34 @@ instance (KnownNecessity necessity, Sql DBType a) =>
instance Sql DBType a =>
Recontextualize Aggregate Insert (Aggregate a) (Create 'Required a)
Recontextualize Aggregate Insert (Aggregate a) (Create 'NoDefault a)
instance Sql DBType a => Recontextualize Expr Insert (Expr a) (Create 'Required a)
instance Sql DBType a => Recontextualize Expr Insert (Expr a) (Create 'NoDefault a)
instance Sql DBType a =>
Recontextualize Result Insert (Identity a) (Create 'Required a)
Recontextualize Result Insert (Identity a) (Create 'NoDefault a)
instance Sql DBType a =>
Recontextualize Insert Aggregate (Create 'Required a) (Aggregate a)
Recontextualize Insert Aggregate (Create 'NoDefault a) (Aggregate a)
instance Sql DBType a => Recontextualize Insert Expr (Create 'Required a) (Expr a)
instance Sql DBType a => Recontextualize Insert Expr (Create 'NoDefault a) (Expr a)
instance Sql DBType a =>
Recontextualize Insert Result (Create 'Required a) (Identity a)
Recontextualize Insert Result (Create 'NoDefault a) (Identity a)
instance Sql DBType a => Recontextualize Insert Insert (Create 'Required a) (Create 'Required a)
instance Sql DBType a => Recontextualize Insert Insert (Create 'NoDefault a) (Create 'NoDefault a)
instance Sql DBType a => Recontextualize Insert Name (Create 'Required a) (Name a)
instance Sql DBType a => Recontextualize Insert Name (Create 'NoDefault a) (Name a)
instance Sql DBType a => Recontextualize Name Insert (Name a) (Create 'Required a)
instance Sql DBType a => Recontextualize Name Insert (Name a) (Create 'NoDefault a)
instance Labelable Insert where

View File

@ -84,7 +84,7 @@ instance Sql DBType a => Recontextualize Name Name (Name a) (Name a)
instance Interpretation Name where
data Col Name _spec where
N :: {unN :: !(Name a)} -> Col Name ('Spec labels necessity a)
N :: {unN :: !(Name a)} -> Col Name ('Spec labels defaulting a)
instance Labelable Name where

View File

@ -16,7 +16,7 @@ where
import Prelude hiding ( null )
-- rel8
import Rel8.Kind.Necessity ( Necessity( Required ) )
import Rel8.Kind.Defaulting ( Defaulting( NoDefault ) )
import Rel8.Schema.Context ( Interpretation( Col ) )
import Rel8.Schema.HTable.Identity ( HIdentity(..) )
import Rel8.Schema.Kind ( Context )
@ -30,32 +30,32 @@ data Result a
instance Interpretation Result where
data Col Result _spec where
R :: {unR :: !a} -> Col Result ('Spec labels necessity a)
R :: {unR :: !a} -> Col Result ('Spec labels defaulting a)
relabel :: ()
=> HIdentity ('Spec labels necessity a) (Col Result)
-> HIdentity ('Spec relabels necessity a) (Col Result)
=> HIdentity ('Spec labels defaulting a) (Col Result)
-> HIdentity ('Spec relabels defaulting a) (Col Result)
relabel (HIdentity (R a)) = HIdentity (R a)
null :: Col Result ('Spec labels necessity (Maybe a))
null :: Col Result ('Spec labels defaulting (Maybe a))
null = R Nothing
nullifier :: ()
=> SSpec ('Spec labels necessity a)
-> Col Result ('Spec labels necessity a)
-> Col Result ('Spec labels necessity (Nullify a))
=> SSpec ('Spec labels defaulting a)
-> Col Result ('Spec labels defaulting a)
-> Col Result ('Spec labels defaulting (Nullify a))
nullifier SSpec {nullity} (R a) = R $ case nullity of
Null -> a
NotNull -> Just a
unnullifier :: ()
=> SSpec ('Spec labels necessity a)
-> Col Result ('Spec labels necessity (Nullify a))
-> Maybe (Col Result ('Spec labels necessity a))
=> SSpec ('Spec labels defaulting a)
-> Col Result ('Spec labels defaulting (Nullify a))
-> Maybe (Col Result ('Spec labels defaulting a))
unnullifier SSpec {nullity} (R a) =
case nullity of
Null -> pure $ R a
@ -63,14 +63,14 @@ unnullifier SSpec {nullity} (R a) =
vectorizer :: Functor f
=> SSpec ('Spec labels necessity a)
-> f (Col Result ('Spec labels necessity a))
-> Col Result ('Spec labels 'Required (f a))
=> SSpec ('Spec labels defaulting a)
-> f (Col Result ('Spec labels defaulting a))
-> Col Result ('Spec labels 'NoDefault (f a))
vectorizer _ = R . fmap unR
unvectorizer :: Functor f
=> SSpec ('Spec labels necessity a)
-> Col Result ('Spec labels 'Required (f a))
-> f (Col Result ('Spec labels necessity a))
=> SSpec ('Spec labels defaulting a)
-> Col Result ('Spec labels 'NoDefault (f a))
-> f (Col Result ('Spec labels defaulting a))
unvectorizer _ (R results) = R <$> results

View File

@ -6,7 +6,7 @@
module Rel8.Schema.Spec
( Spec( Spec )
, SSpec( SSpec, labels, necessity, info, nullity )
, SSpec( SSpec, labels, defaulting, info, nullity )
, KnownSpec( specSing )
)
where
@ -17,10 +17,10 @@ import Prelude ()
-- rel8
import Rel8.Kind.Labels ( Labels, SLabels, KnownLabels, labelsSing )
import Rel8.Kind.Necessity
( Necessity
, SNecessity
, KnownNecessity, necessitySing
import Rel8.Kind.Defaulting
( Defaulting
, SDefaulting
, KnownDefaulting, defaultingSing
)
import Rel8.Schema.Null ( Nullity, Sql, Unnullify, nullable )
import Rel8.Type ( DBType, typeInformation )
@ -28,18 +28,18 @@ import Rel8.Type.Information ( TypeInformation )
type Spec :: Type
data Spec = Spec Labels Necessity Type
data Spec = Spec Labels Defaulting Type
type SSpec :: Spec -> Type
data SSpec spec where
SSpec ::
{ labels :: SLabels labels
, necessity :: SNecessity necessity
, defaulting :: SDefaulting defaulting
, info :: TypeInformation (Unnullify a)
, nullity :: Nullity a
}
-> SSpec ('Spec labels necessity a)
-> SSpec ('Spec labels defaulting a)
type KnownSpec :: Spec -> Constraint
@ -49,14 +49,14 @@ class KnownSpec spec where
instance
( KnownLabels labels
, KnownNecessity necessity
, KnownDefaulting defaulting
, Sql DBType a
)
=> KnownSpec ('Spec labels necessity a)
=> KnownSpec ('Spec labels defaulting a)
where
specSing = SSpec
{ labels = labelsSing
, necessity = necessitySing
, defaulting = defaultingSing
, info = typeInformation
, nullity = nullable
}

View File

@ -31,13 +31,13 @@ import Rel8.Schema.Spec ( Spec( Spec ), SSpec( SSpec, nullity ) )
type ConstrainDBType :: (Type -> Constraint) -> Spec -> Constraint
class
( forall c labels necessity a. ()
=> (spec ~ 'Spec labels necessity a)
( forall c labels defaulting a. ()
=> (spec ~ 'Spec labels defaulting a)
=> (forall x. (constraint x => c x)) => Sql c a
)
=> ConstrainDBType constraint spec
instance
( spec ~ 'Spec labels necessity a
( spec ~ 'Spec labels defaulting a
, Sql constraint a
)
=> ConstrainDBType constraint spec
@ -69,9 +69,9 @@ fromNullityDict NotNull Dict = Dict
nullifier :: ()
=> SSpec ('Spec labels necessity a)
-> Dict (ConstrainDBType c) ('Spec labels necessity a)
-> Dict (ConstrainDBType c) ('Spec labels necessity (Nullify a))
=> SSpec ('Spec labels defaulting a)
-> Dict (ConstrainDBType c) ('Spec labels defaulting a)
-> Dict (ConstrainDBType c) ('Spec labels defaulting (Nullify a))
nullifier SSpec {} dict = case dbTypeDict dict of
Dict -> case dbTypeNullity dict of
Null -> Dict
@ -79,9 +79,9 @@ nullifier SSpec {} dict = case dbTypeDict dict of
unnullifier :: ()
=> SSpec ('Spec labels necessity a)
-> Dict (ConstrainDBType c) ('Spec labels necessity (Nullify a))
-> Dict (ConstrainDBType c) ('Spec labels necessity a)
=> SSpec ('Spec labels defaulting a)
-> Dict (ConstrainDBType c) ('Spec labels defaulting (Nullify a))
-> Dict (ConstrainDBType c) ('Spec labels defaulting a)
unnullifier SSpec {nullity} dict = case dbTypeDict dict of
Dict -> case nullity of
Null -> Dict

View File

@ -22,10 +22,10 @@ import Rel8.Schema.Spec ( Spec( Spec ) )
type ConstrainType :: (Type -> Constraint) -> Spec -> Constraint
class
( forall labels necessity a. ()
=> (spec ~ 'Spec labels necessity a)
( forall labels defaulting a. ()
=> (spec ~ 'Spec labels defaulting a)
=> constraint a
) =>
ConstrainType constraint spec
instance (spec ~ 'Spec labels necessity a, constraint a) =>
instance (spec ~ 'Spec labels defaulting a, constraint a) =>
ConstrainType constraint spec

View File

@ -14,7 +14,7 @@ import Prelude
-- rel8
import Rel8.Expr ( Col( E ) )
import Rel8.Kind.Necessity ( SNecessity( SOptional, SRequired ) )
import Rel8.Kind.Defaulting ( SDefaulting( SHasDefault, SNoDefault ) )
import Rel8.Schema.HTable ( hfield, htabulate, hspecs )
import Rel8.Schema.Insert ( Inserts, Col( I ), Create(..) )
import Rel8.Schema.Spec ( SSpec(..) )
@ -43,7 +43,7 @@ toInsert (toColumns -> exprs) = fromColumns $ htabulate $ \field ->
toInsertDefaults :: Inserts exprs inserts => exprs -> inserts
toInsertDefaults (toColumns -> exprs) = fromColumns $ htabulate $ \field ->
case hfield hspecs field of
SSpec {necessity} -> case hfield exprs field of
E expr -> I $ case necessity of
SRequired -> Value expr
SOptional -> Default
SSpec {defaulting} -> case hfield exprs field of
E expr -> I $ case defaulting of
SNoDefault -> Value expr
SHasDefault -> Default

View File

@ -43,7 +43,7 @@ import Rel8.Expr.Opaleye
, fromColumn, toColumn
, scastExpr
)
import Rel8.Kind.Necessity ( SNecessity( SRequired, SOptional ) )
import Rel8.Kind.Defaulting ( SDefaulting( SNoDefault, SHasDefault ) )
import Rel8.Schema.HTable ( htabulateA, hfield, htraverse, hspecs, htabulate )
import Rel8.Schema.Insert ( Col( I ), Create(..), Insert, Inserts )
import Rel8.Schema.Name ( Col( N ), Name( Name ), Selects )
@ -100,12 +100,12 @@ tableFields (toColumns -> names) = dimap toColumns fromColumns $
name -> lmap (`hfield` field) (go specs name)
where
go :: SSpec spec -> Col Name spec -> Opaleye.TableFields (Col Insert spec) (Col Expr spec)
go SSpec {necessity} (N (Name name)) = case necessity of
SRequired ->
go SSpec {defaulting} (N (Name name)) = case defaulting of
SNoDefault ->
lmap (\(I (Value a)) -> toColumn $ toPrimExpr a) $
E . fromPrimExpr . fromColumn <$>
Opaleye.requiredTableField name
SOptional ->
SHasDefault ->
lmap (\(I ma) -> toColumn . toPrimExpr <$> fromInsert ma) $
E . fromPrimExpr . fromColumn <$>
Opaleye.optionalTableField name