当前位置: 首页>>代码示例>>Python>>正文


Python DBSession.query方法代码示例

本文整理汇总了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()
开发者ID:hellowego,项目名称:auto,代码行数:14,代码来源:answer_models.py

示例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
开发者ID:euzhang,项目名称:auto,代码行数:9,代码来源:answer_vote_models.py

示例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
开发者ID:euzhang,项目名称:auto,代码行数:9,代码来源:account_models.py

示例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
开发者ID:hellowego,项目名称:auto,代码行数:10,代码来源:users_models.py

示例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
开发者ID:hellowego,项目名称:auto,代码行数:11,代码来源:user_vote_model.py

示例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'
开发者ID:euzhang,项目名称:auto,代码行数:15,代码来源:account_models.py

示例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'
开发者ID:euzhang,项目名称:auto,代码行数:15,代码来源:account_models.py

示例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
开发者ID:euzhang,项目名称:auto,代码行数:17,代码来源:account_models.py

示例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
开发者ID:hellowego,项目名称:auto,代码行数:21,代码来源:userFollow_models.py

示例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
开发者ID:hellowego,项目名称:auto,代码行数:6,代码来源:question_models.py

示例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
开发者ID:hellowego,项目名称:auto,代码行数:6,代码来源:question_models.py

示例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()

开发者ID:hellowego,项目名称:auto,代码行数:31,代码来源:question_models.py

示例13: queryPageCount

# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import query [as 别名]
	def queryPageCount(cls):
		session = DBSession()
		count = session.query(cls)
开发者ID:hellowego,项目名称:auto,代码行数:5,代码来源:catalogModel.py

示例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
开发者ID:hellowego,项目名称:auto,代码行数:6,代码来源:catalogModel.py

示例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
开发者ID:hellowego,项目名称:auto,代码行数:8,代码来源:userFollow_models.py


注:本文中的db.dbSession.DBSession.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。