mirror of
https://github.com/LBRYFoundation/lbcd.git
synced 2025-08-30 00:41:26 +00:00
This commit adds a new backend driver which conforms to the btcdb interface to provide a memory only database. This is primarily useful for testing purposes as normal operations require a persistent block storage mechanism.
29 lines
729 B
Go
29 lines
729 B
Go
// Copyright (c) 2013 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 (
|
|
"github.com/conformal/btcdb"
|
|
"github.com/conformal/seelog"
|
|
)
|
|
|
|
var log = seelog.Disabled
|
|
|
|
func init() {
|
|
driver := btcdb.DriverDB{DbType: "memdb", Create: CreateDB, Open: OpenDB}
|
|
btcdb.AddDBDriver(driver)
|
|
}
|
|
|
|
// OpenDB opens an existing database for use.
|
|
func OpenDB(dbpath string) (btcdb.Db, error) {
|
|
// A memory database is not persistent, so let CreateDB handle it.
|
|
return CreateDB(dbpath)
|
|
}
|
|
|
|
// CreateDB creates, initializes, and opens a database for use.
|
|
func CreateDB(dbpath string) (btcdb.Db, error) {
|
|
log = btcdb.GetLog()
|
|
return newMemDb(), nil
|
|
}
|