Compare commits

..
3 Commits
Author SHA1 Message Date
lan-air bec3eb2ea1 完善 aiosqlite 异步数据库驱动 2022-12-11 18:15:54 +08:00
lan-air ae7aa63e2a 完善 aiosqlite 异步数据库驱动 2022-12-11 18:14:41 +08:00
lan-air b999073da4 完善 aiosqlite 异步数据库驱动 2022-12-11 18:03:46 +08:00
4 changed files with 16 additions and 4 deletions

No files matched your search

+2 -2
View File
@@ -1,13 +1,13 @@
FROM python:3.9.5
LABEL author="Lan"
LABEL email="vast@tom.com"
LABEL version="1.0"
LABEL version="1.4.2"
COPY . /app
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo 'Asia/Shanghai' >/etc/timezone
WORKDIR /app
RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/
RUN pip install -r requirements.txt
EXPOSE 12345
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "12345"]
+6
View File
@@ -1,3 +1,4 @@
import asyncio
import datetime
from sqlalchemy import Boolean, Column, Integer, String, DateTime
@@ -10,6 +11,11 @@ engine = create_async_engine("sqlite+aiosqlite:///database.db")
Base = declarative_base()
async def init_models():
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
async def get_session():
async with AsyncSession(engine, expire_on_commit=False) as s:
yield s
+7 -1
View File
@@ -11,13 +11,19 @@ from starlette.staticfiles import StaticFiles
from sqlalchemy import or_, select, update, delete
from sqlalchemy.ext.asyncio.session import AsyncSession
from database import get_session, Codes
from database import get_session, Codes, init_models
app = FastAPI()
if not os.path.exists('./static'):
os.makedirs('./static')
app.mount("/static", StaticFiles(directory="static"), name="static")
@app.on_event('startup')
async def startup():
await init_models()
############################################
# 需要修改的参数
# 允许错误次数
+1 -1
View File
@@ -10,7 +10,7 @@
<meta name="description" content="{{description}}"/>
<meta name="keywords" content="{{keywords}}"/>
<meta name="generator" content="FileCodeBox"/>
<meta name="template" content="Lan-V1.4.1"/>
<meta name="template" content="Lan-V1.4.2"/>
<style>
.qu .el-button {
width: 100px;