I'm trying to extract records from an Oriented DB using pyorient
and here is my query:
query = "SELECT value FROM (SELECT expand(Elements) FROM dataset) WHERE type = 'XXX'"
records = client.command(query)
and everything is working fine. When I try to print records, here is what I get:
record = records[0]
print type(record)
<class 'pyorient.otypes.OrientRecord'>
print record
{{'value': 'Name'},'version':0,'rid':'#-2:0'}
and since I just need to extract 'Name
' from record
, I tried:
print record[0]
and got
TypeError: 'OrientRecord' object does not support indexing
and here is the results of repr
:
print(repr(record))
<pyorient.otypes.OrientRecord object at 0x7fdcdb531ad0>
After looking at the source code I figured out how to access the various parts of the data from the string representation:
>>> x
<pyorient.otypes.OrientRecord object at 0x105789e48>
>>> print(x)
{{'value': 'Name'},'version':0,'rid':'#-2:0'}
>>> x.oRecordData
{'value': 'Name'}
>>> x.value #allow for access in the oRecordData as attributes?
'Name'
>>> x._version, x._rid #other values in string representation
(0, '#-2:0')
I'm fairly disappointed that the string representation didn't make this apparent. Anyway I think you want the x.oRecordData
one.