Search code examples
orientdborientdb2.2pyorient

how to retrieve the @rid value from a query select from User where name = 'Nicole' using pyorient


I have not figure it out yet, how to retrieve the @rid value from the record metadata using python 3.5 with pyorient client.command to run such SQL query.

Let's said that I have created a User class using the following query in the client.command(query) of pyorient. For simplicity only the queries calls will be shown here:

CREATE User EXTENDS V
CREATE PROPERTY User.name IF NOT EXISTS STRING (MANDATORY TRUE, NOTNULL TRUE)
CREATE INDEX User.name ON User (name) UNIQUE

Let's create a dictionary to hold the pointers of recent created vertex

rec = {}

Now we add some vertex:

rec['Cleo'] = CREATE VERTEX User CLUSTER User CONTENT {'name': 'Cleopatra'}
rec['Alex'] = CREATE VERTEX User CLUSTER User CONTENT {'name': 'Alex'}

Let's see the value of rec['Alex']:

rec['Alex']
[<pyorient.otypes.OrientRecord at 0x7fc39cd69c50>] 

Let's said that, we want to know the @rid for Alex, so we can later on use it to create Edges among other classes.

If I run a quety using orientdb studio I can see the @rid:

enter image description here

but, if I run the same query using client.command I get the a list with the two record pointers. So it is the same as having the result from rec['Alex']

so, if I do rec['Alex'][0].oRecordData to get the record data, I only get back:

{'name': 'Alex'}

(1) How can I store the rid in a variable when I create a new vertex?

(2) How can I retrieve the rid for a record when you know, let's said the property name ?


Solution

  • With the python driver you need to do : ret._rid to access the rid