github.com/amazechain/amc@v0.1.3/common/db/database.go (about)

     1  // Copyright 2022 The AmazeChain Authors
     2  // This file is part of the AmazeChain library.
     3  //
     4  // The AmazeChain library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The AmazeChain library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the AmazeChain library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package db
    18  
    19  type IDBReader interface {
    20  	Get(key []byte) (value []byte, err error)
    21  	Gets(key []byte, count uint) (keys [][]byte, value [][]byte, err error)
    22  	GetIterator(key []byte) (iterator IIterator, err error)
    23  }
    24  
    25  type IDBWriter interface {
    26  	Put(key []byte, value []byte) (err error)
    27  	Puts(keys [][]byte, values [][]byte) (err error)
    28  	Delete(key []byte) (err error)
    29  	Drop() (err error)
    30  }
    31  
    32  /*
    33  	IIterator mdbx must close
    34  */
    35  type IIterator interface {
    36  	Next() (err error)
    37  	Prev() (err error)
    38  	Key() (key []byte, err error)
    39  	Value() (value []byte, err error)
    40  	Close()
    41  }
    42  
    43  type IDBReaderWriter interface {
    44  	IDBReader
    45  	IDBWriter
    46  }
    47  
    48  type IDatabaseReader interface {
    49  	IDBReader
    50  }
    51  
    52  type IDatabaseWriter interface {
    53  	IDBWriter
    54  }
    55  
    56  type IDatabaseWriterReader interface {
    57  	IDBReaderWriter
    58  }
    59  
    60  type IDatabase interface {
    61  	OpenReader(dbName string) (reader IDatabaseReader, err error)
    62  	OpenWriter(dbName string) (writer IDatabaseWriter, err error)
    63  	Open(dbName string) (rw IDatabaseWriterReader, err error)
    64  	Snapshot() (ISnapshot, error)
    65  	Close() (err error)
    66  }
    67  
    68  type ISnapshot interface {
    69  	Put(dbName string, key []byte, value []byte) (err error)
    70  	Get(dbName string, key []byte) (value []byte, err error)
    71  	Commit() error
    72  	Rollback()
    73  }