From be48e5b7b640e466d7baf1acc0014e789eb733f9 Mon Sep 17 00:00:00 2001 From: ryjiang Date: Tue, 11 Jun 2024 16:26:45 +0800 Subject: [PATCH] add describeDatabase api (#323) * support db_name in APIs Signed-off-by: ryjiang * fix build Signed-off-by: ryjiang * add describeDatabase api Signed-off-by: ryjiang --------- Signed-off-by: ryjiang --- milvus/grpc/Database.ts | 40 ++++++++++++++++++++++++++++++++++++++ milvus/types/Database.ts | 13 ++++++++++++- test/grpc/Database.spec.ts | 12 +++++++++++- 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/milvus/grpc/Database.ts b/milvus/grpc/Database.ts index dffc966b..0aa33cc1 100644 --- a/milvus/grpc/Database.ts +++ b/milvus/grpc/Database.ts @@ -4,6 +4,8 @@ import { ListDatabasesRequest, ListDatabasesResponse, DropDatabasesRequest, + DescribeDatabaseRequest, + DescribeDatabaseResponse, ResStatus, promisify, } from '../'; @@ -74,6 +76,44 @@ export class Database extends BaseClient { return promise; } + /** + * Describes a database. + * + * @param {DescribeDatabaseRequest} data - The request parameters. + * @param {string} data.db_name - The name of the database to describe. + * @param {number} [data.timeout] - An optional duration of time in milliseconds to allow for the RPC. If it is set to undefined, the client keeps waiting until the server responds or error occurs. Default is undefined. + * + * @returns {Promise} The response from the server. + * @returns {string} status.error_code - The error code of the operation. + * @returns {string} status.reason - The reason for the error, if any. + * @returns {string} db_name - The name of the database. + * @returns {number} dbID - The ID of the database. + * @returns {number} created_timestamp - The timestamp of when the database was created. + * @returns {KeyValuePair[]} properties - The properties of the database. + * + * @example + * ``` + * const milvusClient = new milvusClient(MILUVS_ADDRESS); + * const res = await milvusClient.describeDatabase({ db_name: 'db_to_describe' }); + * ``` + */ + async describeDatabase( + data: DescribeDatabaseRequest + ): Promise { + // check compatibility + await this.checkCompatibility({ + message: `describeDatabase is not supported on this version of milvus.`, + }); + + const promise = await promisify( + this.channelPool, + 'DescribeDatabase', + data, + data.timeout || this.timeout + ); + return promise; + } + /** * Drops a database. * diff --git a/milvus/types/Database.ts b/milvus/types/Database.ts index e71b2b8b..8468c647 100644 --- a/milvus/types/Database.ts +++ b/milvus/types/Database.ts @@ -1,12 +1,23 @@ -import { GrpcTimeOut, resStatusResponse } from './Common'; +import { GrpcTimeOut, resStatusResponse, KeyValuePair } from './Common'; // base export interface databaseReq extends GrpcTimeOut { db_name: string; // required, database name } + +// request export interface CreateDatabaseRequest extends databaseReq {} export interface DropDatabasesRequest extends databaseReq {} +export interface DescribeDatabaseRequest extends databaseReq {} + +// response export interface ListDatabasesRequest extends GrpcTimeOut {} export interface ListDatabasesResponse extends resStatusResponse { db_names: string[]; // database names } +export interface DescribeDatabaseResponse extends resStatusResponse { + db_name: string; // database name + dbID: number; // database id + created_timestamp: number; // created timestamp + properties: KeyValuePair[]; // properties +} diff --git a/test/grpc/Database.spec.ts b/test/grpc/Database.spec.ts index 591bf985..95302075 100644 --- a/test/grpc/Database.spec.ts +++ b/test/grpc/Database.spec.ts @@ -62,6 +62,14 @@ describe(`Database API`, () => { expect(allDatabases.db_names.length).toBeGreaterThan(1); }); + it(`describe database should be ok`, async () => { + const describe = await milvusClient.describeDatabase({ db_name: DB_NAME }); + expect(describe.db_name).toEqual(DB_NAME); + expect(describe.dbID * 1).toBeGreaterThan(0); + expect(describe.created_timestamp * 1).toBeGreaterThan(0); + expect(describe.properties).toEqual([]); + }); + it(`drop database should be ok`, async () => { const drop = await milvusClient.dropDatabase({ db_name: DB_NAME }); expect(drop.error_code).toEqual(ErrorCode.SUCCESS); @@ -85,7 +93,9 @@ describe(`Database API`, () => { const describeCollectionInDb = await milvusClient.describeCollection({ collection_name: COLLECTION_NAME2, }); - expect(describeCollectionInDb.status.error_code).toEqual(ErrorCode.UnexpectedError); + expect(describeCollectionInDb.status.error_code).toEqual( + ErrorCode.UnexpectedError + ); // create index const createIndex = await milvusClient.createIndex({