mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-03 17:44:29 +00:00
32 lines
640 B
Go
32 lines
640 B
Go
|
package mdbx
|
||
|
|
||
|
import (
|
||
|
"github.com/ledgerwatch/erigon-lib/kv"
|
||
|
"github.com/ledgerwatch/erigon-lib/log"
|
||
|
mdbxbind "github.com/torquem-ch/mdbx-go/mdbx"
|
||
|
)
|
||
|
|
||
|
func MustOpen(path string) kv.RwDB {
|
||
|
db, err := Open(path, log.New(), false)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return db
|
||
|
}
|
||
|
|
||
|
// Open - main method to open database.
|
||
|
func Open(path string, logger log.Logger, readOnly bool) (kv.RwDB, error) {
|
||
|
var db kv.RwDB
|
||
|
var err error
|
||
|
opts := NewMDBX(logger).Path(path)
|
||
|
if readOnly {
|
||
|
opts = opts.Flags(func(flags uint) uint { return flags | mdbxbind.Readonly })
|
||
|
}
|
||
|
db, err = opts.Open()
|
||
|
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return db, nil
|
||
|
}
|