github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/causetstore/petri/acyclic/structure/structure.go (about)

     1  // Copyright 2020 WHTCORPS INC, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package structure
    15  
    16  import (
    17  	"github.com/whtcorpsinc/BerolinaSQL/terror"
    18  	"github.com/whtcorpsinc/milevadb/ekv"
    19  	allegrosql "github.com/whtcorpsinc/milevadb/errno"
    20  )
    21  
    22  var (
    23  	// ErrInvalidHashKeyFlag used by structure
    24  	ErrInvalidHashKeyFlag = terror.ClassStructure.New(allegrosql.ErrInvalidHashKeyFlag, allegrosql.MyALLEGROSQLErrName[allegrosql.ErrInvalidHashKeyFlag])
    25  	// ErrInvalidListIndex used by structure
    26  	ErrInvalidListIndex = terror.ClassStructure.New(allegrosql.ErrInvalidListIndex, allegrosql.MyALLEGROSQLErrName[allegrosql.ErrInvalidListIndex])
    27  	// ErrInvalidListMetaData used by structure
    28  	ErrInvalidListMetaData = terror.ClassStructure.New(allegrosql.ErrInvalidListMetaData, allegrosql.MyALLEGROSQLErrName[allegrosql.ErrInvalidListMetaData])
    29  	// ErrWriteOnSnapshot used by structure
    30  	ErrWriteOnSnapshot = terror.ClassStructure.New(allegrosql.ErrWriteOnSnapshot, allegrosql.MyALLEGROSQLErrName[allegrosql.ErrWriteOnSnapshot])
    31  )
    32  
    33  // NewStructure creates a TxStructure with Retriever, RetrieverMutator and key prefix.
    34  func NewStructure(reader ekv.Retriever, readWriter ekv.RetrieverMutator, prefix []byte) *TxStructure {
    35  	return &TxStructure{
    36  		reader:     reader,
    37  		readWriter: readWriter,
    38  		prefix:     prefix,
    39  	}
    40  }
    41  
    42  // TxStructure supports some simple data structures like string, hash, list, etc... and
    43  // you can use these in a transaction.
    44  type TxStructure struct {
    45  	reader     ekv.Retriever
    46  	readWriter ekv.RetrieverMutator
    47  	prefix     []byte
    48  }