native-level-promise

A native node 8 promise wrapper around the `level` database.

Usage no npm install needed!

<script type="module">
  import nativeLevelPromise from 'https://cdn.skypack.dev/native-level-promise';
</script>

README

Native Level Promise

A proper, Class-based, Promisified, Node 8 Native wrapper around level.

Installation

npm i native-level-promise

Usage

Most native Level features should work the same in promisified versions. Here are a few examples:

const Level = require('native-level-promise');

db = new Level('./data/mydb');

db.put("test", "thing").then(() => console.log("Value inserted"));

db.del(key).then(() => console.log("Value deleted"));

Note that streams remain the same:

const stream = db.keyStream();
stream.on('data', (key) => {
  this.db.get(key, (err, value) => {
    if (err) console.log(err);
    // do something with value.
  });
});
stream.on('end', () => {
  console.log("Key Stream has ended");
});

And finally

db.close().then(() => {
  console.log("DB has been closed!");
});

I feel I don't need to say this all works with async/await but I'll say it anyway because... because.