Skip to content

Commit

Permalink
Add support for level v8 (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
neruson authored Jan 22, 2024
1 parent 8799d03 commit 0532629
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions lib/register-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,24 @@ function createDbRegister (pwd, _path, _require = require) {
return dbs.get(name)
}

const db = level(
path.resolve(dbPath, name),
{valueEncoding: 'json'}
)
let db
try {
// Level pre-v8
db = level(
path.resolve(dbPath, name),
{valueEncoding: 'json'}
)
} catch (err) {
if (err instanceof TypeError && level.Level) {
// Level v8
db = new level.Level(
path.resolve(dbPath, name),
{valueEncoding: 'json'}
)
} else {
throw err
}
}

dbs.set(name, db)

Expand Down

0 comments on commit 0532629

Please sign in to comment.