feat:增加预制问题-保存用户问题为后期加入rag
This commit is contained in:
0
db_util/__init__.py
Normal file
0
db_util/__init__.py
Normal file
68
db_util/db_main.py
Normal file
68
db_util/db_main.py
Normal file
@@ -0,0 +1,68 @@
|
||||
from sqlalchemy import Column, DateTime, String, create_engine, Boolean, Text
|
||||
from sqlalchemy.orm import declarative_base, sessionmaker
|
||||
|
||||
# 申明基类对象
|
||||
Base = declarative_base()
|
||||
from decouple import config
|
||||
|
||||
DB_PATH = config('DB_PATH', default='E://pyptoject//sqlbot_agent//main.sqlite3')
|
||||
|
||||
|
||||
class QuestionFeedBack(Base):
|
||||
# 定义表名
|
||||
__tablename__ = 'db_question_feedback'
|
||||
# 定义字段
|
||||
id = Column(String(255), primary_key=True)
|
||||
create_time = Column(DateTime, nullable=False, )
|
||||
question = Column(String(255), nullable=False)
|
||||
sql = Column(String(500), nullable=False)
|
||||
user_id = Column(String(100), nullable=False, default='1')
|
||||
# 用户意见反馈
|
||||
user_comment = Column(Text, nullable=True)
|
||||
# 用户点赞,点踩
|
||||
user_praise = Column(Boolean, nullable=False, default=False)
|
||||
# 该数据是否被认为梳理过
|
||||
is_process = Column(Boolean, nullable=False, default=False)
|
||||
|
||||
|
||||
class QuestionFeedBack(Base):
|
||||
# 定义表名
|
||||
__tablename__ = 'db_question_feedback'
|
||||
__table_args__ = {'extend_existing': True}
|
||||
# 定义字段
|
||||
id = Column(String(255), primary_key=True)
|
||||
create_time = Column(DateTime, nullable=False, )
|
||||
question = Column(String(255), nullable=False)
|
||||
sql = Column(String(500), nullable=False)
|
||||
user_id = Column(String(100), nullable=False, default='1')
|
||||
# 用户意见反馈
|
||||
user_comment = Column(Text, nullable=True)
|
||||
# 用户点赞,点踩
|
||||
user_praise = Column(Boolean, nullable=False, default=False)
|
||||
# 该数据是否被认为梳理过
|
||||
is_process = Column(Boolean, nullable=False, default=False)
|
||||
|
||||
|
||||
class PredefinedQuestion(Base):
|
||||
# 定义表名,预制问题表
|
||||
__tablename__ = 'db_predefined_question'
|
||||
__table_args__ = {'extend_existing': True}
|
||||
# 定义字段
|
||||
id = Column(String(255), primary_key=True)
|
||||
question = Column(String(255), nullable=False)
|
||||
user_id = Column(String(100), nullable=False, default='1')
|
||||
# 该数据是否被认为梳理过
|
||||
enable = Column(Boolean, nullable=False, default=True)
|
||||
|
||||
def to_dict(self):
|
||||
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
|
||||
|
||||
|
||||
class SqliteSqlalchemy(object):
|
||||
def __init__(self):
|
||||
# 创建sqlite连接引擎
|
||||
engine = create_engine(f'sqlite:///{DB_PATH}', echo=True)
|
||||
# 创建表
|
||||
Base.metadata.create_all(engine, checkfirst=True)
|
||||
# 创建sqlite的session连接对象
|
||||
self.session = sessionmaker(bind=engine)()
|
||||
Reference in New Issue
Block a user