-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parameters not working? #32
Comments
For background:
And in my |
hi there - I'm pretty sure the params support is working. Are you trying to use the mix task? If yes, I am not sure it can be used for something else than simple queries, as it was scoped as a convenience only. I'll have a look though. And, regarding the query you show in the comment above, you should probably try using a Neo4j.query!(Neo4j.conn, "CREATE (report:Report) SET report.test = {props}", %{props: "foo"}) |
Wait, are you referring to |
plus |
@cheerfulstoic please, check that the Bolt.Sips is started before you try to query, example, https://github.com/sirko-io/engine/blob/master/lib/sirko.ex#L10. It should solve your first problem with the socket. The second problem should be solved by @florinpatrascu 's suggestion about strings. |
Ah, sorry for the confusion. This is actually https://github.com/florinpatrascu/bolt_sips/blob/master/lib/mix/tasks/cypher.ex#L30 Though I'm not using the built-in task, I'm using my own custom mix task that I've created. I don't think it's a network issue because I do a Good catch about |
We actually have tests covering this, please see link. Excerpt: test "executing a Cpyher query, with map parameters", context do
conn = context[:conn]
cypher = """
CREATE(n:User {props})
"""
assert {:ok, _} = Bolt.Sips.query(conn, cypher, %{props: %{name: "Mep", bolt_sips: true}})
end |
hmmm, I believe I understand what is going on. Boltex is throwing an exception for nested maps. Will try to look into it later as I am caught into a project for work, unless @mschae or @dnesteryuk have a quicker answer?! :) an anticipated thanks guys! Basically this: # in boltex repo, run MIX_ENV=test iex -S mix
uri = Boltex.IntegrationCase.neo4j_uri
Boltex.test uri.host, uri.port, "CREATE (report:Report) SET report = {props}", %{props: %{foo: "bar", another_map: %{unu: 1, doi: 2}}}, uri.userinfo
%Boltex.Error{code: "Neo.ClientError.Statement.TypeError", connection_id: 43264,
function: :run_statement,
message: "Property values can only be of primitive types or arrays thereof",
type: :cypher_error} will also try to see if we can throw better errors from our end, but we pretty much echo back boltex' error messages. Good catch! |
for brevity, 1st test will pass, the 2nd one will fail (in Bolt.Sips) defmodule NodesAndProperties.Test do
use ExUnit.Case, async: true
alias Bolt.Sips, as: Neo4j
@simple_map %{foo: "bar", bolt_sips: true}
@nested_map %{foo: "bar", bolt_sips: true, a_map: %{unu: 1, doi: 2, baz: "foo"}, a_list: [1, 2, 3.14]}
test "create a node using SET properties and a simple map" do
r = Neo4j.query!(Neo4j.conn, "CREATE (report:Report) SET report = {props}", %{props: @simple_map})
assert r = %{stats: %{"labels-added" => 1, "nodes-created" => 1, "properties-set" => 2}, type: "w"}
end
test "create a node using SET properties and a nested map" do
r = Neo4j.query!(Neo4j.conn, "CREATE (report:Report) SET report = {props}", %{props: @nested_map})
assert r = %{stats: %{"labels-added" => 1, "nodes-created" => 1, "properties-set" => 2}, type: "w"}
end
end leaving this here as a bookmark, for later |
Hey, You're right @florinpatrascu that's a Neo4J error and not much we can do about it. Neo4J doesn't allow for nested maps. Neither via bolt nor via REST. It's a limitation to Neo4J. In our projects I've resorted to encoding and decoding nested maps to json. I quite like the error message actually. :) |
Thank you, Michael!!!
me too :) And you also saved me for some pain, as I was planning later on to check the REST support for the nested maps. Thanks again! @cheerfulstoic - is there something else we could help you with, for this issue? Thank you for your report though! |
for reference: https://stackoverflow.com/questions/25750016/nested-maps-and-collections-in-neo4j-2#25754628 One comment:
exactly as you said, @mschae |
I don't actually have a nested map, actually. It's just a plain map. I can't share the example I'm using, but I'll try to put together a version which still breaks |
understood, ty |
Oh, gosh. I figured it out and it's my Ruby habits again: Neo4j.query!(Neo4j.conn, "CREATE (:Report {props})", %{props: %{'foo' => "test" }}) It's because of the single quotes for the key in the map being a charlist. So I'm able to fix my issue. I don't know if there's a way to validate values going in so that users get a better error message than Thanks! |
no worries, we all went through this :) I'll close this one, and create a new issue for improving the error support. I have an idea about why the "socket is not connected". We're retrying the requests in case of errors, but there are some specific errors we shouldn't bother the server with, such as the one you encountered, encoding errors, and so on. I believe the "socket is not connected", is actually an artifact of trying a request with errors and for some reasons the connection is lost in "translation". I'll look into that this week-end. Thanks again! |
I'm trying to use parameters to create nodes and not having much luck. I started out with:
That gives me:
To simplify I tried this:
That successfully queries, but then the
test
property has the value"102,111,111"
in the database.This works, however:
So it seems like maybe there's just something wrong with params (?)
The text was updated successfully, but these errors were encountered: