appdata

AppData is a minimalistic Node.js framework for accessing, writing and manipulating datasets in the users AppData (or Homedata) folder. It has a simple API and helps you saving persistent data for e.g. an electron desktop application.

Usage no npm install needed!

<script type="module">
  import appdata from 'https://cdn.skypack.dev/appdata';
</script>

README

AppData is a minimalistic Node.js framework for accessing, writing and manipulating datasets in the users AppData (or Homedata) folder. It has a simple API and helps you saving persistent data for e.g. an electron desktop application.

Installation

npm install --save appdata

# or via git
git clone https://github.com/janbiasi/appdata.git

Usage

Setup

First off you need to create a new AppData Storage object. The AppData module exports a function which takes one argument, an optional custom settings object. If you are wondering which options are supported, take a look at TODO.

const appdata = require('appdata');

Selecting a Database

Next, you will have to select your database by a name. If the database does not exists a new set will be created by the system itself. There are only lower-, uppercase letters, numbers, hyphens and underscores allowed!

const database = appdata.connect('database-name', {
    /* options here */
});
Signature
connect(name: String [, options: Object]): Interface

Inserting data

Inserting data is as simple as setting new variables! The key must be a string and not an integer. But the value can be whatever you'd like to insert.

database.set('hello', 'world!');
database.set('mynum', 1923);
database.set('coll', [ 0, undefined, 'hey' ]);
Signature
set(key: String, value: <T>): <T>

Reading data

Like inserting, reading is very simple. Grab the key you'd like to find the value for and you'll get the result (or undefined in case the key does not exist).

database.all(); // { hello: "world!" ... }
database.get('hello'); // world!
database.get('mynum'); // 1923
Signature
get(key: String): <T>

Deleting and dropping

Datasets can be deleted by key or can be totally removed by the .drop() method. The methods are pretty simple to use, just look at the example below.

let name = storage.delete('name');
storage.get('name') === name; // false
storage.drop(); // {}
Signature
drop(): <T>

Eventhandling

The Interface inherits from the EventEmitter class, so it implements its own events. All possible events execute on the storage are listed below with a description and its paramters.

Event Description Paramter
connect Emitted when connected to the database Database-name
sync Emitted on sync action Boolean or data synced
set Emitted when setting a new key-value pair Key and value
get Emitted when getting a key-value pair Key and value
has Emitted when checking if a key exists Key and if exists (Boolean)
delete Emitted when deleting a key-value pair Key and the deleted value
drop Emitted when dropping the database -
Signature
on(event: String, handler: Function): void

Services

Services can be created and published as node modules for adding custom functionallity to the interface of the AppData module. Services can be used e.g. for filtering, querying, exporting data and much more. Inside the service itself there is an interface property, which will provide you all methods which are listed above! Here is a short example how you can create your own service;

var Service = require('appdata').Service;
var MyService = new Service();

MyService.filter = function(data, options) {
    var data = this.interface.all();
    // ... add your filter logic here
    return [];
};

// Attach the service to your store instance
storage.service(MyService);

License

This project is licensed under the Apache 2.0 License.