def add(policyId, userId, active, inobj, session=None): if not session: session = db.Session inobj['active'] = active inobj.pop('last_updated', None) inobj.pop('created_at', None) our_result = session.query(PolicyBundle).filter_by( policyId=policyId).filter_by(userId=userId).first() if not our_result: new_service = PolicyBundle(policyId=policyId, userId=userId) new_service.update(inobj) session.add(new_service) else: our_result.update(inobj) # try: # session.commit() # except Exception as err: # raise err # finally: # session.rollback() return (True)
def add(policyId, userId, active, inobj, session=None): if not session: session = db.Session inobj["active"] = active inobj.pop("last_updated", None) inobj.pop("created_at", None) our_result = ( session.query(PolicyBundle) .filter_by(policyId=policyId) .filter_by(userId=userId) .first() ) if not our_result: new_service = PolicyBundle(policyId=policyId, userId=userId) new_service.update(inobj) session.add(new_service) else: # Force an update here to cover updates even if content doesn't change. # This is probably worth revisiting later, to use a content digest to ensure changes actually inobj["last_updated"] = anchore_now() our_result.update(inobj) return True
def add(policyId, userId, active, inobj, session=None): if not session: session = db.Session inobj['active'] = active inobj.pop('last_updated', None) #inobj['last_updated'] = int(time.time()) inobj.pop('created_at', None) our_result = session.query(PolicyBundle).filter_by(policyId=policyId).filter_by(userId=userId).first() if not our_result: new_service = PolicyBundle(policyId=policyId, userId=userId) new_service.update(inobj) session.add(new_service) else: our_result.update(inobj) return(True)