database.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Licensed to the LF AI & Data foundation under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. The ASF licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. package client
  17. import (
  18. "context"
  19. "google.golang.org/grpc"
  20. "github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
  21. "github.com/milvus-io/milvus/pkg/util/merr"
  22. )
  23. func (c *Client) UsingDatabase(ctx context.Context, option UsingDatabaseOption) error {
  24. dbName := option.DbName()
  25. c.usingDatabase(dbName)
  26. return c.connectInternal(ctx)
  27. }
  28. func (c *Client) ListDatabase(ctx context.Context, option ListDatabaseOption, callOptions ...grpc.CallOption) (databaseNames []string, err error) {
  29. req := option.Request()
  30. err = c.callService(func(milvusService milvuspb.MilvusServiceClient) error {
  31. resp, err := milvusService.ListDatabases(ctx, req, callOptions...)
  32. err = merr.CheckRPCCall(resp, err)
  33. if err != nil {
  34. return err
  35. }
  36. databaseNames = resp.GetDbNames()
  37. return nil
  38. })
  39. return databaseNames, err
  40. }
  41. func (c *Client) CreateDatabase(ctx context.Context, option CreateDatabaseOption, callOptions ...grpc.CallOption) error {
  42. req := option.Request()
  43. return c.callService(func(milvusService milvuspb.MilvusServiceClient) error {
  44. resp, err := milvusService.CreateDatabase(ctx, req, callOptions...)
  45. return merr.CheckRPCCall(resp, err)
  46. })
  47. }
  48. func (c *Client) DropDatabase(ctx context.Context, option DropDatabaseOption, callOptions ...grpc.CallOption) error {
  49. req := option.Request()
  50. return c.callService(func(milvusService milvuspb.MilvusServiceClient) error {
  51. resp, err := milvusService.DropDatabase(ctx, req, callOptions...)
  52. return merr.CheckRPCCall(resp, err)
  53. })
  54. }