modules

ac-bundle-module-api-leveldb

api/leveldb.js

A module for ac-bundle-app, published by ac-bundle-module.

Available Methods: levels, level, db, getCallback, putCallback

levels

[object Object]
level

[object Object]
db

function(path) {
  fs.mkdirSync("./" + path, {recursive: true});
  if (!app.has(mod.levels[path])) mod.levels[path] = mod.level(path);
  return mod.levels[path];
}

getCallback

async function(callback, errorCallback, table, key) {
  var db = mod.db(config.leveldb.path + "/" + table);
  await new Promise(function(resolve, reject) {
    db.get(key, function(error, val) {
      if (!app.has(error)) {
        if (typeof callback === "function") callback(val);
      } else {
        if (typeof errorCallback === "function") errorCallback("LevelDB: Could not fetch " + table + "/" + key, val);
      }
      resolve();
    });
  });
}

putCallback

async function(callback, errorCallback, table, key, value) {
  var db = mod.db(config.leveldb.path + "/" + table);
  await new Promise(function(resolve, reject) {
    db.put(key, value, function(error, val) {
      if (!app.has(error)) {
        if (typeof callback === "function") callback(val);
      } else {
        if (typeof errorCallback === "function") errorCallback("LevelDB: Could not fetch " + table + "/" + key, val);
      }
      resolve();
    });
  });
}

Happy Coding!

Leave a Reply

Your email address will not be published. Required fields are marked *