You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@age.apache.org by GitBox <gi...@apache.org> on 2022/04/26 07:00:02 UTC

[GitHub] [incubator-age] lnoir commented on issue #210: Dynamic queries

lnoir commented on issue #210:
URL: https://github.com/apache/incubator-age/issues/210#issuecomment-1109420302

   Hi @JoshInnis, thanks for your quick response and help. I figured out the problem and realised the correct approach. :+1: 
   
   It wasn't clear to me how I should construct and execute the queries. Reading the documentation, named parameters (`$param_name` syntax) _seemed_ to be restricted to prepared statements. Coupled with reading elsewhere that AGE doesn't support `$n` syntax in the cypher query itself, I was a little confused.
   
   I'm using NodeJS with the [pg](https://github.com/brianc/node-postgres) library. I'll leave a working example here for anyone else who might find it useful. This works:
   
   ```
   ...
   
   const id = 'e4510317-67dc-4002-b28d-347699c8f8ca';
   const query = ` 
       SELECT * FROM ag_catalog.cypher('minmail', $$
       MATCH (u:User {_id: $userId})
       RETURN u
   `;
   const params = {userId: id};
   const json = JSON.stringify(params);
   const values = [json];
   pool.query(query, values).then(...).catch(...);
   
   ...
   ```
   
   Of course, I aim to use prepared statements too, but just didn't want to have dozens of prepared statements that were essentially just slight variations on the same thing.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@age.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org