github.com/weaviate/weaviate@v1.24.6/usecases/classification/transactions.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package classification
    13  
    14  import (
    15  	"encoding/json"
    16  
    17  	"github.com/pkg/errors"
    18  	"github.com/weaviate/weaviate/entities/models"
    19  	"github.com/weaviate/weaviate/usecases/cluster"
    20  )
    21  
    22  const TransactionPut cluster.TransactionType = "put_single"
    23  
    24  type TransactionPutPayload struct {
    25  	Classification models.Classification `json:"classification"`
    26  }
    27  
    28  func UnmarshalTransaction(txType cluster.TransactionType,
    29  	payload json.RawMessage,
    30  ) (interface{}, error) {
    31  	switch txType {
    32  	case TransactionPut:
    33  		return unmarshalPut(payload)
    34  
    35  	default:
    36  		return nil, errors.Errorf("unrecognized schema transaction type %q", txType)
    37  
    38  	}
    39  }
    40  
    41  func unmarshalPut(payload json.RawMessage) (interface{}, error) {
    42  	var pl TransactionPutPayload
    43  	if err := json.Unmarshal(payload, &pl); err != nil {
    44  		return nil, err
    45  	}
    46  
    47  	return pl, nil
    48  }