Browse Source

video_histories への書込みを Upsert に

main
みてるぞ 4 weeks ago
parent
commit
067c90890e
5 changed files with 13 additions and 2 deletions
  1. BIN
      __pycache__/models.cpython-312.pyc
  2. BIN
      __pycache__/my_eloquent.cpython-312.pyc
  3. BIN
      __pycache__/update_db.cpython-312.pyc
  4. +12
    -1
      my_eloquent.py
  5. +1
    -1
      update_db.py

BIN
__pycache__/models.cpython-312.pyc View File


BIN
__pycache__/my_eloquent.cpython-312.pyc View File


BIN
__pycache__/update_db.cpython-312.pyc View File


+ 12
- 1
my_eloquent.py View File

@@ -1,3 +1,10 @@
# pylint: disable = missing-class-docstring
# pylint: disable = missing-function-docstring

"""
みてるぞ式魔改造(言ふほどか?)版 Eloquent
"""

import eloquent


@@ -6,6 +13,8 @@ class DatabaseManager (eloquent.DatabaseManager):


class Model (eloquent.Model):
id: int

def upsert (
self,
*args: str,
@@ -16,5 +25,7 @@ class Model (eloquent.Model):
row = q.first ()
if row is not None:
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 ()

+ 1
- 1
update_db.py View File

@@ -59,7 +59,7 @@ def update_tables (
video_history.video_id = video.id
video_history.fetched_at = now
video_history.views_count = datum['viewCounter']
video_history.save ()
video_history.upsert ()
video_tags = [video_tag for video_tag in video.video_tags
if video_tag.untagged_at is not None]
tag: Tag | None


Loading…
Cancel
Save