feat: 接入mysql数据库
This commit is contained in:
24
service/report_service.py
Normal file
24
service/report_service.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import json
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from models.health import Report
|
||||
|
||||
|
||||
def upload_report(report: str, db: Session):
|
||||
report = Report(
|
||||
content=json.loads(report),
|
||||
)
|
||||
db.add(report)
|
||||
db.commit()
|
||||
db.refresh(report)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def query_report(id: int, db: Session):
|
||||
result = db.execute(
|
||||
select(Report).where(Report.id == id)
|
||||
)
|
||||
return result.scalar_one_or_none()
|
||||
Reference in New Issue
Block a user