diff options
| author | LV-426 <lv-426@taproot.org.il> | 2014-10-06 18:16:12 +0300 |
|---|---|---|
| committer | LV-426 <lv-426@taproot.org.il> | 2014-10-06 18:16:12 +0300 |
| commit | eef0c89ed89293ca89ba8b5f42b7100c46682fd7 (patch) | |
| tree | 305bf2570eb5936f206117c776e651e248ab0fdc | |
| parent | b7ac56cbe38fbccbb782b42c07bb5b389e65a433 (diff) | |
filter_attr_map to cypher where clause conversion: where_clause_from_filter_attr_map()
| -rw-r--r-- | src-py/neo4j_util.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src-py/neo4j_util.py b/src-py/neo4j_util.py index 4c166bfe..929324fb 100644 --- a/src-py/neo4j_util.py +++ b/src-py/neo4j_util.py @@ -48,3 +48,19 @@ def statement_set_to_REST_form(statement_set): assert isinstance(statement_set, list) return {'statements': statement_set} + +def where_clause_from_filter_attr_map(filter_attr_map, node_param_name="n"): + """ + convert a filter attribute map to a parameterized Cypher where clause, eg. + in: { 'att_foo': [ 'a', 'b' ], 'att_goo': [1,2] } + out: where n.att_foo in {att_foo} and n.att_goo in {att_goo} ... + """ + filter_arr = [] + for k in filter_attr_map.keys(): + # create a cypher query parameter place holder for each attr set + # eg. n.foo in {foo}, where foo is passed as a query parameter + f_attr = "{0}.{1} in {{{1}}}".format(node_param_name, k) + filter_arr.append(f_attr) + filter_str = "where {0}".format(' and '.join(filter_arr)) + return filter_str + |
