Skip to content

Commit

Permalink
fix: actually use given DB connection pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
tauraamui committed Jul 11, 2023
1 parent 573d264 commit fb89ddc
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions kvdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ type KVDB struct {
}

func NewKVDB(db *badger.DB) (KVDB, error) {
return newKVDB(false)
return newKVDB(db)
}

func NewMemKVDB() (KVDB, error) {
return newKVDB(true)
return newKVDB(nil)
}

func newKVDB(inMemory bool) (KVDB, error) {
db, err := badger.Open(badger.DefaultOptions("").WithLogger(nil).WithInMemory(inMemory))
if err != nil {
return KVDB{}, err
func newKVDB(db *badger.DB) (KVDB, error) {
if db == nil {
db, err := badger.Open(badger.DefaultOptions("").WithLogger(nil).WithInMemory(true))
if err != nil {
return KVDB{}, err
}
return KVDB{conn: db}, nil
}

return KVDB{conn: db}, nil
Expand Down

0 comments on commit fb89ddc

Please sign in to comment.