python 3.x - sqlalchemy reflecting table and inserting a row -
im building wrapper db_connector using sqlalchemy...
since im trying stay generic presume wont know tables il have , cant use orm line of development.... trying use reflection system, reflect table database , trying create new object table in order insert new info got user.
at moment func gets table_name table insert new row , row_arguments, list arguments new row...
im struggling creating new object of table, more precise object of row table, think if id manage doing swell , using session manage add new row. question how can create kind of object things pass? got engine,session,metadata in class defined....
def insertrow(self,table_name,row_arguments): self.table = self.gettablesindb(table_name) self.session = self.session() class test(object): pass mapper(test,self.table) string ="" in row_arguments: string += insert = test() self.session.add(insert) self.session.commit()
in middle of code have lots of things tried, nothing seem succeedd.... im kinda hopeless , out of ideas, please help
idea not know kind of tables im facing before retrieving them way
what if try :
def insertrow(self,table_name,row_arguments): table = self.gettablesindb(table_name) self.session = self.session() # considering row_arguents dict {"colname1":value, "colname2":value} insert = table(**row_arguments) self.session.add(insert) self.session.commit()
Comments
Post a Comment