def create(blob): session.add(blob) session.commit() blob_id = blob.id session.close() return blob_id
def get_all(): res_list = [] for user in session.query(module.User).all(): d = {} d.setdefault('id', user.id) d.setdefault('username', user.username) d.setdefault('password', user.password) res_list.append(d) session.close() return jsonify(res_list)
def get_user_by_name_psword(username=None, password=None): users = [] for user in session.query(User).filter(User.username == username).filter(User.password == password).all(): users.append(user) session.close() if len(users) == 1: return users[0] elif len(users) > 1: raise RunException('count user by username and password more than one') else: raise RunException('password is wrong')
def get_blobs_by_user_id(user_id=None, type_id=None): sql = session.query(Blob).outerjoin( Sort, Blob.id == Sort.blob_id).filter(Blob.user_id == user_id) if not type_id == None: sql = sql.filter(Sort.type_id == type_id) result = [] for blob in sql.group_by(Blob.id).all(): result.append(blob) session.close() return result
def update(user): session.query(User).filter(User.id == user.id).update({'username':user.username, 'password':user.password}) session.commit() session.close()
def update(user_id, person): session.query(Person).filter(Person.user_id == user_id).update(person) session.commit() session.close()
def insert_one_person(person): session.add(person) session.commit() session.close()
def create(sort): session.add(sort) session.commit() session.close()