-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfeed_impl.py
More file actions
27 lines (22 loc) · 959 Bytes
/
feed_impl.py
File metadata and controls
27 lines (22 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from shared.db_models.basic_feed_impl import BaseFeedImpl
from feeds_gen.models.feed import Feed
from shared.database_gen.sqlacodegen_models import Feed as FeedOrm
class FeedImpl(BaseFeedImpl, Feed):
"""Base implementation of the feeds models.
This class converts a SQLAlchemy row DB object with common feed fields to a Pydantic model.
"""
class Config:
"""Pydantic configuration.
Enabling `from_attributes` method to create a model instance from a SQLAlchemy row object."""
from_attributes = True
@classmethod
def from_orm(cls, feed_orm: FeedOrm | None) -> Feed | None:
feed: Feed = super().from_orm(feed_orm)
if not feed:
return None
feed.status = feed_orm.status
feed.official = feed_orm.official
feed.official_updated_at = feed_orm.official_updated_at
feed.feed_name = feed_orm.feed_name
feed.note = feed_orm.note
return feed