d574a3af6d
This commit contains the entire btcdb repository along with several changes needed to move all of the files into the database directory in order to prepare it for merging. This does NOT update btcd or any of the other packages to use the new location as that will be done separately. - All import paths in the old btcdb test files have been changed to the new location - All references to btcdb as the package name have been chagned to database - The coveralls badge has been removed since it unfortunately doesn't support coverage of sub-packages This is ongoing work toward #214.
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
// Copyright (c) 2013-2014 Conformal Systems LLC.
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package memdb
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/btcsuite/btcd/database"
|
|
"github.com/btcsuite/btclog"
|
|
)
|
|
|
|
var log = btclog.Disabled
|
|
|
|
func init() {
|
|
driver := database.DriverDB{DbType: "memdb", CreateDB: CreateDB, OpenDB: OpenDB}
|
|
database.AddDBDriver(driver)
|
|
}
|
|
|
|
// parseArgs parses the arguments from the database package Open/Create methods.
|
|
func parseArgs(funcName string, args ...interface{}) error {
|
|
if len(args) != 0 {
|
|
return fmt.Errorf("memdb.%s does not accept any arguments",
|
|
funcName)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// OpenDB opens an existing database for use.
|
|
func OpenDB(args ...interface{}) (database.Db, error) {
|
|
if err := parseArgs("OpenDB", args...); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// A memory database is not persistent, so let CreateDB handle it.
|
|
return CreateDB()
|
|
}
|
|
|
|
// CreateDB creates, initializes, and opens a database for use.
|
|
func CreateDB(args ...interface{}) (database.Db, error) {
|
|
if err := parseArgs("CreateDB", args...); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
log = database.GetLog()
|
|
return newMemDb(), nil
|
|
}
|