From ecd16c965192ac0e976cb4ba82de63f7feb37194 Mon Sep 17 00:00:00 2001 From: SimFG <1142838399@qq.com> Date: Mon, 25 Nov 2024 16:07:38 +0800 Subject: [PATCH] support the properties param in the create database api (#379) Signed-off-by: SimFG <1142838399@qq.com> --- milvus/grpc/Database.ts | 5 ++++- milvus/types/Database.ts | 4 +++- test/grpc/Database.spec.ts | 30 +++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/milvus/grpc/Database.ts b/milvus/grpc/Database.ts index 11a23557..f9faea22 100644 --- a/milvus/grpc/Database.ts +++ b/milvus/grpc/Database.ts @@ -40,7 +40,10 @@ export class Database extends BaseClient { const promise = await promisify( this.channelPool, 'CreateDatabase', - data, + { + db_name: data.db_name, + properties: parseToKeyValue(data.properties), + }, data.timeout || this.timeout ); return promise; diff --git a/milvus/types/Database.ts b/milvus/types/Database.ts index 87753eb9..87cd333b 100644 --- a/milvus/types/Database.ts +++ b/milvus/types/Database.ts @@ -7,7 +7,9 @@ export interface databaseReq extends GrpcTimeOut { } // request -export interface CreateDatabaseRequest extends databaseReq {} +export interface CreateDatabaseRequest extends databaseReq { + properties?: Properties; // optional, properties +} export interface DropDatabasesRequest extends databaseReq {} export interface DescribeDatabaseRequest extends databaseReq {} diff --git a/test/grpc/Database.spec.ts b/test/grpc/Database.spec.ts index 73024419..bbc37123 100644 --- a/test/grpc/Database.spec.ts +++ b/test/grpc/Database.spec.ts @@ -1,4 +1,4 @@ -import { MilvusClient, ErrorCode, DEFAULT_DB } from '../../milvus'; +import { MilvusClient, ErrorCode, DEFAULT_DB, formatKeyValueData } from '../../milvus'; import { IP, genCollectionParams, @@ -10,6 +10,7 @@ let milvusClient = new MilvusClient({ address: IP, logLevel: 'info' }); const DEFAULT = 'default'; const DB_NAME = GENERATE_NAME('database'); const DB_NAME2 = GENERATE_NAME('database'); +const DB_WITH_PROPERTY = GENERATE_NAME(); const COLLECTION_NAME = GENERATE_NAME(); const COLLECTION_NAME2 = GENERATE_NAME(); @@ -272,6 +273,33 @@ describe(`Database API`, () => { ]); }); + it(`create db with property set should be successful`, async () => { + const res = await milvusClient.createDatabase({ + db_name: DB_WITH_PROPERTY, + properties: { + 'replicate.id': "local-mac", + }, + }); + expect(res.error_code).toEqual(ErrorCode.SUCCESS); + + const describe = await milvusClient.describeDatabase({ + db_name: DB_WITH_PROPERTY, + }); + + expect( + String( + formatKeyValueData(describe.properties, ['replicate.id'])[ + 'replicate.id' + ] + ) + ).toEqual("local-mac"); + + // drop collection + await milvusClient.dropDatabase({ + db_name: DB_WITH_PROPERTY, + }); + }); + // it(`drop database should be ok`, async () => { // const all = await milvusClient.listDatabases();