sqlalchemy的增删改查

#设置staticmethod方法后,在调用这个类的时候就不用实例化对象了
@staticmethod
@cache.memoize(20)
def getstudentinfo(user):

inf= set()
res = {user: val}
# # 获取code的sql
info= text(
"select name,class,score,course_id from student
where user = {user}.format(
user=user))
rows = db.session.execute(info).fetchall()
for row in rows:
inf.add(row['code'])

return res

@staticmethod
def getstudentinfo(name,class,score,course_id):

lis = []
  #一次提交多个数据用list
for r_id in course_id:
lis.append(UserRole(name=name, score=score, course_id=course_id,
created_time=time.localtime(time.time())))
db.session.add_all(lis)
db.session.flush() # 可以获取对应的id

return lis
posted @ 2020-02-25 13:18  星空之主  阅读(266)  评论(0编辑  收藏  举报