Search code examples
pythonpython-2.7orientdbpyorient

Check class creation in OrientDB


I'm trying to create classes with pyorient driver but sometime if class exists I got class exists message. Is there a way to check whether class is exists or not in OrientDB python driver? Here is part of my sample code for class creation...

@classmethod
def create(cls):

    cls._cluster_id = OrientEngine.client.command("CREATE CLASS %s EXTENDS V" % cls.__name__)
    return cls._cluster_id

Solution

  • Via SQL to check the existence of "OUser" class execute this:

    SELECT FROM ( SELECT expand( classes ) FROM metadata:schema ) WHERE name = 'OUser'
    

    Via Java API:

    OClass cls = db.getMetadata().getSchema().getClass("OUser");