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
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 database = 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!
database.use('my-database-name');
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' ]);
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.get('hello');
database.get('mynum');
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;
storage.drop();
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 | - |
License
This project is licensed under the Apache 2.0 License.