|
@@ -9,7 +9,7 @@ from __future__ import annotations |
|
|
|
|
|
|
|
|
from datetime import date, datetime |
|
|
from datetime import date, datetime |
|
|
|
|
|
|
|
|
from eloquent import Model |
|
|
|
|
|
|
|
|
from my_eloquent import Model |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Comment (Model): |
|
|
class Comment (Model): |
|
@@ -40,8 +40,9 @@ class Comment (Model): |
|
|
|
|
|
|
|
|
def upsert ( |
|
|
def upsert ( |
|
|
self, |
|
|
self, |
|
|
|
|
|
*args: str, |
|
|
) -> None: |
|
|
) -> None: |
|
|
upsert (self, 'video_id', 'comment_no') |
|
|
|
|
|
|
|
|
super ().upsert ('video_id', 'comment_no') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Tag (Model): |
|
|
class Tag (Model): |
|
@@ -53,7 +54,7 @@ class Tag (Model): |
|
|
@property |
|
|
@property |
|
|
def video_tags ( |
|
|
def video_tags ( |
|
|
self, |
|
|
self, |
|
|
) -> VideoTag: |
|
|
|
|
|
|
|
|
) -> list[VideoTag]: |
|
|
return self.has_many (VideoTag) |
|
|
return self.has_many (VideoTag) |
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -66,7 +67,7 @@ class User (Model): |
|
|
@property |
|
|
@property |
|
|
def comments ( |
|
|
def comments ( |
|
|
self, |
|
|
self, |
|
|
) -> Comment: |
|
|
|
|
|
|
|
|
) -> list[Comment]: |
|
|
return self.has_many (Comment) |
|
|
return self.has_many (Comment) |
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -83,25 +84,26 @@ class Video (Model): |
|
|
@property |
|
|
@property |
|
|
def video_histories ( |
|
|
def video_histories ( |
|
|
self, |
|
|
self, |
|
|
) -> VideoHistory: |
|
|
|
|
|
|
|
|
) -> list[VideoHistory]: |
|
|
return self.has_many (VideoHistory) |
|
|
return self.has_many (VideoHistory) |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def video_tags ( |
|
|
def video_tags ( |
|
|
self, |
|
|
self, |
|
|
) -> VideoTag: |
|
|
|
|
|
|
|
|
) -> list[VideoTag]: |
|
|
return self.has_many (VideoTag) |
|
|
return self.has_many (VideoTag) |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def comments ( |
|
|
def comments ( |
|
|
self, |
|
|
self, |
|
|
) -> Comment: |
|
|
|
|
|
|
|
|
) -> list[Comment]: |
|
|
return self.has_many (Comment) |
|
|
return self.has_many (Comment) |
|
|
|
|
|
|
|
|
def upsert ( |
|
|
def upsert ( |
|
|
self, |
|
|
self, |
|
|
|
|
|
*args: str, |
|
|
) -> None: |
|
|
) -> None: |
|
|
upsert (self, 'code') |
|
|
|
|
|
|
|
|
super ().upsert ('code') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class VideoHistory (Model): |
|
|
class VideoHistory (Model): |
|
@@ -120,8 +122,9 @@ class VideoHistory (Model): |
|
|
|
|
|
|
|
|
def upsert ( |
|
|
def upsert ( |
|
|
self, |
|
|
self, |
|
|
|
|
|
*args: str, |
|
|
) -> None: |
|
|
) -> None: |
|
|
upsert (self, 'video_id', 'fetched_at') |
|
|
|
|
|
|
|
|
super ().upsert ('video_id', 'fetched_at') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class VideoTag (Model): |
|
|
class VideoTag (Model): |
|
@@ -147,23 +150,6 @@ class VideoTag (Model): |
|
|
|
|
|
|
|
|
def upsert ( |
|
|
def upsert ( |
|
|
self, |
|
|
self, |
|
|
|
|
|
*args: str, |
|
|
) -> None: |
|
|
) -> 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') |