github.com/milvus-io/milvus-sdk-go/v2@v2.4.1/client/alias.go (about)

     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  
    17  package client
    18  
    19  import (
    20  	"context"
    21  
    22  	"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
    23  )
    24  
    25  // CreateAlias creates an alias for collection
    26  func (c *GrpcClient) CreateAlias(ctx context.Context, collName string, alias string) error {
    27  	if c.Service == nil {
    28  		return ErrClientNotReady
    29  	}
    30  
    31  	req := &milvuspb.CreateAliasRequest{
    32  		DbName:         "", // reserved
    33  		CollectionName: collName,
    34  		Alias:          alias,
    35  	}
    36  
    37  	resp, err := c.Service.CreateAlias(ctx, req)
    38  	if err != nil {
    39  		return err
    40  	}
    41  	err = handleRespStatus(resp)
    42  	if err != nil {
    43  		return err
    44  	}
    45  	return nil
    46  }
    47  
    48  // DropAlias drops the specified Alias
    49  func (c *GrpcClient) DropAlias(ctx context.Context, alias string) error {
    50  	if c.Service == nil {
    51  		return ErrClientNotReady
    52  	}
    53  
    54  	req := &milvuspb.DropAliasRequest{
    55  		DbName: "", // reserved
    56  		Alias:  alias,
    57  	}
    58  
    59  	resp, err := c.Service.DropAlias(ctx, req)
    60  	if err != nil {
    61  		return err
    62  	}
    63  	err = handleRespStatus(resp)
    64  	if err != nil {
    65  		return err
    66  	}
    67  	return nil
    68  }
    69  
    70  // AlterAlias changes collection alias to provided alias
    71  func (c *GrpcClient) AlterAlias(ctx context.Context, collName string, alias string) error {
    72  	if c.Service == nil {
    73  		return ErrClientNotReady
    74  	}
    75  
    76  	req := &milvuspb.AlterAliasRequest{
    77  		DbName:         "", // reserved
    78  		CollectionName: collName,
    79  		Alias:          alias,
    80  	}
    81  
    82  	resp, err := c.Service.AlterAlias(ctx, req)
    83  	if err != nil {
    84  		return err
    85  	}
    86  	err = handleRespStatus(resp)
    87  	if err != nil {
    88  		return err
    89  	}
    90  	return nil
    91  }