Browse Source

【お試し】Upsert 時に LAST_INSERT_ID 指定

feature/query
みてるぞ 1 month ago
parent
commit
6535cbed70
1 changed files with 10 additions and 5 deletions
  1. +10
    -5
      update_db.py

+ 10
- 5
update_db.py View File

@@ -403,6 +403,7 @@ class VideoDao:
%s, %s,
%s) %s)
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
id = LAST_INSERT_ID(id),
code = VALUES(code), code = VALUES(code),
title = VALUES(title), title = VALUES(title),
description = VALUES(description), description = VALUES(description),
@@ -623,6 +624,7 @@ class VideoTagDao:
%s, %s,
%s) %s)
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
id = LAST_INSERT_ID(id),
video_id = VALUES(video_id), video_id = VALUES(video_id),
tag_id = VALUES(tag_id), tag_id = VALUES(tag_id),
tagged_at = VALUES(tagged_at), tagged_at = VALUES(tagged_at),
@@ -756,6 +758,7 @@ class TagDao:
VALUES VALUES
(%s) (%s)
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
id = LAST_INSERT_ID(id),
name = VALUES(name)""", (tag.name,))) name = VALUES(name)""", (tag.name,)))
tag.id_ = c.lastrowid tag.id_ = c.lastrowid


@@ -837,11 +840,12 @@ class VideoHistoryDao:
%s, %s,
%s) %s)
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
video_id,
fetched_at,
views_count""", (video_history.video_id,
video_history.fetched_at,
video_history.views_count)))
id = LAST_INSERT_ID(id),
video_id = VALUES(video_id),
fetched_at = VALUES(fetched_at),
views_count = VALUES(views_count)""", (video_history.video_id,
video_history.fetched_at,
video_history.views_count)))


def upsert_all ( def upsert_all (
self, self,
@@ -938,6 +942,7 @@ class CommentDao:
%s, %s,
%s) %s)
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
id = LAST_INSERT_ID(id),
video_id = VALUES(video_id), video_id = VALUES(video_id),
comment_no = VALUES(comment_no), comment_no = VALUES(comment_no),
user_id = VALUES(user_id), user_id = VALUES(user_id),


Loading…
Cancel
Save