本文整理汇总了Python中db.dbSession.DBSession.query方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.query方法的具体用法?Python DBSession.query怎么用?Python DBSession.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.dbSession.DBSession
的用法示例。
在下文中一共展示了DBSession.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: updateVoteByAnswerId
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import query [as 别名]
def updateVoteByAnswerId(cls, answer_id, type, against_count, agree_count):
session = DBSession()
# 0反对票, 1赞同票
# if type == '-1' :
# print 'update against_count'
# session.query(cls).filter(cls.answer_id == answer_id).update({cls.against_count:count})
# elif type == '1' :
# print 'update agree_count'
# session.query(cls).filter(cls.answer_id == answer_id).update({cls.agree_count:count})
session.query(cls).filter(cls.answer_id == answer_id).update({cls.against_count:against_count, cls.agree_count:agree_count})
session.commit()
session.close()
示例2: queryByAnswerId
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import query [as 别名]
def queryByAnswerId(cls, answerId, voteValue):
session = DBSession()
name = session.query(AutoUser.name).filter(AutoUser.id == AnswerVote.vote_uid, AnswerVote.answer_id == answerId, AnswerVote.vote_value == voteValue).distinct().all()
namelist = []
for str in name :
namelist.append(str[0])
return namelist
示例3: queryByUserId
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import query [as 别名]
def queryByUserId(cls, userid):
session = DBSession()
u = session.query(cls).filter(cls.id==userid).first()
if not u:
return None
else:
return u
示例4: queryByUsername
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import query [as 别名]
def queryByUsername(cls, username):
""" 按用户名查询用户 """
session = DBSession()
u = session.query(cls).filter(cls.user_name==username).first()
if not u:
return None
else:
return u
示例5: queryByUserIdAndLinkId
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import query [as 别名]
def queryByUserIdAndLinkId(cls, userId, linkid):
session = DBSession()
userVote = session.query(cls).filter(cls.user_id == userId, cls.link_id == linkid).first()
session.close()
if not userVote:
return False
else:
print userVote
return userVote
示例6: checkEmail
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import query [as 别名]
def checkEmail(cls, email):
'''
检查邮箱是否已经被注册
'''
session = DBSession()
u = session.query(cls).filter(cls.email==email).first()
if not u:
return False
else:
return u
print 'hi'
示例7: checkUsername
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import query [as 别名]
def checkUsername(cls, username):
'''
检查用户名是否已经被注册
'''
session = DBSession()
u = session.query(cls).filter(cls.name==username).first()
if not u:
return False
else:
return u
print 'hi'
示例8: queryUser
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import query [as 别名]
def queryUser(cls, username, password):
# 创建session对象:
session = DBSession()
u = session.query(cls).filter(cls.name==username).first()
if not u:
return False
hashed_password = bcrypt.hashpw(password, tornado.escape.utf8(u.hashed_password))
if u.hashed_password == hashed_password:
return u
else:
print 'wrong password'
return False
示例9: unfollow
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import query [as 别名]
def unfollow(cls, fansUid, friendUid):
''' 取消关注 '''
# 创建session对象:
session = DBSession()
ret = session.query(cls).filter(cls.friend_uid==friendUid, cls.fans_uid==fansUid).delete()
session.commit()
session.close()
# 更新uid为fansUid的关注人数和粉丝数
following = cls.countFollowing(fansUid)
follower = cls.countFollower(fansUid)
Users.updateFollowCount(fansUid, follower, following)
# 更新uid为friendUid的关注人数和粉丝数
following = cls.countFollowing(friendUid)
follower = cls.countFollower(friendUid)
Users.updateFollowCount(friendUid, follower, following)
return True
示例10: queryById
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import query [as 别名]
def queryById(cls, questionId):
session = DBSession()
question = session.query(cls).filter(cls.question_id == questionId).first()
return question
示例11: queryAllQuestions
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import query [as 别名]
def queryAllQuestions(cls):
session = DBSession()
questions = session.query(cls)
return questions
示例12: addQuestion
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import query [as 别名]
def addQuestion(cls, question_content, question_detail, published_uid):
obj = cls(question_content = question_content, question_detail = question_detail,
published_uid = published_uid, add_time = long(time.time()), update_time = long(time.time()))
session = DBSession()
session.add(obj)
session.commit()
session.close()
return True
if __name__ == "__main__":
# 创建session对象:
session = DBSession()
# 创建新User对象:
#new_user = AutoUser(id='6', name='Bob', hashed_password='ok', email = '[email protected]')
# 添加到session:
#session.add(new_user)
query = session.query(Question)
for question in query:
print question.question_content
print question.question_detail
print question.comment_count
# 提交即保存到数据库:
session.commit()
# 关闭session:
session.close()
示例13: queryPageCount
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import query [as 别名]
def queryPageCount(cls):
session = DBSession()
count = session.query(cls)
示例14: queryAll
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import query [as 别名]
def queryAll(cls):
session = DBSession()
linkList = session.query(cls)
return linkList
示例15: followerList
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import query [as 别名]
def followerList(cls, uid):
''' 获取用户粉丝名单,uid, url_token, '''
# 创建session对象:
session = DBSession()
ret = session.query(Users.uid, Users.user_name, Users.url_token).filter(cls.friend_uid == uid, Users.uid == cls.fans_uid).all()
return ret