|
@@ -26,10 +26,10 @@ def main ( |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_video_table ( |
|
|
def update_video_table ( |
|
|
video_dao, |
|
|
|
|
|
|
|
|
video_dao: VideoDao, |
|
|
api_data: list[dict], |
|
|
api_data: list[dict], |
|
|
) -> None: |
|
|
) -> None: |
|
|
# TODO: 書くこと |
|
|
|
|
|
|
|
|
# TODO: videos 取得書くこと |
|
|
|
|
|
|
|
|
video_dao.upsert_all (videos) |
|
|
video_dao.upsert_all (videos) |
|
|
|
|
|
|
|
@@ -176,7 +176,7 @@ class VideoDao: |
|
|
self, |
|
|
self, |
|
|
videos: list[VideoDto], |
|
|
videos: list[VideoDto], |
|
|
with_relation_tables: bool = True, |
|
|
with_relation_tables: bool = True, |
|
|
) -> int: |
|
|
|
|
|
|
|
|
) -> None: |
|
|
with self.conn.cursor () as c: |
|
|
with self.conn.cursor () as c: |
|
|
for video in videos: |
|
|
for video in videos: |
|
|
c.execute (""" |
|
|
c.execute (""" |
|
@@ -199,14 +199,16 @@ class VideoDao: |
|
|
title = VALUES(title), |
|
|
title = VALUES(title), |
|
|
description = VALUES(description), |
|
|
description = VALUES(description), |
|
|
uploaded_at = VALUES(uploaded_at), |
|
|
uploaded_at = VALUES(uploaded_at), |
|
|
deleted_at = VALUES(deleted_at)""", ( |
|
|
|
|
|
video.code, |
|
|
|
|
|
video.title, |
|
|
|
|
|
video.description, |
|
|
|
|
|
video.uploaded_at, |
|
|
|
|
|
video.deleted_at)) |
|
|
|
|
|
|
|
|
deleted_at = VALUES(deleted_at)""", (video.code, |
|
|
|
|
|
video.title, |
|
|
|
|
|
video.description, |
|
|
|
|
|
video.uploaded_at, |
|
|
|
|
|
video.deleted_at)) |
|
|
video.id_ = c.lastrowid |
|
|
video.id_ = c.lastrowid |
|
|
# TODO: with_relation_tables が True の場合,子テーブルも UPSERT すること |
|
|
|
|
|
|
|
|
if with_relation_tables: |
|
|
|
|
|
VideoTagDao (self.conn).upsert_all (video.video_tags, False) |
|
|
|
|
|
CommentDao (self.conn).upsert_all (video.comments, False) |
|
|
|
|
|
VideoHistoryDao (self.conn).upsert_all (video.video_histories, False) |
|
|
|
|
|
|
|
|
def _create_dto_from_row ( |
|
|
def _create_dto_from_row ( |
|
|
self, |
|
|
self, |
|
@@ -218,10 +220,7 @@ class VideoDao: |
|
|
title = row['title'], |
|
|
title = row['title'], |
|
|
description = row['description'], |
|
|
description = row['description'], |
|
|
uploaded_at = row['uploaded_at'], |
|
|
uploaded_at = row['uploaded_at'], |
|
|
deleted_at = row['deleted_at'], |
|
|
|
|
|
video_tags = None, |
|
|
|
|
|
comments = None, |
|
|
|
|
|
video_histories = None) |
|
|
|
|
|
|
|
|
deleted_at = row['deleted_at']) |
|
|
if with_relation_tables: |
|
|
if with_relation_tables: |
|
|
video.video_tags = VideoTagDao (self.conn).fetch_by_video_id (video.id_, False) |
|
|
video.video_tags = VideoTagDao (self.conn).fetch_by_video_id (video.id_, False) |
|
|
for i in range (len (video.video_tags)): |
|
|
for i in range (len (video.video_tags)): |
|
@@ -237,15 +236,15 @@ class VideoDao: |
|
|
|
|
|
|
|
|
@dataclass (slots = True) |
|
|
@dataclass (slots = True) |
|
|
class VideoDto: |
|
|
class VideoDto: |
|
|
id_: int |
|
|
|
|
|
|
|
|
id_: int | None = None |
|
|
code: str |
|
|
code: str |
|
|
title: str |
|
|
title: str |
|
|
description: str |
|
|
description: str |
|
|
uploaded_at: datetime |
|
|
uploaded_at: datetime |
|
|
deleted_at: datetime | None |
|
|
|
|
|
video_tags: list[VideoTagDto] | None |
|
|
|
|
|
comments: list[CommentDto] | None |
|
|
|
|
|
video_histories: list[VideoHistoryDto] | None |
|
|
|
|
|
|
|
|
deleted_at: datetime | None = None |
|
|
|
|
|
video_tags: list[VideoTagDto] | None = None |
|
|
|
|
|
comments: list[CommentDto] | None = None |
|
|
|
|
|
video_histories: list[VideoHistoryDto] | None = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class VideoTagDao: |
|
|
class VideoTagDao: |
|
@@ -288,9 +287,7 @@ class VideoTagDao: |
|
|
video_id = row['video_id'], |
|
|
video_id = row['video_id'], |
|
|
tag_id = row['tag_id'], |
|
|
tag_id = row['tag_id'], |
|
|
tagged_at = row['tagged_at'], |
|
|
tagged_at = row['tagged_at'], |
|
|
untagged_at = row['untagged_at'], |
|
|
|
|
|
video = None, |
|
|
|
|
|
tag = None) |
|
|
|
|
|
|
|
|
untagged_at = row['untagged_at']) |
|
|
if with_relation_tables: |
|
|
if with_relation_tables: |
|
|
video_tag.video = VideoDao (self.conn).fetch (video_tag.video_id, True) |
|
|
video_tag.video = VideoDao (self.conn).fetch (video_tag.video_id, True) |
|
|
video_tag.tag = TagDao (self.conn).fetch (video_tag.tag_id, True) |
|
|
video_tag.tag = TagDao (self.conn).fetch (video_tag.tag_id, True) |
|
@@ -299,13 +296,13 @@ class VideoTagDao: |
|
|
|
|
|
|
|
|
@dataclass (slots = True) |
|
|
@dataclass (slots = True) |
|
|
class VideoTagDto: |
|
|
class VideoTagDto: |
|
|
id_: int |
|
|
|
|
|
|
|
|
id_: int | None = None |
|
|
video_id: int |
|
|
video_id: int |
|
|
tag_id: int |
|
|
tag_id: int |
|
|
tagged_at: datetime |
|
|
tagged_at: datetime |
|
|
untagged_at: datetime |
|
|
untagged_at: datetime |
|
|
video: VideoDto |
|
|
|
|
|
tag: TagDto |
|
|
|
|
|
|
|
|
video: VideoDto | None = None |
|
|
|
|
|
tag: TagDto | None = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
if __name__ == '__main__': |
|
|