Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/database/logging_message.py
2021-08-25 23:15:20 +08:00

36 lines
895 B
Python

from sqlalchemy import create_engine, Column, String, Text, Integer
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
DB_LINK = 'sqlite:///database/msg.db'
class MSG(Base):
__tablename__ = "msg"
id = Column(Integer, primary_key=True)
targetId = Column(String(512))
command = Column(Text)
message = Column(Text)
class MSGDBSession:
def __init__(self):
self.engine = engine = create_engine(DB_LINK)
Base.metadata.create_all(bind=engine, checkfirst=True)
self.Session = sessionmaker()
self.Session.configure(bind=self.engine)
@property
def session(self):
return self.Session()
session = MSGDBSession().session
def LoggerMSG(userid, command, msg):
session.add_all([MSG(targetId=userid, command=command, message=msg)])
session.commit()