mirror of
https://github.com/xfgryujk/blivechat.git
synced 2026-08-19 09:43:28 +08:00
升级SQLAlchemy到2.0.19
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
|
||||
import sqlalchemy
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
import models.database
|
||||
|
||||
|
||||
class BilibiliUser(models.database.OrmBase):
|
||||
__tablename__ = 'bilibili_users'
|
||||
uid = sqlalchemy.Column(sqlalchemy.BigInteger, primary_key=True) # 创建表后最好手动改成unsigned
|
||||
avatar_url = sqlalchemy.Column(sqlalchemy.String(100))
|
||||
update_time = sqlalchemy.Column(sqlalchemy.DateTime)
|
||||
uid: Mapped[int] = mapped_column(sqlalchemy.BigInteger, primary_key=True) # 创建表后最好手动改成unsigned
|
||||
avatar_url: Mapped[str] = mapped_column(sqlalchemy.String(100))
|
||||
update_time: Mapped[datetime.datetime]
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from typing import *
|
||||
|
||||
import sqlalchemy.ext.declarative
|
||||
import sqlalchemy.orm
|
||||
|
||||
import config
|
||||
|
||||
OrmBase = sqlalchemy.ext.declarative.declarative_base()
|
||||
_engine = None
|
||||
_DbSession: Optional[Type[sqlalchemy.orm.Session]] = None
|
||||
_engine: Optional[sqlalchemy.Engine] = None
|
||||
|
||||
|
||||
class OrmBase(sqlalchemy.orm.DeclarativeBase):
|
||||
pass
|
||||
|
||||
|
||||
def init(_debug):
|
||||
cfg = config.get_config()
|
||||
global _engine, _DbSession
|
||||
global _engine
|
||||
# engine = sqlalchemy.create_engine(cfg.database_url, echo=debug)
|
||||
_engine = sqlalchemy.create_engine(cfg.database_url)
|
||||
_DbSession = sqlalchemy.orm.sessionmaker(bind=_engine)
|
||||
|
||||
OrmBase.metadata.create_all(_engine)
|
||||
|
||||
|
||||
def get_session():
|
||||
return _DbSession()
|
||||
def get_session() -> sqlalchemy.orm.Session:
|
||||
return sqlalchemy.orm.Session(_engine)
|
||||
|
||||
Reference in New Issue
Block a user