""" This example updates one module name and position """ import sys from ttdb.model import obtain_session, Crate if __name__ == "__main__": #get connection string if len(sys.argv) <= 1: exit("Provide connection string for database. For sqlite use 'sqlite:///' (Note 3 slashes)") session = obtain_session(sys.argv[1]) #Get crate with id==1 is is "T1-1-TOP" crate = session.query(Crate).get(1) #change name name = "T1-1-TOP" if crate.name == "T1-1-TOP+" else "T1-1-TOP+" crate.name = name #commit changes session.commit() print("crate name changed to {}".format(name)) #now select crate from database by name selected_crate = session.query(Crate).filter(Crate.name == name).first() print("selected by that name crate id={} name={}".format(selected_crate.id, selected_crate.name))