From 830c6f20af9c7ae5da2d054bcfed8bb701475545 Mon Sep 17 00:00:00 2001 From: wolin_huajiaxuan123 Date: Sat, 19 Sep 2026 14:47:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=E3=80=8C/=E3=80=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- database.py | 18 ++++++++++++++++++ main.py | 13 +++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 database.py create mode 100644 main.py diff --git a/database.py b/database.py new file mode 100644 index 0000000..e9646ca --- /dev/null +++ b/database.py @@ -0,0 +1,18 @@ +from sqlalchemy import * +from sqlalchemy.orm import declarative_base,sessionmaker + +db_url = "mysql+pymysql://root:123456@127.0.0.1:3306/ai0824?charset=utf8mb4" +engine = create_engine(db_url) + +Base = declarative_base() +Session = sessionmaker(bind=engine + ,autoflush=False + ,autocommit = False + ) + +def get_db(): + db = Session() + try: + yield db + finally: + db.close() diff --git a/main.py b/main.py new file mode 100644 index 0000000..e93eacc --- /dev/null +++ b/main.py @@ -0,0 +1,13 @@ +from fastapi import FastAPI +from day24.api.order_api import order_api + +app = FastAPI() + +app.include_router(order_api, tags=['订单接口'], prefix='/orders') + +if __name__ == '__main__': + import uvicorn + + uvicorn.run("main:app", host='127.0.0.1', port=12345) + +