Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDB ¶
newDB creates/opens a leveldb persistent database at the given path. If no path is given, an in-memory, temporary database is constructed.
func NewMemoryDB ¶
newMemoryDB creates a new in-memory node database without a persistent backend.
Types ¶
type GenericDB ¶
type GenericDB struct {
// contains filtered or unexported fields
}
GenericDB manages a levelDB database
func New ¶
func New(dbVersion int64, path string, logger log.Logger, writeOptions *opt.WriteOptions) (*GenericDB, error)
New will open a new db at the given file path with the given version. If the path is empty, the db will be created in memory. If there is a version mismatch in the existing db, the contents are flushed.
func (*GenericDB) Iterate ¶
Iterate will iterate through each entry in the db whose key has the prefix keyPrefix, and call `onEntry` with the bytes of the key (without the prefix) and the bytes of the value
func (*GenericDB) Upsert ¶
func (gdb *GenericDB) Upsert( entries []GenericEntry, getExistingEntry func(entry GenericEntry) (GenericEntry, error), onUpdatedEntry func(batch *leveldb.Batch, existingEntry GenericEntry, newEntry GenericEntry) error, onNewEntry func(batch *leveldb.Batch, entry GenericEntry) error, ) error
Upsert iterates through each provided entry and determines if the entry is new. If there is an existing entry in the db, `onUpdatedEntry` is called. If there is no existing entry, `onNewEntry` is called. Db content modifications are left to those functions by providing a leveldb Batch that is written after all entries are processed.
type GenericEntry ¶
type GenericEntry interface{}