|
@@ -172,6 +172,42 @@ class VideoDao: |
|
|
videos.append (self._create_dto_from_row (row, with_relation_tables)) |
|
|
videos.append (self._create_dto_from_row (row, with_relation_tables)) |
|
|
return videos |
|
|
return videos |
|
|
|
|
|
|
|
|
|
|
|
def upsert_all ( |
|
|
|
|
|
self, |
|
|
|
|
|
videos: list[VideoDto], |
|
|
|
|
|
with_relation_tables: bool = True, |
|
|
|
|
|
) -> int: |
|
|
|
|
|
with self.conn.cursor () as c: |
|
|
|
|
|
for video in videos: |
|
|
|
|
|
c.execute (""" |
|
|
|
|
|
INSERT INTO |
|
|
|
|
|
videos( |
|
|
|
|
|
code, |
|
|
|
|
|
title, |
|
|
|
|
|
description, |
|
|
|
|
|
uploaded_at, |
|
|
|
|
|
deleted_at) |
|
|
|
|
|
VALUES |
|
|
|
|
|
( |
|
|
|
|
|
%s, |
|
|
|
|
|
%s, |
|
|
|
|
|
%s, |
|
|
|
|
|
%s, |
|
|
|
|
|
%s) |
|
|
|
|
|
ON DUPLICATE KEY UPDATE |
|
|
|
|
|
code = VALUES(code), |
|
|
|
|
|
title = VALUES(title), |
|
|
|
|
|
description = VALUES(description), |
|
|
|
|
|
uploaded_at = VALUES(uploaded_at), |
|
|
|
|
|
deleted_at = VALUES(deleted_at)""", ( |
|
|
|
|
|
video.code, |
|
|
|
|
|
video.title, |
|
|
|
|
|
video.description, |
|
|
|
|
|
video.uploaded_at, |
|
|
|
|
|
video.deleted_at)) |
|
|
|
|
|
video.id_ = c.lastrowid |
|
|
|
|
|
# TODO: with_relation_tables が True の場合,子テーブルも UPSERT すること |
|
|
|
|
|
|
|
|
def _create_dto_from_row ( |
|
|
def _create_dto_from_row ( |
|
|
self, |
|
|
self, |
|
|
row, |
|
|
row, |
|
|