def _init_db_data(self, db_name: str, xml_files: Optional[List[str]] = None, client: pyorient.OrientDB = None) -> pyorient.OrientDB: if xml_files is not None: for filepath in xml_files: json.dump(self.config, open(SWRI_CONFIG_FILE, 'w'), indent=4) importer = OrientDBXMLImporter(databaseName=db_name, configFile=SWRI_CONFIG_FILE, mdlFile=filepath) importer.import_xml() importer.orientDB_helper.close_database() if client is None: client = pyorient.OrientDB(self.host, self.port) client.connect('root', self.root_password) if client.db_exists(db_name): client.db_open(db_name, 'admin', 'admin') else: client.db_create(db_name, pyorient.DB_TYPE_GRAPH, pyorient.STORAGE_TYPE_MEMORY) client.db_open(db_name, 'admin', 'admin') client.command('CREATE CLASS BBNEvaluationData EXTENDS V') client.command( 'CREATE PROPERTY BBNEvaluationData.inputJsonData STRING') client.command( 'CREATE PROPERTY BBNEvaluationData.outputJsonData STRING') client.command('CREATE PROPERTY BBNEvaluationData.currentState STRING') client.command( 'CREATE PROPERTY BBNEvaluationData.currentStateInfo STRING') return client
def create_db(db_name, server, port, user, password): """ Create a new database and populate it with the base types """ client = OrientDB(server, port) client.connect(user, password) client.db_create(db_name, DB_TYPE_GRAPH, STORAGE_TYPE_MEMORY) for key, value in types.items(): client.command("create class %s extends V" % value) for edge_type in edge_types: client.command("create class %s extends E" % edge_type) client.db_close(db_name)
def load_schema(client: OrientDB) -> None: """Read the schema file and apply the specified SQL updates to the client.""" project_root = path.dirname(path.dirname(path.abspath(__file__))) file_path = path.join(project_root, "test_data_tools/schema.sql") sql_files = glob(file_path) if len(sql_files) > 1: raise AssertionError( u"Multiple schema files found. Expected single `schema.sql` " u"in graphql-compiler/graphql_compiler/tests/test_data_tools/" ) if len(sql_files) == 0 or sql_files[0] != file_path: raise AssertionError( u"Schema file not found. Expected graphql-compiler/graphql_compiler/" u"tests/test_data_tools/schema.sql" ) with open(file_path, "r") as update_file: for line in update_file: sanitized = line.strip() if len(sanitized) == 0 or sanitized[0] == "#": # comment or empty line, ignore continue client.command(sanitized)
def add_connections(newConnections): client_ = OrientDB(configuration.get_prop('srv_addr'), configuration.get_prop('srv_port')) client_.connect(configuration.get_prop('user'), configuration.get_prop('pass')) client_.db_open(configuration.get_prop('db_name'), configuration.get_prop('user'), configuration.get_prop('pass')) for links in newConnections: v1 = client_.query('SELECT FROM Site WHERE url = "%s"' % (links[0]), 1) if (len(v1) == 0): client_.command('CREATE VERTEX Site SET url = "%s"' % (links[0])) v2 = client_.query('SELECT FROM Site WHERE url = "%s"' % (links[1]), 1) if (len(v2) == 0): client_.command('CREATE VERTEX Site SET url = "%s"' % (links[1])) count = newConnections[links] edge_query = client_.query( 'SELECT FROM links_to WHERE out in (SELECT @rid FROM Site WHERE url = "%s") ' 'and in in (SELECT @rid FROM Site WHERE url = "%s")' % (links[0], links[1])) if (len(edge_query) == 0): client_.command( 'CREATE EDGE links_to FROM (SELECT FROM Site WHERE url = "%s") ' 'TO (SELECT FROM Site WHERE url = "%s") SET count = %d' % (links[0], links[1], count)) else: edge = edge_query[0].oRecordData new_count = edge['count'] + count client_.command('UPDATE %s SET count = %d' % (edge_query[0]._rid, new_count))
def init_db_data(host: str, port: int, root_password: str, db_name: str, xml_files: Optional[List[str]] = None, client: OrientDB = None) -> pyorient.OrientDB: if xml_files is not None: for filepath in xml_files: load_xml_into_db(host, port, root_password, filepath, db_name) if client is None: client = pyorient.OrientDB(host, port) client.connect('root', root_password) if client.db_exists(db_name): client.db_open(db_name, 'admin', 'admin') else: client.db_create(db_name, pyorient.DB_TYPE_GRAPH, pyorient.STORAGE_TYPE_MEMORY) client.db_open(db_name, 'admin', 'admin') client.command('CREATE CLASS BBNEvaluationInput EXTENDS V') client.command('CREATE PROPERTY BBNEvaluationInput.jsonData STRING') client.command('CREATE CLASS BBNEvaluationOutput EXTENDS V') client.command('CREATE PROPERTY BBNEvaluationOutput.jsonData STRING') client.command('CREATE PROPERTY BBNEvaluationOutput.finalState STRING') client.command('CREATE PROPERTY BBNEvaluationOutput.finalStateInfo STRING') # client.coommand('CREATE CLASS DAUInventory EXTENDS V') return client
from pyorient import OrientDB import pyorient from socket_config import Socket import db_atributes socket = Socket("orientDB", 2424) try: print("here") socket.connect() client = OrientDB(socket) session_id = client.connect("root", "password") #get session id client.db_open("test", "root", "password") #open db for item in db_atributes.orient_classes( ): #create a classes and atributes of new class if not exists based on db atributes file client.command("CREATE CLASS " + item['name'] + " IF NOT EXISTS EXTENDS " + item['classType']) for prop in item['atributes']: client.command("CREATE PROPERTY " + item['name'] + "." + prop['name'] + " IF NOT EXISTS " + prop['types']) except Exception as e: print(e) socket.connect() client = OrientDB(socket) session_id = client.connect("root", "password") #get session id if not client.db_exists( "test" ): #if exeption is for non created db lets create the db and classes with atributes based on db_atributes file client.db_create("test", pyorient.DB_TYPE_GRAPH, pyorient.STORAGE_TYPE_PLOCAL) client.db_open("test", "root", "password") for item in db_atributes.orient_classes(): client.command("CREATE CLASS " + item['name'] +