Browse Source

本日作業分

feature/query
みてるぞ 1 month ago
parent
commit
d8b83c8632
1 changed files with 36 additions and 0 deletions
  1. +36
    -0
      update_db.py

+ 36
- 0
update_db.py View File

@@ -172,6 +172,42 @@ class VideoDao:
videos.append (self._create_dto_from_row (row, with_relation_tables))
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 (
self,
row,


Loading…
Cancel
Save