Ejemplo n.º 1
0
 def updateOutip(Name_DICT={}):
     '''
     :param Name_DICT:
     :return: {1:'success', 2:'name is empty', 3:'failed'}
     '''
     try:
         if (Name_DICT is None):
             return 3
         for name in Name_DICT.keys():
             ret = 1
             ret = Outip.check(name)
             if (ret == 1):
                 Outip.add(name, Name_DICT[name])
                 continue
             elif (ret == 2):
                 curCount = session.query(
                     Outip.count).filter(Outip.name == name).first()
                 if (curCount is None):
                     continue
                 else:
                     count = int(curCount[0]) + Name_DICT[name]
                     session.query(Outip).filter(Outip.name == name).update(
                         {
                             'count': count,
                             'ltime': datetime.now()
                         })
                     session.commit()
             else:
                 continue
     except BaseException:
         session.rollback()
     finally:
         session.close()
     return 1
Ejemplo n.º 2
0
 def updateHost(Name_DICT = {}):
     '''
     :param Name_DICT:
     :return: {1:'success', 2:'name is empty', 3:'failed'}
     '''
     try:
         if(Name_DICT == None):
             return 3
         for name in Name_DICT.keys():
             #print("add name: %s" %name)
             ret = 1
             ret = Host.check(name)
             if(ret == 1):
                 Host.add(name,Name_DICT[name])
                 continue
             elif(ret == 2):
                 curCount = session.query(Host.count).filter(Host.name == name).first()
                 if(curCount == None):
                     continue
                 else:
                     count = int(curCount[0]) + Name_DICT[name]
                     session.query(Host).filter(Host.name == name).update({'count':count, 'ltime':datetime.now()})
                     session.commit()
             else:
                 continue
     except:
         session.rollback()
     finally:
         session.close()
     return 1;
Ejemplo n.º 3
0
 def delete_data(self,id):
     try:
         """删除数据,默认开始事务"""
         rows = session.query(ProductModel).filter(ProductModel.id == id).first()
         session.delete(rows)
         session.commit()
         return True
     except:
         session.rollback()
Ejemplo n.º 4
0
 def update_data(self,datas,id):
     try:
         datas.pop("id")
         print(datas)
         session.query(ProductModel).filter(ProductModel.id == id).update(datas)
         session.commit()
         return True
     except:
         session.rollback()
Ejemplo n.º 5
0
def add_user_one(data):

    model_obj = User(**data)
    try:
        session.add(model_obj) 
        session.commit()
        return inspect(model_obj).identity[0]
    except Exception as e:
        session.rollback()
        raise e
Ejemplo n.º 6
0
def add_user_many(data_li):
    """
    [User(username='******', password='******'),]
    """
    try:
        session.add_all(data_li)
        session.commit()
    except Exception as e:
        session.rollback()
        raise e
Ejemplo n.º 7
0
def delete_user(*args,**kwargs):
    """"
    query>User.username=='cainiao'
    """
    try:
        rows = session.query(User).filter(*args).filter_by(**kwargs)[0]
        session.delete(rows)
        session.commit()
    except Exception as e:
        session.rollback()
        raise e
Ejemplo n.º 8
0
def update_user(data,*args,**kwargs):
    """
    query> User.username=='cainiao'
    data> {User.password:1}
    """
    try:
        rows = session.query(User).filter(*args).filter_by(**kwargs).update(data)
        session.commit()
    except Exception as e:
        session.rollback()
        raise e
Ejemplo n.º 9
0
    def insert_data(self,datas):

        try:
            if "product_name" in datas:
                product_name = datas["product_name"]
            else:
                product_name = None
            if "version" in datas:
                version = datas["version"]
            else:
                version = None
            if "infos" in datas:
                infos = datas["infos"]
            else:
                infos = None
            if "pro_sys" in datas:
                pro_sys = datas["pro_sys"]
            else:
                pro_sys = None
            if "channel" in datas:
                channel = datas["channel"]
            else:
                channel = None
            if "opernation" in datas:
                opernation = datas["opernation"]
            else:
                opernation = None
            dao = ProductModel(product_name=product_name,version=version,infos=infos,pro_sys=pro_sys,channel=channel,opernation=opernation)
            # session.add(add_data)  # 添加一条
            # session.add_all(add_datas)  # 添加多条
            session.add(dao)
            session.commit()
            print('新增成功')
            return True
        except:
            session.rollback()
            print('新增失败')
Ejemplo n.º 10
0
 def updateHost(Name_DICT={}):
     '''
     :param Name_DICT:
     :return: {1:'success', 2:'name is empty', 3:'failed'}
     '''
     try:
         if (Name_DICT == None):
             return 3
         for name in Name_DICT.keys():
             #print("add name: %s" %name)
             ret = 1
             ret = Host.check(name)
             if (ret == 1):
                 Host.add(name, Name_DICT[name])
                 continue
             elif (ret == 2):
                 curCount = session.query(
                     Host.count).filter(Host.name == name).first()
                 if (curCount == None):
                     continue
                 else:
                     count = int(curCount[0]) + Name_DICT[name]
                     session.query(Host).filter(Host.name == name).update({
                         'count':
                         count,
                         'ltime':
                         datetime.now()
                     })
                     session.commit()
             else:
                 continue
     except:
         session.rollback()
     finally:
         session.close()
     return 1