packages feed

haskell-neo4j-client 0.3.0.7 → 0.3.0.8

raw patch · 4 files changed

+85/−17 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

haskell-neo4j-client.cabal view
@@ -1,5 +1,5 @@ name:                haskell-neo4j-client-version:             0.3.0.7+version:             0.3.0.8 synopsis:            A Haskell neo4j client description:              Library to interact with Neo4j databases. 
src/Database/Neo4j.hs view
@@ -24,7 +24,7 @@         setProperty, deleteProperties, deleteProperty,      -- * Managing nodes     Node, getNodeProperties, createNode, getNode, deleteNode, nodeId, nodePath, runNodeIdentifier, NodeIdentifier(..),-    NodePath(..),+         NodePath(..),     -- * Managing relationships     Relationship, Direction(..), RelationshipType, createRelationship, getRelationship, deleteRelationship,         getRelationships, relId, relPath, allRelationshipTypes, getRelProperties, getRelType, runRelIdentifier,
src/Database/Neo4j/Graph.hs view
@@ -232,18 +232,19 @@  -- | Filter the nodes of a graph nodeFilter :: (Node -> Bool) -> Graph -> Graph-nodeFilter f g = foldl (\gacc n -> if f n then deleteNode n gacc else gacc) g (M.elems $ nodes g)+nodeFilter f g = foldl (\gacc n -> if f n then gacc else deleteNode n gacc) g (M.elems $ nodes g)  -- | Filter the relationships of a graph relationshipFilter :: (Relationship -> Bool) -> Graph -> Graph-relationshipFilter f g = foldl (\gacc r -> if f r then deleteRelationship r gacc else gacc) g (M.elems $ rels g)+relationshipFilter f g = foldl (\gacc r -> if f r then gacc else deleteRelationship r gacc) g (M.elems $ rels g)  -- | Add two graphs resulting in a graph with all the nodes, labels and relationships of both -- | If a node/entity is present in both the second one will be chosen union :: Graph -> Graph -> Graph-union ga gb = addRels ga (addNodes ga gb)-    where addRels g1 g2 = foldl (flip addRelationship) g1 (M.elems $ rels g2)-          addNodes g1 g2 = foldl (flip addNode) g1 (M.elems $ nodes g2)+union ga gb = addLabels (addRels (addNodes ga gb) gb) gb+    where addRels g1 g2 = foldl (\gacc r -> addRelationship r gacc) g1 (getRelationships g2)+          addNodes g1 g2 = foldl (flip addNode) g1 (getNodes g2)+          addLabels g1 g2 = foldl (\gacc n -> setNodeLabels n (HS.toList $ getNodeLabels n g2) gacc) g1 (getNodes g2)  -- | Remove the nodes and relationships in the first graph that appear in the second difference :: Graph -> Graph -> Graph
tests/IntegrationTests.hs view
@@ -2,7 +2,7 @@ {-# LANGUAGE FlexibleInstances, TemplateHaskell #-} module Main where -import Control.Monad (void)+import Control.Monad (void, join) import Control.Monad.IO.Class (MonadIO, liftIO) import Data.Monoid (Monoid, mappend) import Data.Int (Int64)@@ -77,6 +77,16 @@ host :: Hostname host = "localhost" +someOtherProperties :: Properties+someOtherProperties = M.fromList ["hola" |: ("adeu" :: T.Text), "proparray" |: ["a" :: T.Text, "", "adeu"]]++anotherProperties :: Properties+anotherProperties = M.empty++myRelType :: T.Text+myRelType = "MYREL"++ -- | Test connecting to a non-existing server case_NoConnection :: Assertion case_NoConnection = assertException expException $ withConnection "localhost" 77 $ createNode someProperties@@ -299,15 +309,6 @@         return ()     where valName = "noproperty" -someOtherProperties :: Properties-someOtherProperties = M.fromList ["hola" |: ("adeu" :: T.Text), "proparray" |: ["a" :: T.Text, "", "adeu"]]--anotherProperties :: Properties-anotherProperties = M.empty--myRelType :: T.Text-myRelType = "MYREL"- setupRelTests :: Neo4j (Node, Node, Relationship) setupRelTests = do     nodeFrom <- createNode anotherProperties@@ -1524,3 +1525,69 @@             TC.commit             return result     where expException = TransactionEndedExc++-- | Test graph union op+case_graphUnion :: Assertion+case_graphUnion = withConnection host port $ do+                g <- B.runBatch $ do+                    n1 <- B.createNode someProperties+                    n2 <- B.createNode anotherProperties+                    void $ B.addLabels ["a"] n1+                    _ <- B.createRelationship "type1" someOtherProperties n1 n2+                    B.createRelationship "type2" someProperties n2 n1+                g2 <- B.runBatch $ do+                    n1 <- B.createNode someOtherProperties+                    n2 <- B.createNode anotherProperties+                    void $ B.addLabels ["b"] n1+                    _ <- B.createRelationship "type1" someOtherProperties n1 n2+                    B.createRelationship "type2" someProperties n2 n1+                let g3 = g `G.union` g2+                let g4 = G.addRelationship (head $ G.getRelationships g) g2+                neo4jEqual 3 (length $ G.getRelationships g4)+                neo4jEqual 4 (length $ G.getNodes g3)+                neo4jEqual 4 (length $ G.getRelationships g3)+                neo4jBool $ someOtherProperties `elem` map getRelProperties (G.getRelationships g3)+                neo4jBool $ someProperties `elem` map getRelProperties (G.getRelationships g3)+                neo4jBool $ someOtherProperties `elem` map getNodeProperties (G.getNodes g3)+                neo4jBool $ someProperties `elem` map getNodeProperties (G.getNodes g3)+                neo4jBool $ "type1" `elem` map getRelType (G.getRelationships g3)+                neo4jBool $ "type2" `elem` map getRelType (G.getRelationships g3)+                neo4jBool $ "a" `elem` (join $ map (HS.toList . (flip G.getNodeLabels g3)) (G.getNodes g3))+                neo4jBool $ "b" `elem` (join $ map (HS.toList . (flip G.getNodeLabels g3)) (G.getNodes g3))+                mapM_ deleteRelationship (G.getRelationships g3)+                mapM_ deleteNode (G.getNodes g3)++-- | Test graph difference op+case_graphDifference :: Assertion+case_graphDifference = withConnection host port $ do+                g <- B.runBatch $ do+                    n1 <- B.createNode someProperties+                    n2 <- B.createNode anotherProperties+                    void $ B.addLabels ["a"] n1+                    _ <- B.createRelationship "type1" someOtherProperties n1 n2+                    B.createRelationship "type2" someProperties n2 n1+                let g2 = g `G.difference` g+                neo4jEqual 0 (length $ G.getRelationships g2)+                neo4jEqual 0 (length $ G.getNodes g2)+                let subGraph = G.deleteNode (head $ G.getNodes g) g+                let g3 = g `G.difference` (G.deleteRelationship (head $ G.getRelationships subGraph) subGraph)+                neo4jEqual 1 (length $ G.getRelationships g3)+                neo4jEqual 1 (length $ G.getNodes g3)++-- | Test graph intersection op+case_graphIntersection :: Assertion+case_graphIntersection = withConnection host port $ do+                g <- B.runBatch $ do+                    n1 <- B.createNode someProperties+                    n2 <- B.createNode anotherProperties+                    void $ B.addLabels ["a"] n1+                    _ <- B.createRelationship "type1" someOtherProperties n1 n2+                    B.createRelationship "type2" someProperties n2 n1+                g2 <- B.runBatch $ do+                    B.createNode someProperties+                let g3 = G.addNode (head $ G.getNodes g) g2+                let g4 = g `G.intersection` (G.addRelationship (head $ G.getRelationships g) g3)+                neo4jEqual 1 (length $ G.getRelationships g4)+                neo4jEqual 1 (length $ G.getNodes g4)+                neo4jEqual (head $ G.getRelationships g) (head $ G.getRelationships g4)+                neo4jEqual (head $ G.getNodes g) (head $ G.getNodes g4)