thingdom / node-neo4j

[RETIRED] Neo4j graph database driver (REST API client) for Node.js
Apache License 2.0
925 stars 135 forks source link

Parameters: invalid syntax #196

Closed ekkis closed 8 years ago

ekkis commented 8 years ago

I'm getting an error on a simple statement and it appears the query's not using the parameters:

function x(type) {
  var q = {
    query: 'match (n:{t}) return n',
    params: {t: type}
  };
  db.cypher(q, ...);
}
x('Config');

here's the error:

$ node ../tst

{ [neo4j.ClientError: [Neo.ClientError.Statement.InvalidSyntax] Invalid input '{': expected whitespace or a label name (line 1, column 10 (offset: 9)) "match (n:{t}) return n" ^] message: '[Neo.ClientError.Statement.InvalidSyntax] Invalid input \'{\': expected whitespace or a label name (line 1, column 10 (offset: 9))\n"match (n:{t}) return n"\n ^', neo4j: { code: 'Neo.ClientError.Statement.InvalidSyntax', message: 'Invalid input \'{\': expected whitespace or a label name (line 1, column 10 (offset: 9))\n"match (n:{t}) return n"\n ^' }, name: 'neo4j.ClientError' }

am I doing something really dumb here?

aseemk commented 8 years ago

Not dumb, just not right. =) Labels can't be parameterized, as they determine the query plan.

Hope that helps! If you still have questions here, I'd recommend asking on the Neo4j Slack #help-cypher channel:

https://neo4j-users.slack.com/messages/help-cypher

Sign up here:

http://neo4j-users-slack-invite.herokuapp.com/

ekkis commented 8 years ago

ah. makes sense but it would be helpful if the documentation stated so

aseemk commented 8 years ago

It's in the Neo4j manual / Cypher docs:

http://neo4j.com/docs/stable/cypher-parameters.html

Parameters can not be used as for property names, relationship types and labels, since these patterns are part of the query structure that is compiled into a query plan.

Would it be helpful if the node-neo4j docs linked to this?

ekkis commented 8 years ago

oh I see. it's an issue with neo4j, not with the npm module. the documentation I was referring to is actually on the npm site (https://www.npmjs.com/package/neo4j) and it differs from that shows in the github project. when I saw MATCH (u:User {email: {email}}) RETURN u I had no reason to think I couldn't replace User with a parameter too. so perhaps a small note there would make sense. thanks.

aseemk commented 8 years ago

Indeed! Okay, thanks for the feedback. =) Cheers.