question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamic Variable Names

See original GitHub issue

Thank you for this package. I wanted to know if the nodes can be specified by strings

For example, I want to write a query

MATCH (n) WHERE n.root = "Something"

Now, I can do this using p.Match.node('n').Where.n.property('root') == "Something" However, I have to do this for many variables for a longer pattern in MATCH, and the name n is generated dynamically, for example it could be n1, n2, n3 etc depending on which iteration of loop it is in. Is it possible to achieve that?

I tried giving Where.raw('n') and Where._('n') but both insert a STATEMENT word in the query.

(Apologies if this is a stupid question)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
emehrkaycommented, May 17, 2021

I was able to get STATEMENT to print out, I think that is an error with the Anon object. I will check into it.

I did manage to get something going based on what you want using the ConditionalAND (https://github.com/emehrkay/Pypher#conditionals) object

EDGES = [(1, 'REL1', 2), (1, 'REL2', 3), (2, 'REL3', 3)]
 
node_prefix = 'n'
relation_prefix = 'r'
edges = []
_rid = 0
 
for _src_id, relation, _dst_id in EDGES:
    _rid += 1
    src_var = f'{node_prefix}{_src_id}'
    dst_var = f'{node_prefix}{_dst_id}'
    rel_var = f'{relation_prefix}{_rid}'
    edge = __.node(src_var).rel_out(rel_var, relation).node(dst_var)
    edges.append(edge)
 
 
conditions = []
 
NAMES = {'first': 'mark', 'you': 'hrshikeshrt'}
_root = 'some root value'
 
 
for _var, _name in NAMES.items():
    conditions.append(__().raw(_var).property('name') == _root)
 
p.Match(*edges)
p.WHERE(__.ConditionalAND(*conditions))
p.Return('*')

Screen Shot 2021-05-17 at 12 29 23 PM

In this example I did __.() which would end up creating a new Pypher object (https://github.com/emehrkay/Pypher/blob/master/pypher/builder.py#L1264) – this is the root of the STATEMENT bug.

0reactions
emehrkaycommented, May 17, 2021

py2neo is great. Here is the base query method that accepts params https://py2neo.org/2021.1/workflow.html#py2neo.Graph.run

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use dynamic variable names in JavaScript - Stack Overflow
var id = "abc"; var mine = {}; mine[id] = 123; console.log(mine.abc);. gives 123. Usually you want to construct the variable which is...
Read more >
Dynamic variable names - Rosetta Code
In Déjà Vu, variable names are idents, which are completely separate from strings, and cannot easily be created from them. · In E,...
Read more >
How to Use Dynamic Variable Names in JavaScript? - Linux Hint
The dynamic variable names mean that the names of variables are modified randomly or are user-defined. The eval() method is specifically utilized to ......
Read more >
How to make dynamic variable names (A1, A2 ... - MathWorks
I did find dynamically named variables useful for a specific need. I have several files in a directory. Each file has a few...
Read more >
Create and use dynamic variable names in JavaScript
Dynamic variables are those types of variables that don't have any specific name in the code through hard coded. A dynamic variable name...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found