def GetCount(self, where, dict): session = DbSession() #count = session.query(self.cls).from_statement(sql.text(sql))#.params(dict).scalar() count = session.query(func.count(self.cls.Id)).filter(sql.text(where)).params(dict).scalar() session.commit() session.close() return count
def Update(self,where,statu): session = DbSession() #session.query(self.cls).filter(self.cls.Id == dict['Id']).update(dict) rows = session.query(self.cls).filter(sql.text(where)).update({self.cls.Status:statu}, synchronize_session=False)#不对session同步直接delete or update session.commit() session.close() return rows
def Add(self, dict): obj = self.ToObj(dict) session = DbSession() session.add(obj) session.commit() id = obj.Id session.close() return id
def Add(str, curtime): token = Token() token.Access_token = str token.Time = curtime session = DbSession() session.add(token) session.commit() session.close() if (1): print('token insert ok')
def GetRows(self, where, dict, pos, row_num): session = DbSession() sql_str = "SELECT * FROM " + self.cls().__tablename__ if len(where.strip()) > 0: sql_str += " WHERE " + where sql_str += " LIMIT " + str(max(pos - 1,0)) + "," + str(max(0,row_num)) lst = copy.deepcopy(session.query(self.cls).from_statement(sql.text(sql_str)).params(dict).all()) session.commit() session.close() return lst
def valuetime(where): session = DbSession() obj = session.query(Habit.Hrange, Habit.Date).filter(sql.text(where)).first() session.close() if (obj): print(int(obj[0]), obj[1]) struct_time = now.strptime(obj[1]) res = (struct_time + datetime.timedelta(days=int(obj[0])) ).strftime("%Y-%m-%d %H:%M:%S") return res else: return 'null'
def update(str, curtime): session = DbSession() rows = 0 try: rows = session.query(Token).update( { Token.Access_token: str, Token.Time: curtime }, synchronize_session=False) session.commit() except: session.rollback() session.close() return rows
def find(): session = DbSession() obj = session.query(Token.Access_token).first() session.close() return obj
def delformid(where): session = DbSession() session.query(Form).filter( sql.text(where)).delete(synchronize_session=False) session.commit() session.close()
def getformid(where): session = DbSession() obj = session.query(Form.FormId).filter(sql.text(where)).first() session.close() return obj
def getuid(where): session = DbSession() obj = session.query(Habit.UserId).filter(sql.text(where)).all() session.close() return obj
def Delete(self, id): session = DbSession() session.query(self.cls).filter(self.cls.Id == id).delete() session.commit() session.close()
def Get(self, id): session = DbSession() obj = session.query(self.cls).filter(self.cls.Id == id).one() session.close() return obj