def upsert_login(login_id, language_id): ''' Add or update a login entity. ''' session = get_session() login = session.query(model.Login).filter(model.Login.id == login_id).one_or_none() if login is not None: login.language_id = language_id else: login = model.Login(id=login_id, language_id=language_id) session.add(login) session.commit() return login
def upsert_login(login_id, language_id): ''' Add or update a login entity. Returns new or updated login. ''' with session_scope() as session: login = session.query( model.Login).filter(model.Login.id == login_id).one_or_none() if login is not None: login.language_id = language_id else: login = model.Login(id=login_id, language_id=language_id) session.add(login) session.commit() session.refresh(login) return login