diff --git a/.gitignore b/.gitignore index 0af027c..1a7bbfd 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ __pycache__/ *.py[cod] *$py.class .vscode +.DS_Store # C extensions *.so diff --git a/milvus_cli/Connection.py b/milvus_cli/Connection.py index d78976e..06dd34f 100644 --- a/milvus_cli/Connection.py +++ b/milvus_cli/Connection.py @@ -3,30 +3,25 @@ from tabulate import tabulate class MilvusConnection(object): - host = "127.0.0.1" - port = 19530 + uri = "127.0.0.1:19530" alias = "default" def connect(self, alias='', - host=None, - port=None, - secure=False, + uri=None, username=None, password=None): self.alias = alias - self.host = host - self.port = port + self.uri = uri trimUsername = None if username is None else username.strip() trimPwd = None if password is None else password.strip() try: res = connections.connect(alias= self.alias, - host=self.host, - port=self.port, + uri=self.uri, user=trimUsername, - password=trimPwd, - secure=secure) + password=trimPwd + ) return res except Exception as e: raise ConnectException(f"Connect to Milvus error!{str(e)}") @@ -42,7 +37,7 @@ def checkConnection(self,alias=None): def showConnection(self, alias=None, showAll=False): tempAlias = alias if alias else self.alias allConnections = connections.list_connections() - + if showAll: return tabulate(allConnections, headers=["Alias"], diff --git a/milvus_cli/Database.py b/milvus_cli/Database.py index f95beab..b995165 100644 --- a/milvus_cli/Database.py +++ b/milvus_cli/Database.py @@ -7,8 +7,8 @@ class Database(): def create_database(self,dbName=None,alias=None): tempAlias = alias if alias else self.alias try: - res = db.create_database(db_name=dbName,using=tempAlias) - print(res) + db.create_database(db_name=dbName,using=tempAlias) + return f"Create database {dbName} successfully!" except Exception as e: raise f"Create database error!{str(e)}" @@ -16,7 +16,6 @@ def list_databases(self,alias=None): tempAlias = alias if alias else self.alias try: res = db.list_database(using=tempAlias) - print('----',res) return res except Exception as e: raise f"List database error!{str(e)}" @@ -24,15 +23,15 @@ def list_databases(self,alias=None): def drop_database(self,dbName=None,alias=None): tempAlias = alias if alias else self.alias try: - res = db.drop_database(db_name=dbName,using=tempAlias) - print(res) + db.drop_database(db_name=dbName,using=tempAlias) + return f"Drop database {dbName} successfully!" except Exception as e: raise f"Drop database error!{str(e)}" def using_database(self,dbName=None,alias=None): tempAlias = alias if alias else self.alias try: - res = db.using_database(db_name=dbName,using=tempAlias) - print(res) + db.using_database(db_name=dbName,using=tempAlias) + return f"Using database {dbName} successfully!" except Exception as e: raise f"Using database error!{str(e)}" \ No newline at end of file diff --git a/milvus_cli/test/test_connection.py b/milvus_cli/test/test_connection.py index fc61946..9498e9d 100644 --- a/milvus_cli/test/test_connection.py +++ b/milvus_cli/test/test_connection.py @@ -8,23 +8,22 @@ sys.path.append(parentdir) from Connection import MilvusConnection -defaultAddress = 'localhost' -defaultPort = 19530 +uri = "http://localhost:19530" tempAlias = "zilliz" milvusConnection = MilvusConnection() class TestConnection(unittest.TestCase): def setUp(self): - milvusConnection.connect(host=defaultAddress,port=defaultPort,alias=tempAlias) - + milvusConnection.connect(uri=uri ,alias=tempAlias) + def tearDown(self): milvusConnection.disconnect(alias=tempAlias) def test_show_connection(self): res = milvusConnection.showConnection(alias=tempAlias) expectRes = tabulate( - [["Address", f'{defaultAddress}:{defaultPort}'], ["User", ''], ["Alias", tempAlias]], + [["Address", f'localhost:19530'], ["User", ''], ["Alias", tempAlias]], tablefmt="pretty", ) self.assertEqual(res, expectRes) diff --git a/milvus_cli/test/test_database.py b/milvus_cli/test/test_database.py index d1d1c0e..b6946ff 100644 --- a/milvus_cli/test/test_database.py +++ b/milvus_cli/test/test_database.py @@ -9,8 +9,7 @@ from Connection import MilvusConnection from Database import Database -defaultAddress = 'localhost' -defaultPort = 19530 +uri = "http://localhost:19530" tempAlias = "zilliz" dbName="test_db" milvusConnection = MilvusConnection() @@ -19,7 +18,7 @@ class TestDatabase(unittest.TestCase): def setUp(self): - milvusConnection.connect(host=defaultAddress,port=defaultPort,alias=tempAlias) + milvusConnection.connect(uri=uri,alias=tempAlias) def tearDown(self): database.drop_database(dbName=dbName,alias=tempAlias)