github.com/vescale/zgraph@v0.0.0-20230410094002-959c02d50f95/internal/structure/structure.go (about)

     1  // Copyright 2022 zGraph Authors. All rights reserved.
     2  //
     3  // Copyright 2015 PingCAP, Inc.
     4  //
     5  // Licensed under the Apache License, Version 2.0 (the "License");
     6  // you may not use this file except in compliance with the License.
     7  // 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 structure
    18  
    19  import (
    20  	"github.com/pingcap/errors"
    21  	"github.com/vescale/zgraph/storage/kv"
    22  )
    23  
    24  var (
    25  	ErrWriteOnSnapshot     = errors.New("write on snapshot")
    26  	ErrInvalidListIndex    = errors.New("invalid list index")
    27  	ErrInvalidListMetaData = errors.New("invalid list metadata")
    28  	ErrInvalidHashKeyFlag  = errors.New("invalid hash key flash")
    29  )
    30  
    31  // NewStructure creates a TxStructure with Retriever, RetrieverMutator and key prefix.
    32  func NewStructure(reader kv.Retriever, readWriter kv.RetrieverMutator, prefix []byte) *TxStructure {
    33  	return &TxStructure{
    34  		reader:     reader,
    35  		readWriter: readWriter,
    36  		prefix:     prefix,
    37  	}
    38  }
    39  
    40  // TxStructure supports some simple data structures like string, hash, list, etc... and
    41  // you can use these in a transaction.
    42  type TxStructure struct {
    43  	reader     kv.Retriever
    44  	readWriter kv.RetrieverMutator
    45  	prefix     []byte
    46  }