haskell-neo4j-client 0.3.0.5 → 0.3.0.6
raw patch · 3 files changed
+48/−4 lines, 3 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ Database.Neo4j.Transactional.Cypher: rollbackAndLeave :: Text -> Transaction ()
Files
- haskell-neo4j-client.cabal +1/−1
- src/Database/Neo4j/Transactional/Cypher.hs +18/−3
- tests/IntegrationTests.hs +29/−0
haskell-neo4j-client.cabal view
@@ -1,5 +1,5 @@ name: haskell-neo4j-client-version: 0.3.0.5+version: 0.3.0.6 synopsis: A Haskell neo4j client description: Library to interact with Neo4j databases.
src/Database/Neo4j/Transactional/Cypher.hs view
@@ -12,7 +12,7 @@ -- > ... -- > res <- TC.runTransaction $ do -- > -- Queries return a result with columns, rows, a list of graphs and stats--- > result <- T.cypher "CREATE (pere: PERSON {age: {age}}) CREATE (pau: PERSON {props}) \+-- > result <- TC.cypher "CREATE (pere: PERSON {age: {age}}) CREATE (pau: PERSON {props}) \ -- > \CREATE p1 = (pere)-[:KNOWS]->(pau) RETURN pere, pau, p1, pere.age" $ -- > M.fromList [("age", TC.newparam (78 :: Int64)), -- > ("props", TC.ParamProperties $ M.fromList["age" |: (99 :: Int64)])]@@ -26,7 +26,7 @@ -- * Types Result(..), Stats(..), ParamValue(..), Params, newparam, emptyStats, TransError, Transaction, -- * Sending queries- loneQuery, runTransaction, cypher, rollback, commit, keepalive, commitWith,+ loneQuery, runTransaction, cypher, rollback, commit, keepalive, commitWith, rollbackAndLeave, -- * Aux functions isSuccess, fromResult, fromSuccess ) where@@ -203,7 +203,8 @@ -- | If a query returns an error we have to stop processing the transaction and make sure it's rolled back catchErrors :: Transaction a -> Transaction a catchErrors t = catchE t handle- where handle err = do+ where handle err@("Rollback", _) = ExceptT $ return (Left err)+ handle err = do rollback ExceptT $ return (Left err) @@ -238,6 +239,20 @@ liftIO $ rollbackReq conn transId void $ R.unprotect key lift $ put TransDone+ TransDone -> liftIO $ Exc.throw TransactionEndedExc++-- | Rollback a transaction and stop processing it, set the message that runTransaction will return as error+rollbackAndLeave :: T.Text -> Transaction ()+rollbackAndLeave msg = do+ conn <- ask+ st <- lift get+ case st of+ TransInit -> throwE ("Rollback", msg)+ TransStarted key transId -> do+ liftIO $ rollbackReq conn transId+ void $ R.unprotect key+ lift $ put TransDone+ throwE ("Rollback", msg) TransDone -> liftIO $ Exc.throw TransactionEndedExc -- | Commit a transaction.
tests/IntegrationTests.hs view
@@ -1495,3 +1495,32 @@ ("props", TC.ParamProperties $ M.fromList["age" |: (99 :: Int64)])] TC.rollback return result++-- | Test a cypher rollback and leave transaction+case_cypherTransactionRollbackAndLeave :: Assertion+case_cypherTransactionRollbackAndLeave = withConnection host port $ do+ res <- TC.runTransaction $ do+ void $ TC.cypher "CREATE (pepe: PERSON {age: 55})" M.empty+ result <- TC.cypher "CREATE (pere: PERSON {age: {age}}) CREATE (pau: PERSON {props}) \+ \CREATE p1 = (pere)-[:KNOWS]->(pau) RETURN pere, pau, p1, pere.age" $+ M.fromList [("age", TC.newparam (78 :: Int64)),+ ("props", TC.ParamProperties $ M.fromList["age" |: (99 :: Int64)])]+ TC.rollbackAndLeave "My message"+ TC.commit+ TC.rollback+ return result+ neo4jEqual (Left ("Rollback", "My message")) res++-- | Test issuing a commits after a rollback+case_cypherTransactionEnded :: Assertion+case_cypherTransactionEnded = assertException expException $ withConnection host port $ do+ void $ TC.runTransaction $ do+ void $ TC.cypher "CREATE (pepe: PERSON {age: 55})" M.empty+ result <- TC.cypher "CREATE (pere: PERSON {age: {age}}) CREATE (pau: PERSON {props}) \+ \CREATE p1 = (pere)-[:KNOWS]->(pau) RETURN pere, pau, p1, pere.age" $+ M.fromList [("age", TC.newparam (78 :: Int64)),+ ("props", TC.ParamProperties $ M.fromList["age" |: (99 :: Int64)])]+ TC.rollback+ TC.commit+ return result+ where expException = TransactionEndedExc