|
|
|
@ -1,31 +1,30 @@
|
|
|
|
|
import itertools
|
|
|
|
|
import contextlib
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
import itertools
|
|
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
|
from typing import List, Any, Optional
|
|
|
|
|
|
|
|
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
|
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
|
from sqlalchemy import create_engine
|
|
|
|
|
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
|
|
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
|
|
|
|
|
|
from website import settings
|
|
|
|
|
from website.handler import Row
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Row(dict):
|
|
|
|
|
"""A dict that allows for object-like property access syntax."""
|
|
|
|
|
|
|
|
|
|
def __getattr__(self, name):
|
|
|
|
|
try:
|
|
|
|
|
return self[name]
|
|
|
|
|
except KeyError:
|
|
|
|
|
raise AttributeError(name)
|
|
|
|
|
# class Row(dict):
|
|
|
|
|
# """A dict that allows for object-like property access syntax."""
|
|
|
|
|
#
|
|
|
|
|
# def __getattr__(self, name):
|
|
|
|
|
# try:
|
|
|
|
|
# return self[name]
|
|
|
|
|
# except KeyError:
|
|
|
|
|
# raise AttributeError(name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def dict_to_obj(d):
|
|
|
|
|
return type('GenericClass', (object,), d)()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def to_json_list(cursor: Any) -> Optional[List[Row]]:
|
|
|
|
|
column_names = list(cursor.keys())
|
|
|
|
|
result = cursor.fetchall()
|
|
|
|
@ -59,7 +58,9 @@ app_engine = create_engine(
|
|
|
|
|
pool_recycle=int(settings.SQLALCHEMY_POOL_RECYCLE), # 多久时间回收连接
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
Session = sessionmaker(bind=app_engine)
|
|
|
|
|
Session = sessionmaker(bind=app_engine, expire_on_commit=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Base = declarative_base(app_engine)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|