hr.db
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

HR.DB

Installation

Linux & Windows

$ npm install hr.db --save

Mac

  1. Install: XCode
  2. Run: npm i -g node-gyp in terminal
  3. Run: node-gyp --python /path/to/python2.7 (skip this step if you didn't install python 3.x)
  4. Run: npm i hr.db
  • Persistent Storage - Data doesn't disappear through restarts
  • Works out of the box - No need to set up a database server, all the data is stored locally in the same project
  • Beginner Friendly - Originally created for use in tutorials, the documentation is straightforward and jargon-free
  • & more...

Example

const db = require('hr.db');

// Setting an object in the database:
db.set('userInfo', { difficulty: 'Easy' })
// -> { difficulty: 'Easy' }

// Pushing an element to an array (that doesn't exist yet) in an object:
db.push('userInfo.items', 'Sword')
// -> { difficulty: 'Easy', items: ['Sword'] }

// Adding to a number (that doesn't exist yet) in an object:
db.add('userInfo.balance', 500)
// -> { difficulty: 'Easy', items: ['Sword'], balance: 500 }

// Repeating previous examples:
db.push('userInfo.items', 'Watch')
// -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 500 }
db.add('userInfo.balance', 500)
// -> { difficulty: 'Easy', items: ['Sword', 'Watch'], balance: 1000 }

// Fetching individual properties
db.get('userInfo.balance') // -> 1000
db.get('userInfo.items') // ['Sword', 'Watch']

hr.db API

db.all(options)

This method returns currently used table (or specified table) as array.

db.fetchAll(options)

Alias of db.all().

db.add(key, number, options)

This method can be used for addition (numbers).

db.delete(key, options)

This method can be used to remove specific data with its key.

db.fetch(key, options)

This method can be used to get data from the database.

db.get(key, options)

Alias of db.fetch.

db.set(key, value, options)

This method can be used to update existing data or add new data.

db.subtract(key, number, options)

Similar to db.add, this method can be used for subtraction.

db.has(key, options)

Returns true if it finds the requested key in the database.

db.type(key, options)

Returns data type of the value assigned to this key.

db.push(key, valueOrValues)

This method can be used to push the data (Similar to Array.prototype.push).

Original License

GitHub DevSnowflake

Package Sidebar

Install

npm i hr.db

Weekly Downloads

3

Version

2.0.0

License

MIT

Unpacked Size

37.3 kB

Total Files

15

Last publish

Collaborators

  • hunterrock