Level / level

Universal abstract-level database for Node.js and browsers.
MIT License
1.55k stars 106 forks source link

How to judge whether the database is empty when it is first used? #156

Closed ziyansuz closed 5 years ago

ziyansuz commented 5 years ago

Use db.get to show that 'Key not found in database'. what should I do?

ziyansuz commented 5 years ago

After the program starts, if the database does not exist, perform the refresh task.

vweevers commented 5 years ago

There are a few ways, like db.iterator({ limit: 1 }), db.createReadStream({ limit: 1 }) or just checking whether the directory on disk exists (unless you are using level in the browser).

But a simpler solution might be to store something like the last refresh time in the db.

ziyansuz commented 5 years ago

very well