|
|
@@ -9,7 +9,7 @@ from __future__ import annotations |
|
|
|
|
|
|
|
from datetime import date, datetime |
|
|
|
|
|
|
|
from eloquent import Model |
|
|
|
from my_eloquent import Model |
|
|
|
|
|
|
|
|
|
|
|
class Comment (Model): |
|
|
@@ -40,8 +40,9 @@ class Comment (Model): |
|
|
|
|
|
|
|
def upsert ( |
|
|
|
self, |
|
|
|
*args: str, |
|
|
|
) -> None: |
|
|
|
upsert (self, 'video_id', 'comment_no') |
|
|
|
super ().upsert ('video_id', 'comment_no') |
|
|
|
|
|
|
|
|
|
|
|
class Tag (Model): |
|
|
@@ -53,7 +54,7 @@ class Tag (Model): |
|
|
|
@property |
|
|
|
def video_tags ( |
|
|
|
self, |
|
|
|
) -> VideoTag: |
|
|
|
) -> list[VideoTag]: |
|
|
|
return self.has_many (VideoTag) |
|
|
|
|
|
|
|
|
|
|
@@ -66,7 +67,7 @@ class User (Model): |
|
|
|
@property |
|
|
|
def comments ( |
|
|
|
self, |
|
|
|
) -> Comment: |
|
|
|
) -> list[Comment]: |
|
|
|
return self.has_many (Comment) |
|
|
|
|
|
|
|
|
|
|
@@ -83,25 +84,26 @@ class Video (Model): |
|
|
|
@property |
|
|
|
def video_histories ( |
|
|
|
self, |
|
|
|
) -> VideoHistory: |
|
|
|
) -> list[VideoHistory]: |
|
|
|
return self.has_many (VideoHistory) |
|
|
|
|
|
|
|
@property |
|
|
|
def video_tags ( |
|
|
|
self, |
|
|
|
) -> VideoTag: |
|
|
|
) -> list[VideoTag]: |
|
|
|
return self.has_many (VideoTag) |
|
|
|
|
|
|
|
@property |
|
|
|
def comments ( |
|
|
|
self, |
|
|
|
) -> Comment: |
|
|
|
) -> list[Comment]: |
|
|
|
return self.has_many (Comment) |
|
|
|
|
|
|
|
def upsert ( |
|
|
|
self, |
|
|
|
*args: str, |
|
|
|
) -> None: |
|
|
|
upsert (self, 'code') |
|
|
|
super ().upsert ('code') |
|
|
|
|
|
|
|
|
|
|
|
class VideoHistory (Model): |
|
|
@@ -120,8 +122,9 @@ class VideoHistory (Model): |
|
|
|
|
|
|
|
def upsert ( |
|
|
|
self, |
|
|
|
*args: str, |
|
|
|
) -> None: |
|
|
|
upsert (self, 'video_id', 'fetched_at') |
|
|
|
super ().upsert ('video_id', 'fetched_at') |
|
|
|
|
|
|
|
|
|
|
|
class VideoTag (Model): |
|
|
@@ -147,23 +150,6 @@ class VideoTag (Model): |
|
|
|
|
|
|
|
def upsert ( |
|
|
|
self, |
|
|
|
*args: str, |
|
|
|
) -> None: |
|
|
|
upsert (self, 'video_id', 'tag_id') |
|
|
|
|
|
|
|
|
|
|
|
def upsert ( |
|
|
|
model: Model, |
|
|
|
*args: str, |
|
|
|
) -> None: |
|
|
|
q = model.query () |
|
|
|
|
|
|
|
for arg in args: |
|
|
|
q = q.where (arg, getattr (model, arg)) |
|
|
|
|
|
|
|
row = q.first () |
|
|
|
|
|
|
|
if row is not None: |
|
|
|
model.id = row.id |
|
|
|
model._Model__exists = True # pylint: disable = protected-access |
|
|
|
|
|
|
|
model.save () |
|
|
|
super ().upsert ('video_id', 'tag_id') |