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

Graphula.Node

Synopsis

Generating

node :: forall a m. (MonadGraphula m, Logging m a, Arbitrary a, HasDependencies a, GenerateKey a, PersistEntityBackend a ~ SqlBackend, PersistEntity a, Typeable a, GraphulaSafeToInsert a) => Dependencies a -> NodeOptions a -> m (Entity a) Source #

Generate a node with a default (Database-provided) key

a <- node @A () mempty

nodeKeyed :: forall a m. (MonadGraphula m, Logging m a, Arbitrary a, HasDependencies a, PersistEntityBackend a ~ SqlBackend, PersistEntity a, Typeable a, GraphulaSafeToInsert a) => Key a -> Dependencies a -> NodeOptions a -> m (Entity a) Source #

Generate a node with an explictly-given key

let someKey = UUID.fromString "..."
a <- nodeKeyed @A someKey () mempty

NodeOptions

data NodeOptions a Source #

Options for generating an individual node

NodeOptions can be created and combined with the Monoidal operations (<>) and mempty.

a1 <- node @A () mempty
a2 <- node @A () $ edit $ \a -> a { someField = True }
a3 <- node @A () $ ensure $ (== True) . someField

Instances

Instances details
Monoid (NodeOptions a) Source # 
Instance details

Defined in Graphula.Node

Semigroup (NodeOptions a) Source # 
Instance details

Defined in Graphula.Node

Generic (NodeOptions a) Source # 
Instance details

Defined in Graphula.Node

Associated Types

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

Methods

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

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

type Rep (NodeOptions a) Source # 
Instance details

Defined in Graphula.Node

type Rep (NodeOptions a)

edit :: (a -> a) -> NodeOptions a Source #

Modify the node after it's been generated

a <- node @A () $ edit $ \a -> a { someField = True }

ensure :: (a -> Bool) -> NodeOptions a Source #

Require a node to satisfy the specified predicate

a <- node @A () $ ensure $ (== True) . someField

N.B. ensuring a condition that is infrequently met can be innefficient.

Exceptions