def db_find_min_code(item_key): db_session = DBFactory().get_db_session() query = db_session.query(DBItem.item_code) result = query.order_by(DBItem.item_code.asc()).filter(DBItem.item_key == item_key).limit(1).first() if result is not None: return result.item_code else: return item_key + '-001'
def func2(key, attribute): db_session = DBFactory().get_db_session() # query_sql = 'SELECT item_date from items where item_key = :item_key order by item_code desc' # db_session.execute(query_sql, {'item_key': item_key}) query = db_session.query(attribute).filter(DBKey.key_ == key) print(query) result = query.first() print(result[0])
def db_if_code_exist(item_code): db_session = DBFactory().get_db_session() query = db_session.query(func.count('*')) result = query.filter(DBItem.item_code == item_code).first() return result[0]
def db_if_key_exist(key): db_session = DBFactory().get_db_session() query = db_session.query(func.count('*')) result = query.filter(DBKey.key_ == key).first() return result[0]
def db_find_attribute(key, attribute): db_session = DBFactory().get_db_session() query = db_session.query(attribute).filter(DBKey.key_ == key) result = query.first() return result[0]
def db_find_key_total(item_key): db_session = DBFactory().get_db_session() query = db_session.query(func.count('*')) result = query.filter(DBItem.item_key == item_key).first() return result[0]
def db_find_attribute(item_code, attribute): db_session = DBFactory().get_db_session() query = db_session.query(attribute).filter(DBItem.item_code == item_code) logging.info(query) result = query.first() return result[0]
def db_find_max_date(item_key): db_session = DBFactory().get_db_session() query = db_session.query(DBItem.item_date) result = query.order_by(DBItem.item_code.desc()).filter(DBItem.item_key == item_key).limit(1).first() return result.item_date