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