video_histories への書込みを Upsert に

このコミットが含まれているのは:
2024-10-16 22:40:42 +09:00
コミット 067c90890e
5個のファイルの変更13行の追加2行の削除
バイナリ
ファイルの表示
バイナリファイルは表示されません.
バイナリファイルは表示されません.
バイナリファイルは表示されません.
+12 -1
ファイルの表示
@@ -1,3 +1,10 @@
# pylint: disable = missing-class-docstring
# pylint: disable = missing-function-docstring
"""
みてるぞ式魔改造(言ふほどか?)版 Eloquent
"""
import eloquent import eloquent
@@ -6,6 +13,8 @@ class DatabaseManager (eloquent.DatabaseManager):
class Model (eloquent.Model): class Model (eloquent.Model):
id: int
def upsert ( def upsert (
self, self,
*args: str, *args: str,
@@ -16,5 +25,7 @@ class Model (eloquent.Model):
row = q.first () row = q.first ()
if row is not None: if row is not None:
self.id = row.id self.id = row.id
self._Model__exists = True # pylint: disable = protected-access # pylint: disable = invalid-name
# pylint: disable = attribute-defined-outside-init
self._Model__exists = True
self.save () self.save ()
+1 -1
ファイルの表示
@@ -59,7 +59,7 @@ def update_tables (
video_history.video_id = video.id video_history.video_id = video.id
video_history.fetched_at = now video_history.fetched_at = now
video_history.views_count = datum['viewCounter'] video_history.views_count = datum['viewCounter']
video_history.save () video_history.upsert ()
video_tags = [video_tag for video_tag in video.video_tags video_tags = [video_tag for video_tag in video.video_tags
if video_tag.untagged_at is not None] if video_tag.untagged_at is not None]
tag: Tag | None tag: Tag | None