Skip to content
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

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

SuperEver
Copy link
Contributor

No description provided.

@SuperEver SuperEver force-pushed the sql/support_sqlalchemy branch from 6e1f29a to 74f63cb Compare October 24, 2024 10:44
lazyllm/module/module.py Outdated Show resolved Hide resolved
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}"
Copy link
Contributor

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},确认一下是合法的?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的。合法的,已经连接MySQL云数据库测试过。


@property
def desc(self):
return self._desc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

基类的方法不能使用子类定义的变量

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DONE

lazyllm/tools/sql/db_manager.py Show resolved Hide resolved
lazyllm/tools/sql/db_manager.py Outdated Show resolved Hide resolved
lazyllm/tools/sql/sql_manager.py Outdated Show resolved Hide resolved
lazyllm/tools/sql/__init__.py Show resolved Hide resolved
if result.status != DBStatus.SUCCESS:
return result
"""
if db_name not in self.client.list_database_names():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要把代码注释起来,这里是什么情况呀

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已删除

raise ValueError(db_result.detail)

@overload
def reset_engine(self, db_type, user, password, host, port, db_name, options_str) -> DBResult:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么要提供一个reset_engine的对外接口?什么场景下会对一个已经创建的SqlManager做重置呀

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看起来只有sql这一支使用了这个函数,是不是应该放到sqlmanagerbase中定义

Copy link
Contributor Author

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/db_manager.py Outdated Show resolved Hide resolved
if self.status != DBStatus.SUCCESS:
raise ValueError(self.detail)

def reset_client(self, user, password, host, port, db_name, collection_name, options_str="") -> DBResult:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同,感觉这个函数没有暴露出去的必要性

result: Union[List, None] = None


class DBManager(ABC):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

图中是有forward的,但我没看到基类和MongoDB有实现forward

super().__init__(db_type, user, password, host, port, db_name, options_str)

def reset_engine(
self,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

参数统一都放紧凑一点吧,即尽量减少参数的行数,与前后保持风格一致

self._db_type = "mongodb"
self.status = DBStatus.SUCCESS
self.detail = ""
conn_url = f"{self._db_type}://{user}:{password}@{host}:{port}/"
Copy link
Contributor

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 Show resolved Hide resolved
self._collection.delete_one(filter)

def select(self, query, projection: dict[str, bool] = None, limit: int = None):
if limit is None:
Copy link
Contributor

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)

lazyllm/tools/sql/mongodb_manager.py Outdated Show resolved Hide resolved
lazyllm/tools/sql/sql_manager.py Outdated Show resolved Hide resolved
lazyllm/tools/sql/sql_manager.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants