diff --git a/client/database.go b/client/database.go index 8c78d651..d05136fd 100644 --- a/client/database.go +++ b/client/database.go @@ -49,12 +49,17 @@ func (c *GrpcClient) CreateDatabase(ctx context.Context, dbName string, opts ... if c.config.hasFlags(disableDatabase) { return ErrFeatureNotSupported } - req := &milvuspb.CreateDatabaseRequest{ - DbName: dbName, + + opt := &createDatabaseOpt{} + for _, o := range opts { + o(opt) } - for _, opt := range opts { - opt(req) + + req := &milvuspb.CreateDatabaseRequest{ + DbName: dbName, + Properties: entity.MapKvPairs(opt.Properties), } + resp, err := c.Service.CreateDatabase(ctx, req) if err != nil { return err diff --git a/client/options.go b/client/options.go index 0254dd7b..9490fef4 100644 --- a/client/options.go +++ b/client/options.go @@ -307,7 +307,21 @@ type ReleaseCollectionOption func(*milvuspb.ReleaseCollectionRequest) type FlushOption func(*milvuspb.FlushRequest) -type CreateDatabaseOption func(*milvuspb.CreateDatabaseRequest) +type createDatabaseOpt struct { + Base *commonpb.MsgBase + Properties map[string]string +} + +type CreateDatabaseOption func(*createDatabaseOpt) + +func WithDatabaseProperty(key, value string) CreateDatabaseOption { + return func(opt *createDatabaseOpt) { + if opt.Properties == nil { + opt.Properties = make(map[string]string, 0) + } + opt.Properties[key] = value + } +} type DropDatabaseOption func(*milvuspb.DropDatabaseRequest) diff --git a/client/options_msg_base.go b/client/options_msg_base.go index cafc4434..4f14c171 100644 --- a/client/options_msg_base.go +++ b/client/options_msg_base.go @@ -36,8 +36,8 @@ func WithFlushMsgBase(msgBase *commonpb.MsgBase) FlushOption { } func WithCreateDatabaseMsgBase(msgBase *commonpb.MsgBase) CreateDatabaseOption { - return func(req *milvuspb.CreateDatabaseRequest) { - req.Base = msgBase + return func(opt *createDatabaseOpt) { + opt.Base = msgBase } } diff --git a/examples/database/database.go b/examples/database/database.go index da84f505..0f04ac8f 100644 --- a/examples/database/database.go +++ b/examples/database/database.go @@ -20,7 +20,7 @@ func main() { clientDefault := mustConnect(ctx, cfg) defer clientDefault.Close() createCollection(ctx, clientDefault, "col1") - if err := clientDefault.CreateDatabase(ctx, "db1"); err != nil { + if err := clientDefault.CreateDatabase(ctx, "db1", client.WithDatabaseProperty("key1", "value1")); err != nil { log.Fatalf("create db1 failed, %+v", err) } dbs, err := clientDefault.ListDatabases(ctx) diff --git a/go.mod b/go.mod index 980c22af..5989f7f2 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/go-faker/faker/v4 v4.1.0 github.com/golang/protobuf v1.5.2 github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 - github.com/milvus-io/milvus-proto/go-api/v2 v2.4.3 + github.com/milvus-io/milvus-proto/go-api/v2 v2.4.6-0.20240705061601-7a658711dc06 github.com/stretchr/testify v1.8.1 github.com/tidwall/gjson v1.14.4 github.com/x448/float16 v0.8.4 diff --git a/go.sum b/go.sum index 988bf02e..85966c6a 100644 --- a/go.sum +++ b/go.sum @@ -161,6 +161,8 @@ github.com/milvus-io/milvus-proto/go-api/v2 v2.3.4-0.20240430025921-135167be0694 github.com/milvus-io/milvus-proto/go-api/v2 v2.3.4-0.20240430025921-135167be0694/go.mod h1:1OIl0v5PQeNxIJhCvY+K55CBUOYDZevw9g9380u1Wek= github.com/milvus-io/milvus-proto/go-api/v2 v2.4.3 h1:KUSaWVePVlHMIluAXf2qmNffI1CMlGFLLiP+4iy9014= github.com/milvus-io/milvus-proto/go-api/v2 v2.4.3/go.mod h1:1OIl0v5PQeNxIJhCvY+K55CBUOYDZevw9g9380u1Wek= +github.com/milvus-io/milvus-proto/go-api/v2 v2.4.6-0.20240705061601-7a658711dc06 h1:b4ulIU5bNSxScgZ4eNb19Gdr6Xhv5pqaC2SOugFogao= +github.com/milvus-io/milvus-proto/go-api/v2 v2.4.6-0.20240705061601-7a658711dc06/go.mod h1:1OIl0v5PQeNxIJhCvY+K55CBUOYDZevw9g9380u1Wek= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= diff --git a/test/base/milvus_client.go b/test/base/milvus_client.go index e3a41e89..4dda3f34 100644 --- a/test/base/milvus_client.go +++ b/test/base/milvus_client.go @@ -104,9 +104,9 @@ func (mc *MilvusClient) ListDatabases(ctx context.Context) ([]entity.Database, e } // CreateDatabase create database with the given name. -func (mc *MilvusClient) CreateDatabase(ctx context.Context, dbName string) error { +func (mc *MilvusClient) CreateDatabase(ctx context.Context, dbName string, opts ...client.CreateDatabaseOption) error { preRequest("CreateDatabase", ctx, dbName) - err := mc.mClient.CreateDatabase(ctx, dbName) + err := mc.mClient.CreateDatabase(ctx, dbName, opts...) postResponse("CreateDatabase", err) return err }