2021-04-19 21:58:05 +00:00
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
2021-07-29 11:53:13 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/kv"
|
|
|
|
"github.com/ledgerwatch/erigon-lib/kv/mdbx"
|
2021-07-29 10:23:23 +00:00
|
|
|
"github.com/ledgerwatch/log/v3"
|
2021-04-19 21:58:05 +00:00
|
|
|
)
|
|
|
|
|
2022-10-11 15:49:38 +00:00
|
|
|
func OpenDatabase(path string, logger log.Logger, inMem bool, readonly bool) kv.RwDB {
|
2022-01-22 05:53:25 +00:00
|
|
|
opts := mdbx.NewMDBX(logger).Label(kv.ConsensusDB)
|
2022-07-31 20:54:23 +00:00
|
|
|
if readonly {
|
|
|
|
opts = opts.Readonly()
|
|
|
|
}
|
2022-10-11 15:49:38 +00:00
|
|
|
if inMem {
|
|
|
|
opts = opts.InMem("")
|
2021-04-19 21:58:05 +00:00
|
|
|
} else {
|
|
|
|
opts = opts.Path(path)
|
|
|
|
}
|
|
|
|
|
|
|
|
return opts.MustOpen()
|
|
|
|
}
|