def insert_properties(properties: Set[str], session: scoped_session) -> Optional[Any]: """Insert all the properties as defined in the APIDocumentation into DB.""" prop_list = [BaseProperty(name=prop) for prop in properties if not session.query(exists().where(BaseProperty.name == prop)).scalar()] session.add_all(prop_list) session.commit() return None # if __name__ == "__main__": # Session = sessionmaker(bind=engine) # session = Session() # # doc = doc_gen("test", "test") # # Extract all classes with supportedProperty from both # classes = get_classes(doc.generate()) # # # Extract all properties from both # # import pdb; pdb.set_trace() # properties = get_all_properties(classes) # # Add all the classes # insert_classes(classes, session) # print("Classes inserted successfully") # # Add all the properties # insert_properties(properties, session) # print("Properties inserted successfully")
def insert_classes(classes: List[Dict[str, Any]], session: scoped_session) -> Optional[Any]: """Insert all the classes as defined in the APIDocumentation into DB. Raises: TypeError: If `session` is not an instance of `scoped_session` or `Session`. """ # print(session.query(exists().where(RDFClass.name == "Datastream")).scalar()) if not isinstance(session, scoped_session) and not isinstance( session, Session): raise TypeError( "session is not of type <sqlalchemy.orm.scoping.scoped_session>" "or <sqlalchemy.orm.session.Session>") class_list = [ RDFClass(name=class_["label"].strip('.')) for class_ in classes if "label" in class_ and not session.query(exists().where( RDFClass.name == class_["label"].strip('.'))).scalar() ] class_list.extend([ RDFClass(name=class_["title"].strip('.')) for class_ in classes if "title" in class_ and not session.query(exists().where( RDFClass.name == class_["title"].strip('.'))).scalar() ]) # print(class_list) session.add_all(class_list) session.commit() return None
def insert_properties(properties: Set[str], session: scoped_session) -> Optional[Any]: """Insert all the properties as defined in the APIDocumentation into DB.""" prop_list = [BaseProperty(name=prop) for prop in properties if not session.query(exists().where(BaseProperty.name == prop)).scalar()] session.add_all(prop_list) session.commit() return None
def initDBofContract(self, session: scoped_session, submitInteral, sleepSec=1): if session.query(dbmodules.Processing).first(): logger.warning("wrong") return for root, dirs, files in os.walk(self.rootpath): interval: int = 0 templist = [] templist_2 = [] for file in files: if file.endswith("txt"): templist.append( dbmodules.Processing( contractAddr=os.path.splitext(file)[0], isprocessed=False)) templist_2.append( dbmodules.SmartContract( contractAddr=os.path.splitext(file)[0], label='none')) interval = interval + 1 if interval % submitInteral == 0: # session.add_all(templist) session.add_all(templist_2) templist = [] # templist_2 = [] session.commit() # session.flush() time.sleep(sleepSec) # print("sumbit: %d times" % ((interval - 1) // submitInteral + 1)) if templist: session.add_all(templist) session.add_all(templist_2) session.commit() session.flush() print("sumbit: %d times" % ((interval - 1) // submitInteral + 1))