graphula-2.1.0.0: A simple interface for generating persistent data and linking its dependencies
Safe HaskellSafe-Inferred
LanguageHaskell2010

Graphula.Dependencies

Synopsis

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 Arbitrary
'SourceExternal  -- explicitly pass a key using nodeKeyed

Most types will use SourceDefault or SourceArbitrary. Only use SourceExternal if the key for a value is always defined externally.

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.

newtype Only a Source #

For entities that only have singular Dependencies

Constructors

Only 

Fields

Instances

Instances details
Foldable Only Source # 
Instance details

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 #

toList :: Only a -> [a] #

null :: Only a -> Bool #

length :: Only a -> Int #

elem :: Eq a => a -> Only a -> Bool #

maximum :: Ord a => Only a -> a #

minimum :: Ord a => Only a -> a #

sum :: Num a => Only a -> a #

product :: Num a => Only a -> a #

Traversable Only Source # 
Instance details

Defined in Graphula.Dependencies

Methods

traverse :: Applicative f => (a -> f b) -> Only a -> f (Only b) #

sequenceA :: Applicative f => Only (f a) -> f (Only a) #

mapM :: Monad m => (a -> m b) -> Only a -> m (Only b) #

sequence :: Monad m => Only (m a) -> m (Only a) #

Functor Only Source # 
Instance details

Defined in Graphula.Dependencies

Methods

fmap :: (a -> b) -> Only a -> Only b #

(<$) :: a -> Only b -> Only a #

Generic (Only a) Source # 
Instance details

Defined in Graphula.Dependencies

Associated Types

type Rep (Only a) :: Type -> Type #

Methods

from :: Only a -> Rep (Only a) x #

to :: Rep (Only a) x -> Only a #

Show a => Show (Only a) Source # 
Instance details

Defined in Graphula.Dependencies

Methods

showsPrec :: Int -> Only a -> ShowS #

show :: Only a -> String #

showList :: [Only a] -> ShowS #

Eq a => Eq (Only a) Source # 
Instance details

Defined in Graphula.Dependencies

Methods

(==) :: Only a -> Only a -> Bool #

(/=) :: Only a -> Only a -> Bool #

Ord a => Ord (Only a) Source # 
Instance details

Defined in Graphula.Dependencies

Methods

compare :: Only a -> Only a -> Ordering #

(<) :: Only a -> Only a -> Bool #

(<=) :: Only a -> Only a -> Bool #

(>) :: Only a -> Only a -> Bool #

(>=) :: Only a -> Only a -> Bool #

max :: Only a -> Only a -> Only a #

min :: Only a -> Only a -> Only a #

type Rep (Only a) Source # 
Instance details

Defined in Graphula.Dependencies

type Rep (Only a) = D1 ('MetaData "Only" "Graphula.Dependencies" "graphula-2.1.0.0-Fs2W3DcwjfEHLHGrmODeEC" 'True) (C1 ('MetaCons "Only" 'PrefixI 'True) (S1 ('MetaSel ('Just "fromOnly") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))
type Keys (Only (Entity a)) Source # 
Instance details

Defined in Graphula.Key

type Keys (Only (Entity a)) = Only (Key a)

only :: a -> Only a Source #

Non-serial keys

data KeySourceType Source #

Constructors

SourceDefault

Generate keys using the database's DEFAULT strategy

SourceArbitrary

Generate keys using the Arbitrary instance for the Key

SourceExternal

Always explicitly pass an external key

See nodeKeyed.

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.

type KeyForInsert record = KeyRequirementForInsertInternal record (Key record) Source #

When Graphula inserts into Persistent, this is the record's key.

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 #

justKey :: key -> requirement key Source #

Instances

Instances details
InsertWithPossiblyRequiredKey Optional Source # 
Instance details

Defined in Graphula.Dependencies

Associated Types

type InsertConstraint Optional :: Type -> Constraint Source #

InsertWithPossiblyRequiredKey Required Source # 
Instance details

Defined in Graphula.Dependencies

Associated Types

type InsertConstraint Required :: Type -> Constraint Source #

newtype Required a Source #

Constructors

Required a 

Instances

Instances details
InsertWithPossiblyRequiredKey Required Source # 
Instance details

Defined in Graphula.Dependencies

Associated Types

type InsertConstraint Required :: Type -> Constraint Source #

type InsertConstraint Required Source # 
Instance details

Defined in Graphula.Dependencies

newtype Optional a Source #

Constructors

Optional (Maybe a) 

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

Instances details
(GenerateKeyInternal (KeySource a) a, KeyConstraint (KeySource a) a, InsertWithPossiblyRequiredKey (KeySourceTypeInternalM (KeySource a)), InsertConstraint (KeySourceTypeInternalM (KeySource a)) a) => GenerateKey a Source # 
Instance details

Defined in Graphula.Dependencies

generateKey :: (GenerateKeyInternal s a, KeyConstraint s a) => Gen (KeySourceTypeInternalM s (Key a)) Source #