fix: api示例增加数据库操作示例
Gitea Action for docker build / build-app (push) Successful in 34s
Details
Gitea Action for docker build / build-app (push) Successful in 34s
Details
This commit is contained in:
parent
c6767778e2
commit
bd9dac23be
|
|
@ -4,7 +4,7 @@ lifetime_seconds=3600
|
||||||
|
|
||||||
[mysql]
|
[mysql]
|
||||||
username=root
|
username=root
|
||||||
password=Chenweijia113!
|
password=123456
|
||||||
host=127.0.0.1
|
host=127.0.0.1
|
||||||
port=3306
|
port=3306
|
||||||
database=test
|
database=test
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import aioredis
|
||||||
from fastapi import APIRouter, Depends, Query
|
from fastapi import APIRouter, Depends, Query
|
||||||
from fastapi.security import OAuth2PasswordBearer
|
from fastapi.security import OAuth2PasswordBearer
|
||||||
from fastapi_plugins import depends_redis
|
from fastapi_plugins import depends_redis
|
||||||
|
from fastapi_sqlalchemy import db
|
||||||
|
from sqlalchemy.sql import text
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
from src.service.example import get_user_by_id
|
from src.service.example import get_user_by_id
|
||||||
|
|
@ -59,6 +61,11 @@ async def get_user_list_pages(page: int = Query(..., description="当前页码")
|
||||||
res = response(data=data, message="Ok!")
|
res = response(data=data, message="Ok!")
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
# 数据库查询
|
||||||
|
@router.get('/get_db_version')
|
||||||
|
async def get_db_version():
|
||||||
|
result = db.session.execute(text("SELECT version()")).first()
|
||||||
|
return dict(result=result.tuple()[0])
|
||||||
|
|
||||||
# Redis 缓存查询
|
# Redis 缓存查询
|
||||||
@router.get("/ping")
|
@router.get("/ping")
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
set FAST_API_ENV=dev
|
set FAST_API_ENV=dev
|
||||||
uvicorn main:fast_api_app --reload --host 0.0.0.0 --port 21021
|
uvicorn main:fast_api_app --reload --host 0.0.0.0 --port 8088
|
||||||
Loading…
Reference in New Issue