0.1.2 • Published 3 years ago

v30db v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Table of Content

Install

  • NPM
    • npm install v30db
  • YARN
    • yarn add v30db

Usage

const v30DB = require('v30db');
const db = new v30DB({
  name: 'database', // default db
  // By the way, you can create the file in the specified folder by typing the file path to the name. Check src/test/test.js file.
  language: 'en', // default en
  adapter: 'JsonDB', // default JsonDB
  seperator: '.' // default .
});

db.set('test.v30.db', 'hello'); // {"test": {"v30": {"db": "hello"} } }
db.set('number', 85); // 85
db.get('test.v30'); // {"db": "hello"}
db.fetch('test.v30'); // {"db": "hello"}
db.delete('test.v30.db'); // true
db.has('test'); // true
db.update('number', (x) => x + 15); // {"number": 100 }
db.add('number', 10); // 110
db.substract('number', 20); // 90
db.substr('number', 15); // 75
db.push('pushed', ['hello', 'everyone'], 'haha'); // {"pushed": [ ['hello', 'everyone'], 'haha'] }
db.setByIndex('pushed', 0, 'hi'); // {"pushed": ['hi', 'haha'] }
db.setByValue('pushed', 'haha', 'not funny'); // {"pushed": ['hi', 'not funny'] }
db.deleteByIndex('pushed', 0); // {"pushed": ['not funny'] }
db.deleteByValue('pushed', 'not funny'); // {"pushed": [] }
db.all(); // {"test": {"v30": {} }, "number": 75, "pushed": [] }
db.deleteAll(); // true

Documentation

Classes

Typedefs

v30DB

v30DB class

Kind: global class

new v30DB(options)

Options of the v30DB class.

Properties

NameTypeDefaultDescription
namestring"db"Name of the database file.
languagestring"en" or "tr"Language of the error and warnings.
adapterstring"JsonDB" or "YamlDB"Type of the stored data.
seperatorstring"."Seperator for each data.

v30DB.set(key, value) ⇒ any

Sets data in database.

Kind: instance method of v30DB

ParamType
keystring
valueany

Example

db.set('test.v3.db', 'hello');
// {"test": {"v3": {"db": "hello"} } }
db.set('number', 85);
// {"number": 85}

v30DB.get(key) ⇒ any

Gets data from database.

Kind: instance method of v30DB

ParamType
keystring

Example

db.get('test.v3');
// {"db": "hello"}

v30DB.fetch()

Clone of get function.

Kind: instance method of v30DB

v30DB.delete(key) ⇒ boolean

Deletes data from database.

Kind: instance method of v30DB

ParamType
keystring

Example

db.delete('test.v3.db');
// true

v30DB.has(key) ⇒ boolean

Checks data in database.

Kind: instance method of v30DB

ParamType
keystring

Example

db.has('test');
// true

v30DB.update(key, fn)

Updates data in database.

Kind: instance method of v30DB

ParamType
keystring
fnfunction

Example

db.update('number', (x) => x + 15);
// {"number": 100 }

v30DB.add(key, value) ⇒ number

Adds value to data in created database.

Kind: instance method of v30DB

ParamType
keystring
valuenumber

Example

db.add('number', 10);
// 110

v30DB.substract(key, value) ⇒ number

Substracts value to data in created database.

Kind: instance method of v30DB

ParamType
keystring
valuenumber

Example

db.substract('number', 20);
// 90

v30DB.substr()

Clone of substract function.

Kind: instance method of v30DB

v30DB.push(key, ...value) ⇒ Array.<any>

Pushs element to data in database.

Kind: instance method of v30DB

ParamType
keystring
...valueany

Example

db.push('pushed', ['hello', 'everyone'], 'haha');
// {"pushed": [ ['hello', 'everyone'], 'haha'] }

v30DB.setByIndex(key, index, value)

Sets element from data in database by index.

Kind: instance method of v30DB

ParamType
keystring
indexnumber
valueany

Example

db.setByIndex('pushed', 0, 'hi');
// {"pushed": ['hi', 'haha'] }

v30DB.setByValue(key, oldValue, newValue)

Sets element from data in database by value.

Kind: instance method of v30DB

ParamType
keystring
oldValueany
newValueany

Example

db.setByValue('pushed', 'haha', 'not funny');
// {"pushed": ['hi', 'not funny'] }

v30DB.deleteByIndex(key, index) ⇒ Array.<any>

Deletes element from data in database by index.

Kind: instance method of v30DB

ParamType
keystring
indexnumber

Example

db.deleteByIndex('pushed', 0);
// {"pushed": ['not funny'] }

v30DB.deleteByValue(key, value) ⇒ Array.<any>

Deletes element from data in database by value.

Kind: instance method of v30DB

ParamType
keystring
valueany

Example

db.deleteByValue('pushed', 'not funny');
// {"pushed": [] }

v30DB.all() ⇒ object

Returns all data in database.

Kind: instance method of v30DB Example

db.all();
// {"test": {"v3": {} }, "number": 75, "pushed": [] }

v30DB.deleteAll() ⇒ boolean

Deletes all data from database.

Kind: instance method of v30DB Example

db.deleteAll();
// true
0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago