Skip to content
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

Redis parameters #116

Closed
FallingSnow opened this issue Jul 23, 2021 · 9 comments · Fixed by #117
Closed

Redis parameters #116

FallingSnow opened this issue Jul 23, 2021 · 9 comments · Fixed by #117
Assignees
Labels
bug Something isn't working In progress

Comments

@FallingSnow
Copy link

Is there a way to pass parameters?
For example when I submit a query with a $variable is I get an error message about missing parameters.

Kind of like https://redisgraph.github.io/redisgraph.js/Graph.html#query

@danitseitlin danitseitlin self-assigned this Jul 23, 2021
@danitseitlin
Copy link
Owner

@FallingSnow Hi, I am looking on https://oss.redislabs.com/redisgraph/commands/#graphquery and It doesn't seem aligned with what you shared. I will try to check what should be the correct syntax and update the code accordingly.
Thanks for your issue.

@danitseitlin
Copy link
Owner

@FallingSnow Can you share your exact usage?

@FallingSnow
Copy link
Author

I'm trying to escape user input in queries I submit to the database. Some libraries provide this escape function. Considering redis returns Missing parameters I think it might be native to redis.

Query:

MATCH (p:user) WHERE p.email=$email RETURN count(p) as count

Response:

Error: RedisGraph class (GRAPH.QUERY): ReplyError: Missing parameters

@danitseitlin
Copy link
Owner

@FallingSnow Can you share your usage with the redis-modules-sdk?

@FallingSnow
Copy link
Author

That is.

export default class Database extends RedisGraph {
  constructor(...args) {
    super({ port: options.databasePort, host: options.databaseHost, ...args });
  }

  async query(query: string) {
    try {
     // Throws "Error: RedisGraph class (GRAPH.QUERY): ReplyError: Missing parameters"
      return await super.query(options.databaseName, query);
    } catch (error) {
      log.error("Failed to run database query: \"%s\"\n%s", query, error);
      throw new Error("Database error. See server logs.");
    }
  }

  static escape(str) {
    return str.replace(/'/g, "\\'");
  }
}

// Doesn't work
const matches = await database.query(`MATCH (p:user) WHERE p.email=$email RETURN count(p) as count`);

// Works
const matches = await database.query(`MATCH (p:user) WHERE p.email='email@email.com' RETURN count(p) as count`);

@FallingSnow
Copy link
Author

Are you unable to replicate the error with a query that has a $ (dollar sign) variable?

@danitseitlin danitseitlin linked a pull request Jul 28, 2021 that will close this issue
@danitseitlin
Copy link
Owner

@FallingSnow hi, yes i am able. Sorry for the delay i will be working on this and many issues this weekend and next week.

@danitseitlin danitseitlin added bug Something isn't working In progress labels Aug 17, 2021
@danitseitlin
Copy link
Owner

@FallingSnow Hi, should have a fix soon, just running some last tests.

@FallingSnow
Copy link
Author

Great! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working In progress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants