comment.py 841 B

123456789101112131415161718192021222324252627
  1. from sql import db
  2. def get_comment_list(blog_id: int):
  3. cur = db.search(columns=["Auth", "Email", "Context", "UpdateTime"],
  4. table="comment_user",
  5. where=f"BlogID={blog_id}")
  6. if cur is None or cur.rowcount == 0:
  7. return []
  8. return cur.fetchall()
  9. def write_comment(blog_id: int, user_id: int, context: str):
  10. cur = db.insert(table="comment",
  11. columns=["BlogID", "Auth", "Context"],
  12. values=f"{blog_id}, {user_id}, '{context}'")
  13. if cur is None or cur.rowcount == 0:
  14. return False
  15. return True
  16. def get_user_comment_count(user_id: int):
  17. cur = db.search(columns=["count(ID)"], table="comment",
  18. where=f"Auth={user_id}")
  19. if cur is None or cur.rowcount == 0:
  20. return 0
  21. return cur.fetchone()[0]