def db_update_application(language_id,name,description): session = DBSession() query = session.query(Application).filter(Application.id == language_id) query.update({Application.name: name,Application.description: description}, synchronize_session=False) #找到id更新 response = query.first() session.commit() return response
def db_update_character(character_id,name,description): session = DBSession() query = session.query(Character).filter(Character.id == character_id) query.update({Character.name: name,Character.description:description}, synchronize_session=False) #找到id更新 response = query.first() session.commit() return response
def db_update_translation(language_id, application_id, character_id, cha_translation): session = DBSession() query = session.query(Translation).filter(Translation.language_id == language_id, \ Translation.application_id == application_id ,\ Translation.character_id == character_id) query.update({Translation.cha_translation: cha_translation}, synchronize_session=False) #找到id更新 response = query.first() session.commit() return response
def db_update_language(language_id, name, description): session = DBSession() query = session.query(Language).filter(Language.id == language_id) query.update({ Language.name: name, Language.description: description }, synchronize_session=False) #找到id更新 response = query.first() session.commit() return response
def db_get_application_page(page_size,page): session = DBSession() count = session.query(Application).count() query = session.query(Application).limit(page_size).offset((int(page)-1)* int(page_size)) session.commit() session.close() return query,count
def db_get_character_page(page_size,page): session = DBSession() count = session.query(Character).count() query = session.query(Character).limit(page_size).offset((int(page)-1) * int(page_size)) session.commit() session.close() return query,count
def db_delete_translation_character_id(character_id): session = DBSession() delete_data = session.query(Translation).filter(Translation.character_id == character_id). \ delete(synchronize_session=False) session.commit() session.close() return 1
def db_delete_application(language_id): session = DBSession() delete_data = session.query(Application).filter(Application.id == language_id). \ delete(synchronize_session=False) session.commit() session.close() return 1
def db_delete_language(language_id): session = DBSession() delete_data = session.query(Language).filter(Language.id == language_id). \ delete(synchronize_session=False) session.commit() session.close() return 1
def db_delete_character(character_id): session = DBSession() delete_data = session.query(Character).filter(Character.id == character_id). \ delete(synchronize_session=False) session.commit() session.close() return 1
def db_delete_translation(language_id, application_id, character_id): session = DBSession() delete_data = session.query(Translation).filter(Translation.language_id == language_id, \ Translation.application_id == application_id ,\ Translation.character_id == character_id). \ delete(synchronize_session=False) session.commit() session.close() return 1
def db_get_application_id(application_id): session = DBSession() language_list = session.query(Application).filter(Application.id == application_id).first() if language_list: respon_dict = tool.language2dict(language_list) else: respon_dict = {} session.commit() session.close() return respon_dict
def db_get_id_character(name): session = DBSession() post_flag = session.query(Character).filter(Character.name == name).first() if post_flag: respon_dict = tool.language2dict(post_flag) else: respon_dict = 0 session.commit() session.close() return respon_dict
def db_get_character_id(character_id): session = DBSession() character_list = session.query(Character).filter(Character.id == character_id).first() if character_list: respon_dict = tool.language2dict(character_list) else: respon_dict = {} session.commit() session.close() return respon_dict
def db_get_translation_group(page_size, page, app_id): session = DBSession() if app_id == 0: count = session.query(Translation.character_id,Translation.application_id).\ order_by(Translation.character_id,Translation.application_id).\ group_by(Translation.character_id,Translation.application_id).count() #query = session.query(Translation).order_by(Translation.application_id).limit(page_size).offset((int(page)-1) * int(page_size)) query = session.query(Translation.character_id,Translation.application_id).\ order_by(Translation.character_id,Translation.application_id).\ group_by(Translation.character_id,Translation.application_id).limit(page_size).offset((int(page)-1) * int(page_size)).all() else: count = session.query(Translation.character_id, Translation.application_id).filter(Translation.application_id == app_id).\ order_by(Translation.character_id, Translation.application_id). \ group_by(Translation.character_id, Translation.application_id).count() # query = session.query(Translation).order_by(Translation.application_id).limit(page_size).offset((int(page)-1) * int(page_size)) query = session.query(Translation.character_id, Translation.application_id). filter(Translation.application_id == app_id).\ order_by(Translation.character_id, Translation.application_id). \ group_by(Translation.character_id, Translation.application_id).limit(page_size).offset( (int(page) - 1) * int(page_size)).all() session.commit() session.close() return query, count
def db_get_id_language(accept_language): session = DBSession() language_list = session.query(Language).filter( Language.name == accept_language).first() if language_list: respon_dict = tool.language2dict(language_list) else: respon_dict = {} session.commit() session.close() return respon_dict
def db_get_translation_id(translation_id): session = DBSession() translation_list = session.query(Translation).filter( Translation.id == translation_id).first() if translation_list: respon_dict = tool.translation2dict(translation_list) else: respon_dict = [] session.commit() session.close() return respon_dict
def db_get_id_translation(language_id, application_id, character_id): session = DBSession() post_flag = session.query(Translation).filter(Translation.language_id == language_id, \ Translation.application_id == application_id ,\ Translation.character_id == character_id).first() if post_flag: respon_dict = tool.translation2dict(post_flag) else: respon_dict = 0 session.commit() session.close() return respon_dict
def db_insert_application(application_list): session = DBSession() response = [] for i in application_list: application = Application(name = i['name'], description = i['description'], identification = i['identification']) session.add(application) response.append(application) session.commit() return response
def db_get_character_list(): session = DBSession() character_list = session.query(Character).all() respon_dict = [] if character_list: for i in character_list: json_transform = tool.language2dict(i) respon_dict.append(json_transform) else: respon_dict = [] session.commit() session.close() return respon_dict
def db_get_language_list(): session = DBSession() language_list = session.query(Language).all() respon_dict = [] if language_list: for i in language_list: json_transform = tool.language2dict(i) respon_dict.append(json_transform) else: respon_dict = [] session.commit() session.close() return respon_dict
def db_get_translation_list(): session = DBSession() translation_list = session.query(Translation).all() respon_dict = [] if translation_list: for i in translation_list: json_transform = tool.translation2dict(i) respon_dict.append(json_transform) else: respon_dict = [] session.commit() session.close() return respon_dict
def db_get_language_translation(language_id, application_id): session = DBSession() translation_list = session.query(Translation).filter(\ Translation.language_id == language_id,Translation.application_id == application_id).all() respon_dict = {} if translation_list: for i in translation_list: respon_dict[i.character.name] = i.cha_translation else: respon_dict = {} session.commit() session.close() return respon_dict
def db_insert_character(character_list): session = DBSession() response = [] for i in character_list: character = Character(name = i['name'], description = i['description']) session.add(character) response.append(character) session.commit() return response
def db_get_translation_cha_id_app_id(character_id, application_id): session = DBSession() translation_list = session.query(Translation).filter(\ Translation.character_id == character_id,Translation.application_id == application_id).order_by(Translation.language_id).all() respon_dict = [] if translation_list: for i in translation_list: json_transform = tool.lan(i) respon_dict.append(json_transform) else: respon_dict = [] session.commit() session.close() return respon_dict
def db_insert_language(language_list): session = DBSession() response = [] for i in language_list: language = Language(name=i['name'], description=i['description'], identification=i['identification']) session.add(language) response.append(language) session.commit() return response
def db_insert_translation(translation_list): session = DBSession() response = [] for param in translation_list: language_id = param['language_id'] application_id = param['application_id'] character_id = param['character_id'] cha_translation = param['cha_translation'] translation = Translation(language_id=language_id, application_id=application_id, \ character_id=character_id, cha_translation=cha_translation) session.add(translation) response.append(translation) session.commit() return response