emehrkay / Pypher

Python Cypher Querybuilder
MIT License
170 stars 29 forks source link

Question: Apoc Functions #8

Closed g3rd closed 6 years ago

g3rd commented 6 years ago

How would you write:

MATCH (u:User {username: 'chad'}) 
WITH apoc.text.join([u.first_name, u.last_name], ' ') AS full_name
RETURN full_name

Thanks!

emehrkay commented 6 years ago

There are a few ways to do it, this is the first that came to mind:

p.WITH.func_raw('apoc.text.join', __.List(__.u.__first_name__, __.u.__last_name__), "''").alias('full_name')                                    
p.RETURN.full_name 

Or you could define the function, this is probably the best case

create_function('apoc_text_join', {'name': 'apoc.text.join'}, func_raw=True) # new release to allow for func_raw argument here

p = Pypher()
p.WITH.apoc_text_join(__.List(__.u.__first_name__, __.u.__last_name__), "''").alias('full_name')                                    

note: you must double quote the quotes that you want to appear in your resulting Cypher

screen shot 2018-05-05 at 8 34 49 am

g3rd commented 6 years ago

@emehrkay this is amazing! Thanks!