From acc9a849a47f0bd3ee9aa85313d429f76a95881d Mon Sep 17 00:00:00 2001 From: martsforever Date: Thu, 2 Apr 2026 15:01:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E6=89=80=E9=9C=80=E8=A6=81=E7=9A=84=E5=B7=A5=E5=85=B7=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/utils/next_id.py | 23 +++++++++++++++++++++++ app/utils/path_join.py | 6 ++++++ 2 files changed, 29 insertions(+) create mode 100644 app/utils/next_id.py create mode 100644 app/utils/path_join.py diff --git a/app/utils/next_id.py b/app/utils/next_id.py new file mode 100644 index 0000000..e47b035 --- /dev/null +++ b/app/utils/next_id.py @@ -0,0 +1,23 @@ +from fastapi import FastAPI +from sqlalchemy import text + +from app.utils.mysql_utils import async_session + + +async def next_id(num: int = 1): + async with async_session() as session: + sql_string = "select " + ",".join([f"uuid() as _{index}" for index in range(num)]) + print(sql_string) + result = await session.execute(text(sql_string)) + val = result.first() + print(val) + arr = list(val or []) + return arr[0] if num == 1 else arr + + +def add_next_id_route(app: FastAPI): + @app.get("/next_id") + async def _next_id(num: int = 1): + return { + "data": await next_id(num), + } diff --git a/app/utils/path_join.py b/app/utils/path_join.py new file mode 100644 index 0000000..5f33a3d --- /dev/null +++ b/app/utils/path_join.py @@ -0,0 +1,6 @@ +import os +from typing import List + + +def path_join(*pat_list: List[str]): + return os.path.join(*pat_list).replace('\\', '/')