1.0.1 • Published 7 years ago

local-database v1.0.1

Weekly downloads
3
License
ISC
Repository
github
Last release
7 years ago

local-database

Methods

localedb = {
  SET(namespace, data, params),
  GET(namespace, params),
  REMOVE(namespace, params),
  REMOVE_ALL(namespace)
}

All methods throw a result array. If you get a data and want access it you need check if the your_method.error.value is set to false unless your action failed. Then you can get your data accessing the your_method.success.data

{
  error: {
    // If the method failed or not (true, false).
    value: null,
    // Message associated with failure action.
    message: null
  },
  success: {
    // Message associated with success action.
    message: null,
    // If the data is supposed to return a value, you will access here.
    data: null
  }
}

SET(namespace, data, params = undefined)

paramtypeoptional
namespacedatabase nameno
datadata to setno
paramsfunction bind with findIndex to edit a specific datayes
  • usage
// 1. On create
var data = {id: 0, name: root, lvl: 100};
localdb.SET('database_test', data);

// 2. On update
var data = {id: 0, name: root, lvl: 100};
function findData(d) {
  return d.name == "root";
}
localedb.SET('database_test', data, findData);

GET(namespace, params = undefined)

paramtypeoptional
namespacedatabase nameno
paramsfunction bind with filter to get a specific datayes
  • usage
// 1. Getting all data
var myDataBase = localdb.GET('database_test');

// 2. Getting filtered data
function filterData(d) {
  return d.lvl >= 50;
}
var myDataBase = localdb.GET('database_test', myDataBase);

REMOVE(namespace, params)

paramtypeoptional
namespacedatabase nameno
paramsfunction bind with findIndex to remove a specific datano
  • usage
// 1 Removing a data
function findData(d) {
  return d.name == "root";
}
localdb.REMOVE('database_test', findData);

REMOVE_ALL(namespace)

paramtypeoptional
namespacedatabase nameno
  • usage
// 1 Removing all data
localdb.REMOVE_ALL('database_test);