I am executing the following query in Python to return the list of all nodes stored in the Apache AGE.
with postgresql.cursor() as cursor:
query = """SELECT * FROM cypher('graph', $$ MATCH (v) RETURN v $$) as (v agtype);"""
cursor.execute(query)
for row in cursor:
print(row[0])
But row[0]
here is of the type str
instead of <class 'age.models.Node'>
. I need to access the id, label, and other properties of the node, which I could have easily done with <class 'age.models.Node'>
by simply using row[0].id
or row[0].label
. I cannot do this with the str type.
I am currently trying to write unit test cases with pytest
and factories
from pytest_postgresql
. It works properly when I run the same thing using psycopg2
, and the expected data type is returned but fails with pytest_postgresql
.
This is the code to set up the database.
postgresql_my_proc = factories.postgresql_proc()
postgresql_my = factories.postgresql('postgresql_my_proc')
Is it the issue with pytest_postgresql
? Is it possible to fix this, and is there some workaround to achieve the same?
2
Answers
You should use the Apache AGE Python Driver. This way, retrieving node IDs and labels would be very easy, as shown in the following sample:
More samples can be seen here.
I have just seen an example from the apache age GitHub documentation and they are using another way to retrieve these things.
Single result column
Multi result columns
you can get more information from this file.
Github File