Skip to content

Commit

Permalink
add describeDatabase api (#323)
Browse files Browse the repository at this point in the history
* support db_name in APIs

Signed-off-by: ryjiang <[email protected]>

* fix build

Signed-off-by: ryjiang <[email protected]>

* add describeDatabase api

Signed-off-by: ryjiang <[email protected]>

---------

Signed-off-by: ryjiang <[email protected]>
  • Loading branch information
shanghaikid authored Jun 11, 2024
1 parent 8889b0d commit be48e5b
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
40 changes: 40 additions & 0 deletions milvus/grpc/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
ListDatabasesRequest,
ListDatabasesResponse,
DropDatabasesRequest,
DescribeDatabaseRequest,
DescribeDatabaseResponse,
ResStatus,
promisify,
} from '../';
Expand Down Expand Up @@ -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<DescribeDatabaseResponse>} 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<DescribeDatabaseResponse> {
// 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.
*
Expand Down
13 changes: 12 additions & 1 deletion milvus/types/Database.ts
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 11 additions & 1 deletion test/grpc/Database.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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({
Expand Down

0 comments on commit be48e5b

Please sign in to comment.