| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Database.Bolt.Extras.Graph
Contents
Synopsis
- data Graph n a b = Graph {
- _vertices :: Map n a
- _relations :: Map (n, n) b
- vertices :: forall n a b a. Lens (Graph n a b) (Graph n a b) (Map n a) (Map n a)
- relations :: forall n a b b. Lens (Graph n a b) (Graph n a b) (Map (n, n) b) (Map (n, n) b)
- emptyGraph :: Ord n => Graph n a b
- addNode :: (Show n, Ord n) => n -> a -> Graph n a b -> Graph n a b
- addRelation :: (Show n, Ord n) => n -> n -> b -> Graph n a b -> Graph n a b
- type NodeName = Text
- relationName :: (NodeName, NodeName) -> Text
- class Requestable a where
- class Returnable a where
- isReturned' :: a -> Bool
- return' :: a -> Text
- class Extractable a where
- extract :: MonadIO m => Text -> [Record] -> BoltActionT m [a]
- data NodeGetter = NodeGetter {}
- data RelGetter = RelGetter {}
- class GetterLike a where
- withBoltId :: BoltId -> a -> a
- withLabel :: Label -> a -> a
- withLabelQ :: Name -> a -> a
- withProp :: (Text, Value) -> a -> a
- withReturn :: [Text] -> a -> a
- isReturned :: a -> a
- (#) :: a -> (a -> b) -> b
- defaultNode :: Bool -> NodeGetter
- defaultRel :: Bool -> RelGetter
- defaultNodeReturn :: NodeGetter
- defaultNodeNotReturn :: NodeGetter
- defaultRelReturn :: RelGetter
- defaultRelNotReturn :: RelGetter
- requestGetters :: [(NodeName, NodeGetter)] -> [((NodeName, NodeName), RelGetter)] -> (Text, [Text])
- allProps :: [Text]
- data NodeResult = NodeResult {}
- data RelResult = RelResult {}
- relationName :: (NodeName, NodeName) -> Text
- type GraphGetRequest = Graph NodeName NodeGetter RelGetter
- type GraphGetResponseA = Graph NodeName NodeResult RelResult
- type GraphGetResponseB = Graph NodeName Node URelationship
- class GraphQuery a where
- type NodeReq a :: *
- type RelReq a :: *
- type NodeRes a :: *
- type RelRes a :: *
- requestEntities :: (Requestable (NodeName, NodeReq a), Requestable ((NodeName, NodeName), RelReq a)) => [(NodeName, NodeReq a)] -> [((NodeName, NodeName), RelReq a)] -> (Text, [Text])
- formQuery :: (Requestable (NodeName, NodeReq a), Requestable ((NodeName, NodeName), RelReq a), Returnable (NodeName, NodeReq a), Returnable ((NodeName, NodeName), RelReq a)) => [Text] -> Graph NodeName (NodeReq a) (RelReq a) -> Text
- extractGraphs :: (Extractable (NodeRes a), Extractable (RelRes a), MonadIO m) => [NodeName] -> [(NodeName, NodeName)] -> [Record] -> BoltActionT m [Graph NodeName (NodeRes a) (RelRes a)]
- makeRequest :: (Requestable (NodeName, NodeReq a), Requestable ((NodeName, NodeName), RelReq a), Returnable (NodeName, NodeReq a), Returnable ((NodeName, NodeName), RelReq a), Extractable (NodeRes a), Extractable (RelRes a), MonadIO m) => [Text] -> Graph NodeName (NodeReq a) (RelReq a) -> BoltActionT m [Graph NodeName (NodeRes a) (RelRes a)]
- data GetRequestA = GetRequestA
- data GetRequestB = GetRequestB
- data PutRequestB = PutRequestB
- mergeGraphs :: GetBoltId a => [Graph NodeName a b] -> Graph NodeName a b
- data PutNode
- data PutRelationship
- type GraphPutRequest = Graph NodeName PutNode PutRelationship
- type GraphPutResponse = Graph NodeName BoltId BoltId
- requestPut :: [(NodeName, PutNode)] -> [((NodeName, NodeName), PutRelationship)] -> (Text, [Text])
Documentation
Graph contains vertices, that are parameterized by some type n, and relations,
that parameterized by pair of type n. This pair represents vertices, that are connected with this relation.
Constructors
| Graph | |
Fields
| |
Instances
| (Show n, Show a, Show b) => Show (Graph n a b) Source # | |
| Generic (Graph n a b) Source # | |
| type Rep (Graph n a b) Source # | |
Defined in Database.Bolt.Extras.Graph.Internal.AbstractGraph type Rep (Graph n a b) = D1 (MetaData "Graph" "Database.Bolt.Extras.Graph.Internal.AbstractGraph" "hasbolt-extras-0.0.0.15-HDWUrnwpJjRBwu6nqvxe91" False) (C1 (MetaCons "Graph" PrefixI True) (S1 (MetaSel (Just "_vertices") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Map n a)) :*: S1 (MetaSel (Just "_relations") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Map (n, n) b)))) | |
relations :: forall n a b b. Lens (Graph n a b) (Graph n a b) (Map (n, n) b) (Map (n, n) b) Source #
emptyGraph :: Ord n => Graph n a b Source #
Creates empty graph.
addNode :: (Show n, Ord n) => n -> a -> Graph n a b -> Graph n a b Source #
Adds node to graph by it's name and node content.
If graph already contains vertex with given name, error will be thrown.
addRelation :: (Show n, Ord n) => n -> n -> b -> Graph n a b -> Graph n a b Source #
Adds relation to graph by startName of vertex, endName of vertex, and rel with relation content.
If graph already contains relation with given (startName, endName), error will be thrown.
relationName :: (NodeName, NodeName) -> Text Source #
Creates relationship name from the names of its start and end nodes in the way `<startNodeName>0<endNodeName>`.
class Requestable a where Source #
Class describes entity, which can be requested.
Instances
| Requestable ((NodeName, NodeName), PutRelationship) Source # | |
Defined in Database.Bolt.Extras.Graph.Internal.Put | |
| Requestable ((NodeName, NodeName), RelGetter) Source # | |
| Requestable (NodeName, PutNode) Source # | |
| Requestable (NodeName, NodeGetter) Source # | |
Defined in Database.Bolt.Extras.Graph.Internal.Get | |
class Returnable a where Source #
Class describes entity, which can be returned.
Methods
isReturned' :: a -> Bool Source #
If the entity should be returned.
How to return entity in the Cypher.
Instances
| Returnable ((NodeName, NodeName), PutRelationship) Source # | |
Defined in Database.Bolt.Extras.Graph.Internal.Put Methods isReturned' :: ((NodeName, NodeName), PutRelationship) -> Bool Source # return' :: ((NodeName, NodeName), PutRelationship) -> Text Source # | |
| Returnable ((NodeName, NodeName), RelGetter) Source # | |
| Returnable (NodeName, PutNode) Source # | |
| Returnable (NodeName, NodeGetter) Source # | |
Defined in Database.Bolt.Extras.Graph.Internal.Get Methods isReturned' :: (NodeName, NodeGetter) -> Bool Source # | |
class Extractable a where Source #
Class describes entity, which can be extracted from records by name.
Instances
| Extractable Node Source # | BOLT FORMAT |
Defined in Database.Bolt.Extras.Graph.Internal.Get | |
| Extractable URelationship Source # | |
Defined in Database.Bolt.Extras.Graph.Internal.Get Methods extract :: MonadIO m => Text -> [Record] -> BoltActionT m [URelationship] Source # | |
| Extractable BoltId Source # | |
Defined in Database.Bolt.Extras.Graph.Internal.Put | |
| Extractable RelResult Source # | |
Defined in Database.Bolt.Extras.Graph.Internal.Get | |
| Extractable NodeResult Source # | |
Defined in Database.Bolt.Extras.Graph.Internal.Get Methods extract :: MonadIO m => Text -> [Record] -> BoltActionT m [NodeResult] Source # | |
Types for requesting nodes and relationships
data NodeGetter Source #
Helper to find Nodes.
Constructors
| NodeGetter | |
Instances
| Eq NodeGetter Source # | |
Defined in Database.Bolt.Extras.Graph.Internal.Get | |
| Show NodeGetter Source # | |
Defined in Database.Bolt.Extras.Graph.Internal.Get Methods showsPrec :: Int -> NodeGetter -> ShowS # show :: NodeGetter -> String # showList :: [NodeGetter] -> ShowS # | |
| GetterLike NodeGetter Source # | |
Defined in Database.Bolt.Extras.Graph.Internal.Get Methods withBoltId :: BoltId -> NodeGetter -> NodeGetter Source # withLabel :: Label -> NodeGetter -> NodeGetter Source # withLabelQ :: Name -> NodeGetter -> NodeGetter Source # withProp :: (Text, Value) -> NodeGetter -> NodeGetter Source # withReturn :: [Text] -> NodeGetter -> NodeGetter Source # isReturned :: NodeGetter -> NodeGetter Source # | |
| Returnable (NodeName, NodeGetter) Source # | |
Defined in Database.Bolt.Extras.Graph.Internal.Get Methods isReturned' :: (NodeName, NodeGetter) -> Bool Source # | |
| Requestable (NodeName, NodeGetter) Source # | |
Defined in Database.Bolt.Extras.Graph.Internal.Get | |
Helper to find URelationships.
Constructors
| RelGetter | |
Instances
| Eq RelGetter Source # | |
| Show RelGetter Source # | |
| GetterLike RelGetter Source # | |
Defined in Database.Bolt.Extras.Graph.Internal.Get Methods withBoltId :: BoltId -> RelGetter -> RelGetter Source # withLabel :: Label -> RelGetter -> RelGetter Source # withLabelQ :: Name -> RelGetter -> RelGetter Source # withProp :: (Text, Value) -> RelGetter -> RelGetter Source # withReturn :: [Text] -> RelGetter -> RelGetter Source # isReturned :: RelGetter -> RelGetter Source # | |
| Returnable ((NodeName, NodeName), RelGetter) Source # | |
| Requestable ((NodeName, NodeName), RelGetter) Source # | |
class GetterLike a where Source #
Helper to work with Getters.
Methods
Arguments
| :: BoltId | |
| -> a | |
| -> a | set known boltId |
Arguments
| :: Label | |
| -> a | |
| -> a | set known label |
Arguments
| :: [Text] | |
| -> a | |
| -> a | add list of properties to return |
Arguments
| :: a | |
| -> a | set that current node should be returned |
Instances
| GetterLike RelGetter Source # | |
Defined in Database.Bolt.Extras.Graph.Internal.Get Methods withBoltId :: BoltId -> RelGetter -> RelGetter Source # withLabel :: Label -> RelGetter -> RelGetter Source # withLabelQ :: Name -> RelGetter -> RelGetter Source # withProp :: (Text, Value) -> RelGetter -> RelGetter Source # withReturn :: [Text] -> RelGetter -> RelGetter Source # isReturned :: RelGetter -> RelGetter Source # | |
| GetterLike NodeGetter Source # | |
Defined in Database.Bolt.Extras.Graph.Internal.Get Methods withBoltId :: BoltId -> NodeGetter -> NodeGetter Source # withLabel :: Label -> NodeGetter -> NodeGetter Source # withLabelQ :: Name -> NodeGetter -> NodeGetter Source # withProp :: (Text, Value) -> NodeGetter -> NodeGetter Source # withReturn :: [Text] -> NodeGetter -> NodeGetter Source # isReturned :: NodeGetter -> NodeGetter Source # | |
defaultNode :: Bool -> NodeGetter Source #
defaultRel :: Bool -> RelGetter Source #
requestGetters :: [(NodeName, NodeGetter)] -> [((NodeName, NodeName), RelGetter)] -> (Text, [Text]) Source #
Takes all node getters and relationship getters and write them to single query to request. Also return conditions on known boltId-s.
Types for extracting nodes and relationships
data NodeResult Source #
AESON FORMAT
Result for node in the Aeson like format.
Constructors
| NodeResult | |
Instances
Result for relationship in the Aeson like format.
Instances
relationName :: (NodeName, NodeName) -> Text Source #
Creates relationship name from the names of its start and end nodes in the way `<startNodeName>0<endNodeName>`.
Graph types
type GraphGetRequest = Graph NodeName NodeGetter RelGetter Source #
The combinations of Getters to load graph from the database.
type GraphGetResponseA = Graph NodeName NodeResult RelResult Source #
The graph of Nodes and URelationships which we got from the database using GraphGetRequest,
converted to the Aeson Value like.
type GraphGetResponseB = Graph NodeName Node URelationship Source #
The graph of Nodes and URelationships which we got from the database using GraphGetRequest,
converted to the Bolt Value like.
class GraphQuery a where Source #
Type family used to perform requests to the Neo4j based on graphs.
Minimal complete definition
Associated Types
Type of entity, describing node for request.
Type of entity, describing relationship for request.
Type of node entity, which will be extracted from result.
Type of relationship entity, which will be extracted from result.
Methods
requestEntities :: (Requestable (NodeName, NodeReq a), Requestable ((NodeName, NodeName), RelReq a)) => [(NodeName, NodeReq a)] -> [((NodeName, NodeName), RelReq a)] -> (Text, [Text]) Source #
How to convert requestable entities to text in the query.
formQuery :: (Requestable (NodeName, NodeReq a), Requestable ((NodeName, NodeName), RelReq a), Returnable (NodeName, NodeReq a), Returnable ((NodeName, NodeName), RelReq a)) => [Text] -> Graph NodeName (NodeReq a) (RelReq a) -> Text Source #
Abstract function to form query for request.
extractGraphs :: (Extractable (NodeRes a), Extractable (RelRes a), MonadIO m) => [NodeName] -> [(NodeName, NodeName)] -> [Record] -> BoltActionT m [Graph NodeName (NodeRes a) (RelRes a)] Source #
Abstract function, which exctracts graph from records if nodes and relations can be extracted.
makeRequest :: (Requestable (NodeName, NodeReq a), Requestable ((NodeName, NodeName), RelReq a), Returnable (NodeName, NodeReq a), Returnable ((NodeName, NodeName), RelReq a), Extractable (NodeRes a), Extractable (RelRes a), MonadIO m) => [Text] -> Graph NodeName (NodeReq a) (RelReq a) -> BoltActionT m [Graph NodeName (NodeRes a) (RelRes a)] Source #
For given query graph, perform query and extract results graph.
Instances
data GetRequestA Source #
Get request with result in Aeson format. Easy way to show result graphs.
Constructors
| GetRequestA |
Instances
data GetRequestB Source #
Get request with result in Bolt format.
Easy way to extract results and convert them to another entities (using fromNode).
Constructors
| GetRequestB |
Instances
data PutRequestB Source #
Put request in Bolt format with BoltIds of uploaded entities as result.
Constructors
| PutRequestB |
Instances
mergeGraphs :: GetBoltId a => [Graph NodeName a b] -> Graph NodeName a b Source #
Helper function to merge graphs of results, i.e. if you requested graph A->B->C and in the database there were two B entities connected to the same entity A and four C entities, connected to the same two entities B, cypher query will return four graphs, which satisfy this path, despite the fact that A was presented only once in the database and B was presented only two times in the database. This function will merge these four graphs in one and return nodes by node names with suffixes equal to their BoltId-s.
For example, if there were four graphs: nodes: [A (boltId = 0), B (boltId = 1), C (boltId = 3)], relations: [A -> B, B -> C], nodes: [A (boltId = 0), B (boltId = 1), C (boltId = 4)], relations: [A -> B, B -> C], nodes: [A (boltId = 0), B (boltId = 2), C (boltId = 5)], relations: [A -> B, B -> C], nodes: [A (boltId = 0), B (boltId = 2), C (boltId = 6)], relations: [A -> B, B -> C], this function will merge them into new graph: nodes: [A0 (boltId = 0), B1 (boltId = 1), B2 (boltId = 2), C3 (boltId = 3), C4 (boltId = 4), C5 (boltId = 5), C6 (boltId = 6)], relations: [A0 -> B1, A0 -> B2, B1 -> C3, B1 -> C4, B2 -> C5, B2 -> C6].
data PutRelationship Source #
PutRelationship is the wrapper for Relationship where we can specify if we want to merge or create it.
Constructors
| MergeR URelationship | |
| CreateR URelationship |
Instances
| Show PutRelationship Source # | |
Defined in Database.Bolt.Extras.Graph.Internal.Put Methods showsPrec :: Int -> PutRelationship -> ShowS # show :: PutRelationship -> String # showList :: [PutRelationship] -> ShowS # | |
| Returnable ((NodeName, NodeName), PutRelationship) Source # | |
Defined in Database.Bolt.Extras.Graph.Internal.Put Methods isReturned' :: ((NodeName, NodeName), PutRelationship) -> Bool Source # return' :: ((NodeName, NodeName), PutRelationship) -> Text Source # | |
| Requestable ((NodeName, NodeName), PutRelationship) Source # | |
Defined in Database.Bolt.Extras.Graph.Internal.Put | |
type GraphPutRequest = Graph NodeName PutNode PutRelationship Source #
The graph of Nodes with specified uploading type and URelationships.
type GraphPutResponse = Graph NodeName BoltId BoltId Source #
The graph of PutNodes corresponding to the nodes and relationships
which we get after putting GraphPutRequest.
requestPut :: [(NodeName, PutNode)] -> [((NodeName, NodeName), PutRelationship)] -> (Text, [Text]) Source #
Takes all PutNodes and PutRelationships
and write them to single query to request.
Here WITH is used, because you cannot perform
"match", "merge" or "create" at the same query.