diff --git a/milvus/types/Collection.ts b/milvus/types/Collection.ts index a59d173b..dd8b2094 100644 --- a/milvus/types/Collection.ts +++ b/milvus/types/Collection.ts @@ -183,6 +183,7 @@ export interface DescribeCollectionResponse extends TimeStamp { status: ResStatus; schema: CollectionSchema; collectionID: string; + collection_name: string; consistency_level: string; aliases: string[]; virtual_channel_names: string[]; // not useful for now diff --git a/milvus/types/Common.ts b/milvus/types/Common.ts index 2f994939..05f8a7db 100644 --- a/milvus/types/Common.ts +++ b/milvus/types/Common.ts @@ -62,6 +62,7 @@ export type keyValueObj = Record; export interface collectionNameReq extends GrpcTimeOut { collection_name: string; // required, collection name + db_name?: string; } export interface partitionNameReq extends collectionNameReq { diff --git a/milvus/types/Data.ts b/milvus/types/Data.ts index 1f771873..b731ef3d 100644 --- a/milvus/types/Data.ts +++ b/milvus/types/Data.ts @@ -88,6 +88,7 @@ export interface Field { export interface FlushReq extends GrpcTimeOut { collection_names: string[]; // collection names + db_name?: string; // database name } export interface CountReq extends collectionNameReq { diff --git a/milvus/types/Resource.ts b/milvus/types/Resource.ts index 6dc2e19a..a7e86bb7 100644 --- a/milvus/types/Resource.ts +++ b/milvus/types/Resource.ts @@ -1,4 +1,4 @@ -import { GrpcTimeOut, resStatusResponse } from './Common'; +import { GrpcTimeOut, resStatusResponse, collectionNameReq } from './Common'; type ResourceGroupConfig = { requests?: { node_num: number }; // requests node num in resource group, if node num is less than requests.nodeNum, it will be transfer from other resource group. @@ -36,10 +36,9 @@ export interface TransferNodeReq extends GrpcTimeOut { num_node: number; // required, number of nodes } -export interface TransferReplicaReq extends GrpcTimeOut { +export interface TransferReplicaReq extends collectionNameReq { source_resource_group: string; // required, source resource group target_resource_group: string; // required, target resource group - collection_name: string; // required, collection name num_replica: number; // required, number of replica } diff --git a/test/grpc/Database.spec.ts b/test/grpc/Database.spec.ts index c62f16b1..591bf985 100644 --- a/test/grpc/Database.spec.ts +++ b/test/grpc/Database.spec.ts @@ -3,9 +3,21 @@ import { IP, genCollectionParams, GENERATE_NAME } from '../tools'; let milvusClient = new MilvusClient({ address: IP }); const DB_NAME = GENERATE_NAME('database'); +const DB_NAME2 = GENERATE_NAME('database'); const COLLECTION_NAME = GENERATE_NAME(); +const COLLECTION_NAME2 = GENERATE_NAME(); describe(`Database API`, () => { + beforeAll(async () => { + await milvusClient.createDatabase({ + db_name: DB_NAME2, + }); + }); + afterAll(async () => { + // drop another db + await milvusClient.dropDatabase({ db_name: DB_NAME2 }); + }); + it(`create database should be ok`, async () => { await milvusClient.use({ db_name: DEFAULT_DB }); @@ -55,6 +67,49 @@ describe(`Database API`, () => { expect(drop.error_code).toEqual(ErrorCode.SUCCESS); }); + it(`using db_name in API should be ok`, async () => { + // create collection on another db + const createCollection = await milvusClient.createCollection({ + ...genCollectionParams({ collectionName: COLLECTION_NAME2, dim: [4] }), + db_name: DB_NAME2, + }); + expect(createCollection.error_code).toEqual(ErrorCode.SUCCESS); + + // describe collection + const describeCollection = await milvusClient.describeCollection({ + collection_name: COLLECTION_NAME2, + db_name: DB_NAME2, + }); + expect(describeCollection.collection_name).toEqual(COLLECTION_NAME2); + + const describeCollectionInDb = await milvusClient.describeCollection({ + collection_name: COLLECTION_NAME2, + }); + expect(describeCollectionInDb.status.error_code).toEqual(ErrorCode.UnexpectedError); + + // create index + const createIndex = await milvusClient.createIndex({ + collection_name: COLLECTION_NAME2, + db_name: DB_NAME2, + field_name: 'vector', + }); + expect(createIndex.error_code).toEqual(ErrorCode.SUCCESS); + + // load collection + const loadCollection = await milvusClient.loadCollection({ + collection_name: COLLECTION_NAME2, + db_name: DB_NAME2, + }); + expect(loadCollection.error_code).toEqual(ErrorCode.SUCCESS); + + // drop collection + const dropCollections = await milvusClient.dropCollection({ + collection_name: COLLECTION_NAME2, + db_name: DB_NAME2, + }); + expect(dropCollections.error_code).toEqual(ErrorCode.SUCCESS); + }); + // it(`drop database should be ok`, async () => { // const all = await milvusClient.listDatabases(); diff --git a/test/utils/Format.spec.ts b/test/utils/Format.spec.ts index c4a9eb7a..b0d086cc 100644 --- a/test/utils/Format.spec.ts +++ b/test/utils/Format.spec.ts @@ -402,6 +402,7 @@ describe('utils/format', () => { created_utc_timestamp: '1683515258531', consistency_level: 'Bounded', num_partitions: '0', + collection_name: 'test', db_name: '', };