-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add sqlalchemy support and mongodb support #321
base: main
Are you sure you want to change the base?
Conversation
6e1f29a
to
74f63cb
Compare
…url 3. estimate token uasge in local llm model
… ProgrammingError), use Exception when Table exists in _create_by_api function 2. Fix regrex error in get_db_init_keywords function when password has special character
lazyllm/tools/sql/sql_manager.py
Outdated
if db_type not in self.DB_TYPE_SUPPORTED: | ||
return DBResult(status=DBStatus.FAIL, detail=f"{db_type} not supported") | ||
if db_type in self.DB_DRIVER_MAP: | ||
conn_url = f"{db_type}+{self.DB_DRIVER_MAP[db_type]}://{user}:{password}@{host}:{port}/{db_name}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个url拼完会是mysql+pymysql://{user}:{password}@{host}:{port}/{db_name}
,确认一下是合法的?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的。合法的,已经连接MySQL云数据库测试过。
lazyllm/tools/sql/db_manager.py
Outdated
|
||
@property | ||
def desc(self): | ||
return self._desc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
基类的方法不能使用子类定义的变量
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
lazyllm/tools/sql/mongodb_manager.py
Outdated
if result.status != DBStatus.SUCCESS: | ||
return result | ||
""" | ||
if db_name not in self.client.list_database_names(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要把代码注释起来,这里是什么情况呀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已删除
lazyllm/tools/sql/db_manager.py
Outdated
raise ValueError(db_result.detail) | ||
|
||
@overload | ||
def reset_engine(self, db_type, user, password, host, port, db_name, options_str) -> DBResult: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么要提供一个reset_engine的对外接口?什么场景下会对一个已经创建的SqlManager做重置呀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看起来只有sql这一支使用了这个函数,是不是应该放到sqlmanagerbase中定义
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
之前reset是考虑在前端填写的sql_info_dict 格式有误时,reset是考虑多次尝试设置。
不过目前UI已经改为了生成这个字段,因此reset 其实就没有必要了。
lazyllm/tools/sql/mongodb_manager.py
Outdated
if self.status != DBStatus.SUCCESS: | ||
raise ValueError(self.detail) | ||
|
||
def reset_client(self, user, password, host, port, db_name, collection_name, options_str="") -> DBResult: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同,感觉这个函数没有暴露出去的必要性
lazyllm/tools/sql/db_manager.py
Outdated
result: Union[List, None] = None | ||
|
||
|
||
class DBManager(ABC): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
图中是有forward的,但我没看到基类和MongoDB有实现forward
lazyllm/tools/sql/sql_manager.py
Outdated
super().__init__(db_type, user, password, host, port, db_name, options_str) | ||
|
||
def reset_engine( | ||
self, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
参数统一都放紧凑一点吧,即尽量减少参数的行数,与前后保持风格一致
lazyllm/tools/sql/mongodb_manager.py
Outdated
self._db_type = "mongodb" | ||
self.status = DBStatus.SUCCESS | ||
self.detail = "" | ||
conn_url = f"{self._db_type}://{user}:{password}@{host}:{port}/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
直接赋值给self即可,无需先搞个临时变量
lazyllm/tools/sql/mongodb_manager.py
Outdated
self._collection.delete_one(filter) | ||
|
||
def select(self, query, projection: dict[str, bool] = None, limit: int = None): | ||
if limit is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result = self._collection.find(query, projection)
if limit: result = result.limit(limit)
No description provided.