hasbolt-extras- Extras for hasbolt library

Safe HaskellNone




makeNodeLike :: Name -> Q [Dec] Source #

Make an instance of NodeLike class. Only data types with one constructor are currently supported. Each field is transformed into Text key and its value is transformed into a Value. For example, we have a structure

data Foo = Bar { baz  :: Double
               , quux :: Text
               , quuz :: Int

You can make it instance of NodeLike by writing

makeNodeLike ''Foo

Then you may create example and convert it into from from Node:

ghci> :set -XOverloadedStrings
ghci> let foo = Bar 42.0 "Loren ipsum" 7
ghci> toNode foo
Node {nodeIdentity = -1, labels = ["Foo"], nodeProps = fromList [("baz",F 42.0),("quux",T "Loren ipsum"),("quuz",I 7)]}
ghci> fromNode . toNode $ foo :: Foo
Bar {baz = 42.0, quux = "Loren ipsum", quuz = 7}

makeURelationLike :: Name -> Q [Dec] Source #

Make an instance of URelationLike class. Transformations are the same as in NodeLike instance declaration with the only one difference: URelationship holds only one label (or type), but Node holds list of labels.