本文整理汇总了Python中db.dbSession.DBSession.add方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.add方法的具体用法?Python DBSession.add怎么用?Python DBSession.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.dbSession.DBSession
的用法示例。
在下文中一共展示了DBSession.add方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import add [as 别名]
def add(cls, session_id, value):
obj = cls(session_id = session_id, value = value, add_time = long(time.time()))
session = DBSession()
session.add(obj)
session.commit()
session.close()
return True
示例2: add
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import add [as 别名]
def add(cls, name, url):
obj = cls(uid = uid, name = name, url = url, add_time = long(time.time()))
session = DBSession()
session.add(obj)
session.commit()
session.close()
return True
示例3: addAnswer
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import add [as 别名]
def addAnswer(cls, questionId, answerContent, userId):
obj = cls(question_id = questionId, answer_content = answerContent, uid = userId, add_time = long(time.time()))
session = DBSession()
session.add(obj)
session.commit()
session.close()
return True
示例4: addAnswerComment
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import add [as 别名]
def addAnswerComment(cls, answer_id, uid, message):
obj = cls(answer_id = answer_id, uid = uid, message = message)
session = DBSession()
session.add(obj)
session.commit()
session.close()
return True
示例5: add
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import add [as 别名]
def add(cls, userid, linkid, type):
obj = cls(user_id = userid, link_id = linkid, type = type, add_time = long(time.time()))
session = DBSession()
session.add(obj)
session.commit()
session.close()
return True
示例6: addAnswerVote
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import add [as 别名]
def addAnswerVote(cls, answer_id, answer_uid, vote_uid, vote_value):
obj = cls(answer_id = answer_id, answer_uid = answer_uid, vote_uid = vote_uid, add_time = long(time.time()), vote_value = vote_value, reputation_factor = 1)
session = DBSession()
session.add(obj)
session.commit()
session.close()
return True
示例7: addQuestion
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import add [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
示例8: addUser
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import add [as 别名]
def addUser(cls, username, email, password):
hashed_password = bcrypt.hashpw(tornado.escape.utf8(password), bcrypt.gensalt())
print hashed_password
ret = cls(name = username, email = email, hashed_password = hashed_password)
session = DBSession()
session.add(ret)
session.commit()
session.close()
return True
示例9: follow
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import add [as 别名]
def follow(cls, fansUid, friendUid):
'''
添加关注
同时更新用户表的粉丝数和关注数
'''
ret = cls(fans_uid = fansUid, friend_uid = friendUid)
session = DBSession()
session.add(ret)
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: AutoUser
# 需要导入模块: from db.dbSession import DBSession [as 别名]
# 或者: from db.dbSession.DBSession import add [as 别名]
import sys
sys.path.append("..")
from db.dbSession import BaseModel, DBSession
from sqlalchemy import Column, String, Integer
class AutoUser(BaseModel):
"""
user model
"""
__tablename__ = 'authors'
id = Column(Integer, primary_key=True, nullable=False)
name = Column(String(64), nullable=False)
hashed_password = Column(String(64), nullable=False)
email = Column(String(64), nullable=False)
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)
# 提交即保存到数据库:
session.commit()
# 关闭session:
session.close()