ぼざろクリーチャーシリーズ DB 兼 API(自分用)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

156 lines
2.7 KiB

  1. # pylint: disable = missing-class-docstring
  2. # pylint: disable = missing-function-docstring
  3. """
  4. ぼざクリ DB の構成
  5. """
  6. from __future__ import annotations
  7. from datetime import date, datetime
  8. from my_eloquent import Model
  9. class Comment (Model):
  10. # pylint: disable = too-many-instance-attributes
  11. id: int
  12. video_id: int
  13. comment_no: int
  14. user_id: int
  15. content: str
  16. posted_at: datetime
  17. nico_count: int
  18. vpos_ms: int
  19. __timestamps__ = False
  20. @property
  21. def video (
  22. self,
  23. ) -> Video:
  24. return self.belongs_to (Video)
  25. @property
  26. def user (
  27. self,
  28. ) -> User:
  29. return self.belongs_to (User)
  30. def upsert (
  31. self,
  32. *args: str,
  33. ) -> None:
  34. super ().upsert ('video_id', 'comment_no')
  35. class Tag (Model):
  36. id: int
  37. name: str
  38. __timestamps__ = False
  39. @property
  40. def video_tags (
  41. self,
  42. ) -> list[VideoTag]:
  43. return self.has_many (VideoTag)
  44. class User (Model):
  45. id: int
  46. code: str
  47. __timestamps__ = False
  48. @property
  49. def comments (
  50. self,
  51. ) -> list[Comment]:
  52. return self.has_many (Comment)
  53. class Video (Model):
  54. id: int
  55. code: str
  56. title: str
  57. description: str
  58. uploaded_at: datetime
  59. deleted_at: datetime | None
  60. __timestamps__ = False
  61. @property
  62. def video_histories (
  63. self,
  64. ) -> list[VideoHistory]:
  65. return self.has_many (VideoHistory)
  66. @property
  67. def video_tags (
  68. self,
  69. ) -> list[VideoTag]:
  70. return self.has_many (VideoTag)
  71. @property
  72. def comments (
  73. self,
  74. ) -> list[Comment]:
  75. return self.has_many (Comment)
  76. def upsert (
  77. self,
  78. *args: str,
  79. ) -> None:
  80. super ().upsert ('code')
  81. class VideoHistory (Model):
  82. id: int
  83. video_id: int
  84. fetched_at: date
  85. views_count: int
  86. __timestamps__ = False
  87. @property
  88. def video (
  89. self,
  90. ) -> Video:
  91. return self.belongs_to (Video)
  92. def upsert (
  93. self,
  94. *args: str,
  95. ) -> None:
  96. super ().upsert ('video_id', 'fetched_at')
  97. class VideoTag (Model):
  98. id: int
  99. video_id: int
  100. tag_id: int
  101. tagged_at: date
  102. untagged_at: date | None
  103. __timestamps__ = False
  104. @property
  105. def video (
  106. self,
  107. ) -> Video:
  108. return self.belongs_to (Video)
  109. @property
  110. def tag (
  111. self,
  112. ) -> Tag:
  113. return self.belongs_to (Tag)
  114. def upsert (
  115. self,
  116. *args: str,
  117. ) -> None:
  118. super ().upsert ('video_id', 'tag_id')