32 lines
1001 B
Python
32 lines
1001 B
Python
"""基金业绩指标仓储。"""
|
|
from __future__ import annotations
|
|
|
|
from sqlalchemy import select
|
|
|
|
from model.fund_performance import FundPerformance
|
|
from repositories.base import BaseRepository
|
|
|
|
|
|
class FundPerformanceRepo(BaseRepository):
|
|
model = FundPerformance
|
|
|
|
async def get_latest_for_product(self, product_id: int) -> FundPerformance | None:
|
|
stmt = (
|
|
select(FundPerformance)
|
|
.where(FundPerformance.product_id == product_id)
|
|
.order_by(
|
|
FundPerformance.calc_date.desc(),
|
|
FundPerformance.id.desc(),
|
|
)
|
|
.limit(1)
|
|
)
|
|
return (await self.db.scalars(stmt)).first()
|
|
|
|
async def list_for_product(self, product_id: int) -> list[FundPerformance]:
|
|
stmt = (
|
|
select(FundPerformance)
|
|
.where(FundPerformance.product_id == product_id)
|
|
.order_by(FundPerformance.period.asc())
|
|
)
|
|
return list((await self.db.scalars(stmt)).all())
|