加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
database.py 1.27 KB
一键复制 编辑 原始数据 按行查看 历史
lan 提交于 2023-01-07 12:09 . update:encoding convert
import datetime
from sqlalchemy import Boolean, Column, Integer, String, DateTime, JSON, Text
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.asyncio import create_async_engine
from sqlalchemy.ext.asyncio.session import AsyncSession
import settings
engine = create_async_engine(settings.DATABASE_URL)
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
class Values(Base):
__tablename__ = 'values'
id = Column(Integer, primary_key=True, index=True)
key = Column(String, unique=True)
value = Column(JSON)
class Codes(Base):
__tablename__ = "codes"
id = Column(Integer, primary_key=True, index=True)
code = Column(String(10), unique=True, index=True)
key = Column(String(30), unique=True, index=True)
name = Column(String(500))
size = Column(Integer)
type = Column(String(20))
text = Column(Text)
used = Column(Boolean, default=False)
count = Column(Integer, default=-1)
use_time = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now)
exp_time = Column(DateTime, nullable=True)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化