forked from Hay1tsme/artemis
forgot to push changes to ongeki
This commit is contained in:
@ -1,13 +1,15 @@
|
|||||||
from typing import Dict, List, Optional
|
from typing import Dict, List, Optional
|
||||||
from sqlalchemy import Table, Column, UniqueConstraint, PrimaryKeyConstraint, and_
|
|
||||||
from sqlalchemy.types import Integer, String, TIMESTAMP, Boolean, JSON, Float
|
from sqlalchemy import Column, Table, UniqueConstraint
|
||||||
from sqlalchemy.schema import ForeignKey
|
|
||||||
from sqlalchemy.sql import func, select
|
|
||||||
from sqlalchemy.dialects.mysql import insert
|
from sqlalchemy.dialects.mysql import insert
|
||||||
|
from sqlalchemy.engine import Row
|
||||||
|
from sqlalchemy.schema import ForeignKey
|
||||||
|
from sqlalchemy.sql import select
|
||||||
|
from sqlalchemy.types import TIMESTAMP, Boolean, Float, Integer, String
|
||||||
|
|
||||||
from core.data.schema import BaseData, metadata
|
from core.data.schema import BaseData, metadata
|
||||||
|
|
||||||
score_best = Table(
|
score_best: Table = Table(
|
||||||
"ongeki_score_best",
|
"ongeki_score_best",
|
||||||
metadata,
|
metadata,
|
||||||
Column("id", Integer, primary_key=True, nullable=False),
|
Column("id", Integer, primary_key=True, nullable=False),
|
||||||
@ -149,8 +151,41 @@ class OngekiScoreData(BaseData):
|
|||||||
return None
|
return None
|
||||||
return result.lastrowid
|
return result.lastrowid
|
||||||
|
|
||||||
async def get_best_scores(self, aime_id: int) -> Optional[List[Dict]]:
|
async def get_best_scores(
|
||||||
sql = select(score_best).where(score_best.c.user == aime_id)
|
self,
|
||||||
|
aime_id: int,
|
||||||
|
limit: Optional[int] = None,
|
||||||
|
offset: Optional[int] = None,
|
||||||
|
) -> Optional[List[Row]]:
|
||||||
|
cond = score_best.c.user == aime_id
|
||||||
|
|
||||||
|
if limit is None and offset is None:
|
||||||
|
sql = (
|
||||||
|
select(score_best)
|
||||||
|
.where(cond)
|
||||||
|
.order_by(score_best.c.musicId, score_best.c.level)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
subq = (
|
||||||
|
select(score_best.c.musicId)
|
||||||
|
.distinct()
|
||||||
|
.where(cond)
|
||||||
|
.order_by(score_best.c.musicId)
|
||||||
|
)
|
||||||
|
|
||||||
|
if limit is not None:
|
||||||
|
subq = subq.limit(limit)
|
||||||
|
if offset is not None:
|
||||||
|
subq = subq.offset(offset)
|
||||||
|
|
||||||
|
subq = subq.subquery()
|
||||||
|
|
||||||
|
sql = (
|
||||||
|
select(score_best)
|
||||||
|
.join(subq, score_best.c.musicId == subq.c.musicId)
|
||||||
|
.where(cond)
|
||||||
|
.order_by(score_best.c.musicId, score_best.c.level)
|
||||||
|
)
|
||||||
|
|
||||||
result = await self.execute(sql)
|
result = await self.execute(sql)
|
||||||
if result is None:
|
if result is None:
|
||||||
|
Reference in New Issue
Block a user