ぼざろクリーチャーシリーズ 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.
 
 
 

178 lines
3.1 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 db.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 TrackedVideo (Model):
  45. id: int
  46. code: str
  47. __timestamps__ = False
  48. def upsert (
  49. self,
  50. *args: str,
  51. ) -> None:
  52. super ().upsert ('code')
  53. class User (Model):
  54. id: int
  55. code: str
  56. __timestamps__ = False
  57. @property
  58. def comments (
  59. self,
  60. ) -> list[Comment]:
  61. return self.has_many (Comment)
  62. class Video (Model):
  63. id: int
  64. code: str
  65. user_id: int | None
  66. title: str
  67. description: str
  68. uploaded_at: datetime
  69. deleted_at: datetime | None
  70. __timestamps__ = False
  71. @property
  72. def user (
  73. self,
  74. ) -> User | None:
  75. if self.user_id is None:
  76. return None
  77. return self.belongs_to (User)
  78. @property
  79. def video_histories (
  80. self,
  81. ) -> list[VideoHistory]:
  82. return self.has_many (VideoHistory)
  83. @property
  84. def video_tags (
  85. self,
  86. ) -> list[VideoTag]:
  87. return self.has_many (VideoTag)
  88. @property
  89. def comments (
  90. self,
  91. ) -> list[Comment]:
  92. return self.has_many (Comment)
  93. def upsert (
  94. self,
  95. *args: str,
  96. ) -> None:
  97. super ().upsert ('code')
  98. class VideoHistory (Model):
  99. id: int
  100. video_id: int
  101. fetched_at: date
  102. views_count: int
  103. __timestamps__ = False
  104. @property
  105. def video (
  106. self,
  107. ) -> Video:
  108. return self.belongs_to (Video)
  109. def upsert (
  110. self,
  111. *args: str,
  112. ) -> None:
  113. super ().upsert ('video_id', 'fetched_at')
  114. class VideoTag (Model):
  115. id: int
  116. video_id: int
  117. tag_id: int
  118. tagged_at: date
  119. untagged_at: date | None
  120. __timestamps__ = False
  121. @property
  122. def video (
  123. self,
  124. ) -> Video:
  125. return self.belongs_to (Video)
  126. @property
  127. def tag (
  128. self,
  129. ) -> Tag:
  130. return self.belongs_to (Tag)
  131. def upsert (
  132. self,
  133. *args: str,
  134. ) -> None:
  135. super ().upsert ('video_id', 'tag_id')