Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Graphula.Dependencies
Contents
Synopsis
- class HasDependencies a where
- type Dependencies a
- type KeySource a :: KeySourceType
- dependsOn :: a -> Dependencies a -> a
- newtype Only a = Only {
- fromOnly :: a
- only :: a -> Only a
- data KeySourceType
- type family KeySourceTypeM (t :: KeySourceType) :: Type -> Type where ...
- type KeyForInsert record = KeyRequirementForInsertInternal record (Key record)
- type KeyRequirementForInsert record = KeySourceTypeM (KeySource record)
- class InsertWithPossiblyRequiredKey (requirement :: Type -> Type) where
- type InsertConstraint requirement :: Type -> Constraint
- insertWithPossiblyRequiredKey :: (PersistEntityBackend record ~ SqlBackend, PersistEntity record, Monad m, MonadGraphulaFrontend m, InsertConstraint requirement record) => requirement (Key record) -> record -> m (Maybe (Entity record))
- justKey :: key -> requirement key
- newtype Required a = Required a
- newtype Optional a = Optional (Maybe a)
- class (GenerateKeyInternal (KeySource a) a, KeyConstraint (KeySource a) a, InsertWithPossiblyRequiredKey (KeySourceTypeInternalM (KeySource a)), InsertConstraint (KeySourceTypeInternalM (KeySource a)) a) => GenerateKey a
- generateKey :: (GenerateKeyInternal s a, KeyConstraint s a) => Gen (KeySourceTypeInternalM s (Key a))
Documentation
class HasDependencies a where Source #
Minimal complete definition
Nothing
Associated Types
type Dependencies a Source #
A data type declaring the model's dependencies
Models with no dependencies can declare an empty instance,
instance HasDependencies
School
Models with one dependency must use the Only
1-tuple constructor,
instance HasDependencies
Teacher where
type Dependencies Teacher = Only SchoolId
Models with multiple dependencies use tuple syntax,
instance HasDependencies
Course where
type Dependencies Course = (SchoolId, TeacherId)
type Dependencies _a = ()
type KeySource a :: KeySourceType Source #
Specify the method for resolving a node's key
This can be
'SourceDefault -- automatically generate keys from the database 'SourceArbitrary -- automatically generate keys using'SourceExternal -- explicitly pass a key using
Arbitrary
nodeKeyed
Most types will use SourceDefault
or SourceArbitrary
. Only use
SourceExternal
if the key for a value is always defined externally.
type KeySource _a = 'SourceDefault
Methods
dependsOn :: a -> Dependencies a -> a Source #
Assign values from the Dependencies
collection to a value
This must be an idempotent operation. Law:
(\x d -> x `dependsOn` d `dependsOn` d) = dependsOn
The default, Generic
-based implementation will assign values by the order
of the fields in the model's type.
default dependsOn :: (HasEot a, HasEot (Dependencies a), GHasDependencies (Proxy a) (Proxy (Dependencies a)) (Eot a) (Eot (Dependencies a))) => a -> Dependencies a -> a Source #
For entities that only have singular Dependencies
Instances
Foldable Only Source # | |
Defined in Graphula.Dependencies Methods fold :: Monoid m => Only m -> m # foldMap :: Monoid m => (a -> m) -> Only a -> m # foldMap' :: Monoid m => (a -> m) -> Only a -> m # foldr :: (a -> b -> b) -> b -> Only a -> b # foldr' :: (a -> b -> b) -> b -> Only a -> b # foldl :: (b -> a -> b) -> b -> Only a -> b # foldl' :: (b -> a -> b) -> b -> Only a -> b # foldr1 :: (a -> a -> a) -> Only a -> a # foldl1 :: (a -> a -> a) -> Only a -> a # elem :: Eq a => a -> Only a -> Bool # maximum :: Ord a => Only a -> a # | |
Traversable Only Source # | |
Functor Only Source # | |
Generic (Only a) Source # | |
Show a => Show (Only a) Source # | |
Eq a => Eq (Only a) Source # | |
Ord a => Ord (Only a) Source # | |
type Rep (Only a) Source # | |
Defined in Graphula.Dependencies | |
type Keys (Only (Entity a)) Source # | |
Non-serial keys
data KeySourceType Source #
Constructors
SourceDefault | Generate keys using the database's |
SourceArbitrary | |
SourceExternal | Always explicitly pass an external key See |
type family KeySourceTypeM (t :: KeySourceType) :: Type -> Type where ... Source #
When a user of Graphula inserts, this wraps the key they provide.
For SourceExternal
a key is required; for others it's optional.
Equations
KeySourceTypeM 'SourceExternal = Required | |
KeySourceTypeM _ = Optional |
type KeyForInsert record = KeyRequirementForInsertInternal record (Key record) Source #
When Graphula inserts into Persistent, this is the record's key.
type KeyRequirementForInsert record = KeySourceTypeM (KeySource record) Source #
class InsertWithPossiblyRequiredKey (requirement :: Type -> Type) where Source #
Associated Types
type InsertConstraint requirement :: Type -> Constraint Source #
Methods
insertWithPossiblyRequiredKey :: (PersistEntityBackend record ~ SqlBackend, PersistEntity record, Monad m, MonadGraphulaFrontend m, InsertConstraint requirement record) => requirement (Key record) -> record -> m (Maybe (Entity record)) Source #
Instances
InsertWithPossiblyRequiredKey Optional Source # | |
Defined in Graphula.Dependencies Associated Types type InsertConstraint Optional :: Type -> Constraint Source # Methods insertWithPossiblyRequiredKey :: (PersistEntityBackend record ~ SqlBackend, PersistEntity record, Monad m, MonadGraphulaFrontend m, InsertConstraint Optional record) => Optional (Key record) -> record -> m (Maybe (Entity record)) Source # | |
InsertWithPossiblyRequiredKey Required Source # | |
Defined in Graphula.Dependencies Associated Types type InsertConstraint Required :: Type -> Constraint Source # Methods insertWithPossiblyRequiredKey :: (PersistEntityBackend record ~ SqlBackend, PersistEntity record, Monad m, MonadGraphulaFrontend m, InsertConstraint Required record) => Required (Key record) -> record -> m (Maybe (Entity record)) Source # |
Constructors
Required a |
Instances
InsertWithPossiblyRequiredKey Required Source # | |
Defined in Graphula.Dependencies Associated Types type InsertConstraint Required :: Type -> Constraint Source # Methods insertWithPossiblyRequiredKey :: (PersistEntityBackend record ~ SqlBackend, PersistEntity record, Monad m, MonadGraphulaFrontend m, InsertConstraint Required record) => Required (Key record) -> record -> m (Maybe (Entity record)) Source # | |
type InsertConstraint Required Source # | |
Defined in Graphula.Dependencies |
Instances
InsertWithPossiblyRequiredKey Optional Source # | |
Defined in Graphula.Dependencies Associated Types type InsertConstraint Optional :: Type -> Constraint Source # Methods insertWithPossiblyRequiredKey :: (PersistEntityBackend record ~ SqlBackend, PersistEntity record, Monad m, MonadGraphulaFrontend m, InsertConstraint Optional record) => Optional (Key record) -> record -> m (Maybe (Entity record)) Source # | |
type InsertConstraint Optional Source # | |
Defined in Graphula.Dependencies |
class (GenerateKeyInternal (KeySource a) a, KeyConstraint (KeySource a) a, InsertWithPossiblyRequiredKey (KeySourceTypeInternalM (KeySource a)), InsertConstraint (KeySourceTypeInternalM (KeySource a)) a) => GenerateKey a Source #
Abstract constraint that some a
can generate a key
This is part of ensuring better error messages.
Instances
(GenerateKeyInternal (KeySource a) a, KeyConstraint (KeySource a) a, InsertWithPossiblyRequiredKey (KeySourceTypeInternalM (KeySource a)), InsertConstraint (KeySourceTypeInternalM (KeySource a)) a) => GenerateKey a Source # | |
Defined in Graphula.Dependencies |
generateKey :: (GenerateKeyInternal s a, KeyConstraint s a) => Gen (KeySourceTypeInternalM s (Key a)) Source #