mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-09 23:36:02 +00:00
feat: 用户账户系统
This commit is contained in:
0
pkg/persistence/entities/__init__.py
Normal file
0
pkg/persistence/entities/__init__.py
Normal file
5
pkg/persistence/entities/base.py
Normal file
5
pkg/persistence/entities/base.py
Normal file
@@ -0,0 +1,5 @@
|
||||
import sqlalchemy.orm
|
||||
|
||||
|
||||
class Base(sqlalchemy.orm.DeclarativeBase):
|
||||
pass
|
||||
11
pkg/persistence/entities/user.py
Normal file
11
pkg/persistence/entities/user.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import sqlalchemy
|
||||
|
||||
from .base import Base
|
||||
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = 'users'
|
||||
|
||||
id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
|
||||
user = sqlalchemy.Column(sqlalchemy.String(255), nullable=False)
|
||||
password = sqlalchemy.Column(sqlalchemy.String(255), nullable=False)
|
||||
@@ -7,6 +7,7 @@ import sqlalchemy.ext.asyncio as sqlalchemy_asyncio
|
||||
import sqlalchemy
|
||||
|
||||
from . import database
|
||||
from .entities import user, base
|
||||
from ..core import app
|
||||
from .databases import sqlite
|
||||
|
||||
@@ -23,7 +24,7 @@ class PersistenceManager:
|
||||
|
||||
def __init__(self, ap: app.Application):
|
||||
self.ap = ap
|
||||
self.meta = sqlalchemy.MetaData()
|
||||
self.meta = base.Base.metadata
|
||||
|
||||
async def initialize(self):
|
||||
|
||||
@@ -46,10 +47,11 @@ class PersistenceManager:
|
||||
self,
|
||||
*args,
|
||||
**kwargs
|
||||
):
|
||||
) -> sqlalchemy.engine.cursor.CursorResult:
|
||||
async with self.get_db_engine().connect() as conn:
|
||||
await conn.execute(*args, **kwargs)
|
||||
result = await conn.execute(*args, **kwargs)
|
||||
await conn.commit()
|
||||
return result
|
||||
|
||||
def get_db_engine(self) -> sqlalchemy_asyncio.AsyncEngine:
|
||||
return self.db.get_engine()
|
||||
|
||||
Reference in New Issue
Block a user