Skip to content

Commit

Permalink
support the properties param in the create database api
Browse files Browse the repository at this point in the history
Signed-off-by: SimFG <1142838399@qq.com>
  • Loading branch information
SimFG committed Nov 25, 2024
1 parent 1f009df commit c094651
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
5 changes: 4 additions & 1 deletion milvus/grpc/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion milvus/types/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
31 changes: 30 additions & 1 deletion test/grpc/Database.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MilvusClient, ErrorCode, DEFAULT_DB } from '../../milvus';
import { MilvusClient, ErrorCode, DEFAULT_DB, formatKeyValueData } from '../../milvus';
import {
IP,
genCollectionParams,
Expand All @@ -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();

Expand Down Expand Up @@ -272,6 +273,34 @@ 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,
});

console.dir(describe, { depth: null });
expect(
Number(
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();

Expand Down

0 comments on commit c094651

Please sign in to comment.