def record_to_model(record: Record, model_class: ModelType) -> Model: """Convert a Record object to Model object. Args: record (Record): Record object. model_class (ModelType): Model class Returns: Model: Model instance. """ new_record = model_class() for k, v in record.items(): new_record.Meta._fromdb_.append(k) setattr(new_record, k, v) return new_record
def from_record(cls: Type[T], record: Record) -> T: """Converts a database record (row) to entity of this type.""" # Pass all values (including id) to constructor as named arguments return cls(**dict(record.items())) # type: ignore
def as_box(record: asyncpg.Record) -> Box: return Box(record.items())
async def populate_cleaning_feed_item(self, *, cleaning_feed_item: Record) -> CleaningFeedItem: return CleaningFeedItem( **{k: v for k, v in cleaning_feed_item.items() if k != "owner"}, owner=await self.users_repo.get_user_by_id(user_id=cleaning_feed_item["owner"]) )