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

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