comment.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from sql import db
  2. def read_comment(blog_id: int):
  3. """ 读取文章的 comment """
  4. cur = db.search(columns=["ID", "Auth", "Email", "Context", "UpdateTime"],
  5. table="comment_user",
  6. where=f"BlogID={blog_id}")
  7. if cur is None or cur.rowcount == 0:
  8. return []
  9. return cur.fetchall()
  10. def create_comment(blog_id: int, user_id: int, context: str):
  11. """ 新建 comment """
  12. cur = db.insert(table="comment",
  13. columns=["BlogID", "Auth", "Context"],
  14. values=f"{blog_id}, {user_id}, '{context}'")
  15. if cur is None or cur.rowcount == 0:
  16. return False
  17. return True
  18. def delete_comment(comment_id):
  19. """ 删除评论 """
  20. cur = db.delete(table="comment", where=f"ID={comment_id}")
  21. if cur is None or cur.rowcount == 0:
  22. return False
  23. return True
  24. def get_user_comment_count(user_id: int):
  25. """ 读取指定用户的 comment 个数 """
  26. cur = db.search(columns=["count(ID)"], table="comment",
  27. where=f"Auth={user_id}")
  28. if cur is None or cur.rowcount == 0:
  29. return 0
  30. return cur.fetchone()[0]