Skip to content

Commit fd7c36c

Browse files
committed
quote strings
1 parent 83e67c6 commit fd7c36c

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ redis_graph.add_edge(edge)
2323

2424
redis_graph.commit()
2525

26-
query = """MATCH (p:person)-[v:visited {purpose:pleasure}]->(c:country)
27-
RETURN p.name, p.age, v.purpose, c.name"""
26+
query = """MATCH (p:person)-[v:visited {purpose:"pleasure"}]->(c:country)
27+
RETURN p.name, p.age, v.purpose, c.name"""
2828

2929
redis_graph.query(query)
3030
```

redisgraph/client.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@ def random_string(length=10):
1010
"""
1111
return ''.join(random.choice(string.ascii_lowercase) for x in range(length))
1212

13+
def quote_string(prop):
14+
"""
15+
RedisGraph strings must be quoted,
16+
quote_string wraps given prop with quotes incase
17+
prop is a string.
18+
"""
19+
if not isinstance(prop, str):
20+
return prop
21+
22+
if prop[0] != '"':
23+
prop = '"' + prop
24+
25+
if prop[-1] != '"':
26+
prop = prop + '"'
27+
28+
return prop
1329

1430
class Node(object):
1531
"""
@@ -28,7 +44,7 @@ def __str__(self):
2844
return '({alias}:{label} {{{properties}}})'.format(
2945
alias=self.alias,
3046
label=self.label,
31-
properties=','.join(key+':'+str(val) for key, val in self.properties.items()))
47+
properties=','.join(key+':'+str(quote_string(val)) for key, val in self.properties.items()))
3248

3349

3450
class Edge(object):
@@ -51,7 +67,7 @@ def __str__(self):
5167
return '({src_alias})-[:{relation} {{{properties}}}]->({dest_alias})'.format(
5268
src_alias=self.src_node.alias,
5369
relation=self.relation,
54-
properties=','.join(key+':'+str(val) for key, val in self.properties.items()),
70+
properties=','.join(key+':'+str(quote_string(val)) for key, val in self.properties.items()),
5571
dest_alias=self.dest_node.alias)
5672
else:
5773
return '({src_alias})-[:{relation}]->({dest_alias})'.format(

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import setup, find_packages
22
setup(
33
name='redisgraph',
4-
version='0.6',
4+
version='0.8',
55

66
description='RedisGraph Python Client',
77
url='https://github.com/swilly22/redisgraph-py',

0 commit comments

Comments
 (0)