github.com/amazechain/amc@v0.1.3/internal/amcdb/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 amcdb
    18  
    19  type DBType uint8
    20  
    21  const (
    22  	DBMem = iota
    23  	DBLmdb
    24  	DBUnknown
    25  )
    26  
    27  func (dt DBType) String() string {
    28  	switch dt {
    29  	case DBMem:
    30  		return "memory"
    31  	case DBLmdb:
    32  		return "lmdb"
    33  	default:
    34  		return "unknown db"
    35  	}
    36  }
    37  
    38  func ToDBType(name string) DBType {
    39  	switch name {
    40  	case "memory":
    41  		return DBMem
    42  	case "lmdb":
    43  		return DBLmdb
    44  	default:
    45  		return DBUnknown
    46  	}
    47  }
    48  
    49  //func OpenDB(ctx context.Context, nodeConfig *conf.NodeConfig, config *conf.DatabaseConfig) (ethdb.Database, error) {
    50  //	dType := ToDBType(config.DBType)
    51  //	switch dType {
    52  //	case DBLmdb:
    53  //		return lmdb.NewLMDB(ctx, nodeConfig, config)
    54  //	case DBMem:
    55  //		return memdb.NewMemDB(), nil
    56  //	default:
    57  //		return nil, fmt.Errorf("failed open db, err: invalid db type")
    58  //	}
    59  //}