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

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