mirror of
https://github.com/283375/arcaea-offline.git
synced 2025-04-17 21:30:18 +00:00
feat(db): Score
related modify methods
This commit is contained in:
parent
c2a171a6d3
commit
d763896c0c
@ -1,5 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
from typing import List, Optional, Type, Union
|
from typing import Iterable, List, Optional, Type, Union
|
||||||
|
|
||||||
from sqlalchemy import Engine, func, inspect, select
|
from sqlalchemy import Engine, func, inspect, select
|
||||||
from sqlalchemy.orm import DeclarativeBase, InstrumentedAttribute, sessionmaker
|
from sqlalchemy.orm import DeclarativeBase, InstrumentedAttribute, sessionmaker
|
||||||
@ -245,6 +245,30 @@ class Database(metaclass=Singleton):
|
|||||||
result = session.scalar(stmt)
|
result = session.scalar(stmt)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def insert_score(self, score: Score):
|
||||||
|
with self.sessionmaker() as session:
|
||||||
|
session.add(score)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
def insert_scores(self, scores: Iterable[Score]):
|
||||||
|
with self.sessionmaker() as session:
|
||||||
|
session.add_all(scores)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
def update_score(self, score: Score):
|
||||||
|
if score.id is None:
|
||||||
|
raise ValueError(
|
||||||
|
"Cannot determine which score to update, please specify `score.id`"
|
||||||
|
)
|
||||||
|
with self.sessionmaker() as session:
|
||||||
|
session.merge(score)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
def delete_score(self, score: Score):
|
||||||
|
with self.sessionmaker() as session:
|
||||||
|
session.delete(score)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
|
|
||||||
def get_b30(self):
|
def get_b30(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user