zmactep / hasbolt Goto Github PK
View Code? Open in Web Editor NEWHaskell driver for Neo4j 3+ (BOLT protocol)
License: BSD 3-Clause "New" or "Revised" License
Haskell driver for Neo4j 3+ (BOLT protocol)
License: BSD 3-Clause "New" or "Revised" License
Hi,
great driver. But would it be possible to remove the logging output recently added (that you refer to in code comments as 'useless' :) ).
thanks,
S.
Is there a specific reason why hasbolt doesnt implement these instances? If you've just forgotten, I can send a pull request with these instances implemented.
Trying to use Hasbolt to connect to a GrapheneDB database gives the error:
Network.Socket.recvBuf: resource vanished (Connection reset by peer)
I am using the following config:
demoUser :: BoltCfg
demoUser = def
{ user = "demo-user"
, password = "..."
, host = "hobby-jb...pl.dbs.graphenedb.com"
, port = 24786
}
Connecting with these credentials works fine with other Neo4j drivers.
I defined a data type
data A = A B C D
type B = Text
type C = Bool
type D = Int
and i want to build a function that takes an A
type and builds a node with label A
and properties b
,c
and d
out of it as follows
typeAtoNode pipe (A b c d) = run pipe $ query "create (n:A {B:b, C:c, D:d}) return n"
this however, rather understandably, throws an exception from Neo4j because the values of b
,c
, and d
don't actually get interpolated into the query.
I tried also using queryP
and also ran into a Neo4j exception there too as follows
typeAtoNode pipe (A b _ _) = run pipe $ queryP "create (n:A) where n.B contains {B} return n" (fromList [("B", T b)])
*** Exception: user error (code: "Neo.ClientError.Statement.SyntaxError", message: "Invalid input 'h': expected 'i/I' (line 1, column 18 (offset: 17))\n\"create (n:A) where n.B contains {B} return n\"\
How do I correctly use variables to interpolate node/relationship properties in the queries?
I suspect that the issue is with my understanding and not with the package itself, but I figured it'd be best to ask you for the clarification. Thanks for the help in advance!
I seem to have an affliction of fragile pipes. From what I've observed anytime I try to bind records returned by a query to a variable for later use, the pipe breaks immediately thereafter. Here's an example
>>>pipe <- connect $ def {user = "neo4j", password = "neo4j"}
(0.00 secs, 397,056 bytes)
>>>run pipe $ query "create (n) return n"
[fromList [("n",S (Structure {signature = 78, fields = [I 389,L [],M (fromList [])]}))]]
(0.00 secs, 567,568 bytes)
>>>run pipe $ query "match (n) return n"
[fromList [("n",S (Structure {signature = 78, fields = [I 389,L [],M (fromList [])]}))]]
(0.00 secs, 554,896 bytes)
>>>records <- run pipe $ query "create (n) return n"
(0.00 secs, 437,872 bytes)
>>>run pipe $ query "match (n) return n"
[]
(0.00 secs, 450,728 bytes)
>>>run pipe $ query "match (n) return n"
*** Exception: user error (Unknown error)
>>>run pipe $ query "match (n) return n"
*** Exception: sendBuf: resource vanished (Broken pipe)
>>>run pipe $ query "match (n) return n"
*** Exception: writev: resource vanished (Broken pipe)
>>>
How might I fix this issue?
Thanks again,
Kerim
I've been getting up and running with hasbolt today (thanks for creating the package by the way) and I've run into an issue which I've been able to solve. I felt that it'd be worth noting here.
If I simply set up the package with hasbolt as a dependency, then the following compiler error will be displayed on running stack build
:
/home/oscarsouth/haskellProjects/theHarmonicAlgorithm/app/Main.hs:10:17: error: Variable not in scope: def :: BoltCfg
|
10 | defaultConfig = def {user = "neo4j", password = "secret"}
| ^^^
-- While building custom Setup.hs for package theHarmonicAlgorithm-0.1.0.0 using:
/home/oscarsouth/.stack/setup-exe-cache/x86_64-linux-tinfo6/Cabal-simple_mPHDZzAJ_2.0.1.0_ghc-8.2.2 --builddir=.stack-work/dist/x86_64-linux-tinfo6/Cabal-2.0.1.0 build lib:theHarmonicAlgorithm exe:theHarmonicAlgorithm-exe --ghc-options " -ddump-hi -ddump-to-file -fdiagnostics-color=always"
Process exited with code: ExitFailure 1
If I add the following version (or earlier) of hasbolt as an extra-dep, the project will compile successfully:
extra-deps:
- hasbolt-0.1.1.3
However, any version of hasbolt above this (or none specified at lts-11.8) will fail to compile and return the above error.
I'm currently working with the version specified above, in order to 'sidestep' this issue.
Hope that this is helpful,
Let me know if you'd like any more info.
Thanks,
Oscar South
Hi! I want to use Hasbolt, and I'm trying to run the simple example shown on the post in the Neo4J blog.
main :: IO ()
main = do pipe <- connect myConfiguration
records <- run pipe $ query "MATCH (n:Person) WHERE n.name CONTAINS \"Tom\" RETURN n"
let first = head records
cruise <- first `at` "n" >>= exact :: IO Node
print cruise
close pipe
Everything works fine, and I do get the results, but I get an error when I try to use exact
that I can't even begin to understand...
Couldn't match type ‘BoltError’ with ‘UnpackError’ arising from a functional dependency between:
constraint ‘MonadError UnpackError (BoltActionT m0)’
arising from a use of ‘exact’
instance ‘MonadError BoltError (BoltActionT m)’
at <no location info>
In the second argument of ‘(>>=)’, namely ‘exact’
In a stmt of a 'do' block:
cruise <- first `at` "n" >>= exact :: IO Node
In the expression:
do pipe <- connect myConfiguration
records <- run pipe
$ query "MATCH (n:Person) WHERE n.root CONTAINS \"Tom\" RETURN n"
let first = head records
cruise <- first `at` "n" >>= exact :: IO Node
Any ideas?
Hello!
Since migrating from 0.1.1.2 to 0.1.2.1, the def
function appears to have disappeared. What should we use instead?
Thanks for your help and the excellent package!
it's a bit difficult to detach my Haskell code from my cypher queries, so it's not easy for me to use cypher-shell for realistic profiling; so I wonder: what's the best practice for profiling queries when using this library? is there a way of getting the profiling results of queries run by hasbolt
using the PROFILE
keyword?
Hi, thanks for making this. I can't seem to access the 'def' function. I've installed using cabal install hasbolt
.
$ ghci
GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help
Prelude> import Database.Bolt
Prelude Database.Bolt> pipe <- connect $ def { user = "neo4j", password = "xxxxx" }
<interactive>:2:19: error: Variable not in scope: def :: BoltCfg
<interactive>:2:32: error:
• Couldn't match expected type ‘Data.Text.Internal.Text’
with actual type ‘[Char]’
• In the ‘user’ field of a record
In the second argument of ‘($)’, namely
‘def {user = "neo4j", password = "zuhlke"}’
In the first argument of ‘GHC.GHCi.ghciStepIO ::
forall a. IO a -> IO a’, namely
‘connect $ def {user = "neo4j", password = "zuhlke"}’
<interactive>:2:52: error:
• Couldn't match expected type ‘Data.Text.Internal.Text’
with actual type ‘[Char]’
• In the ‘password’ field of a record
In the second argument of ‘($)’, namely
‘def {user = "neo4j", password = "zuhlke"}’
In the first argument of ‘GHC.GHCi.ghciStepIO ::
forall a. IO a -> IO a’, namely
‘connect $ def {user = "neo4j", password = "zuhlke"}’
Prelude Database.Bolt> [Ctrl-D]
Leaving GHCi.
$
Cheers,
Rob
I'm wondering if it would be a good idea to expose the ResponseError
constructors to allow users to make smarter decisions about errors.
For example the error type "Neo.ClientError.Schema.ConstraintValidationFailed" can sometimes be used to determine if there should be a user input error vs an internal server error. Similar to 400 vs 500 http error codes.
Or am I missing some other method to be able to distinguish between the error types in the KnownResponseFailure
?
I understand that neo4j 4 has dropped support for bolt version 1, which causes hasbolt connections to fail with the default version 1 requested.
Perhaps it's time to default to version 2?
I would also like to suggest that current error message be adjusted.
It presently reads "Cannot connect: unsupported server version".
I think that's misleading, and would suggest instead "Cannot connect: Requested Bolt protocol version unsupported".
thanks for the great work,
Stephen.
Pipes work great with resource-pool.
There seems to be a small issue that the pool can hang scrive/pool#28 perhaps for now hasbolt can only be used safely without resource-pool
This makes it hard to do anything with a returned structure.
Hi!
So, since the version 0.1.5.0
(see #28), we have initial support of Bolt Protocol v.3.
It contains:
You may choose { ... version = 3 ... }
in BoltCfg
, and everything should work even with the latest version of neo4j (4.2.6
). But we still do not support the extra
dictionary in "run query" and new transactions style (the old one from protocol v.2 seems to work). And of course, neo4j will drop the version 3 protocol soon, while version 4 has backward capability break again.
I see that I have to redesign a library a lot to support the newest features. So I have a question for all the users: should I still support the versions 1/2 of protocol or keep only the latest version? Or maybe I should make another library (like, hasbolt2
for the newest versions)? Or perhaps you are not interested in novel features and just need the basic statements supporting the latest versions of neo4j?
/polls "I need support of protocol versions 1/2" "I need the non-basic features of latest protocol versions" "I am ok to use the separate library for new/old protocol versions"
would you mind adding a Read
and Show
instance to BoltCfg
? if not, do you know a simple way of having an user specify the configuration? (there are many options, so anything I could think of would involve lots of boilerplate or adding a dependency on a specialized library)
Hi @zmactep , thanks for making this library!
I see that project looks a bit abandoned and I was wondering if you have thought at any point about introducing support for transactions?
I could give it a shot and see if I can implement it if you think it could be merged :)
consider a query of form
MERGE (x:SomeTag{a:"val1",b:"val"2,c:"val3"})
ON MATCH SET x.d = "val7", x.e = "val8", ... , x.z = "val9"
ON CREATE SET x.d = "val4", x.e = "val5", ... , x.z = "val6"
I seem to be hitting a limit of about 12 properties set before subsequent queries for nodes thus initialised results in a binary format decoding error, all using the Haskell hasbolt library. Less than this and all works fine.
A typical failing query would be:
MATCH (x:SomeTag{a:"val1",b:"val"2,c:"val3"}) RETURN x
results in
Cannot fetch: wrong message format (Error while decoding binary format: expected text)
This also seems to happen with SET += {12+ properties}
Happy to did in to diagnose, but just want to seek some commentary/guidance before I do.
thanks, S.
import Database.Bolt hiding (Value)
import qualified Data.Map.Strict as M
main :: IO ()
main = do pipe <- connect $ def {user = "neo4j", password = neo4j}
result <- run pipe $ queryP "MATCH (d {prop: {prop}}) return d;" M.empty
putStr "Result:"
print result
close pipe
With a neo4j db in default config the above program does not terminate
Query gives the following error:
Neo.ClientError.Request.InvalidFormat: Illegal struct size: Expected struct to be 1 fields but got 0
This happens because the specification has been changed, the spec now expects elemIds on everything
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.