README
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
- v30DB
v30DB class
Typedefs
v30DB
v30DB class
Kind: global class
- v30DB
- new v30DB(options)
- .set(key, value) ⇒
any
- .get(key) ⇒
any
- .fetch()
- .delete(key) ⇒
boolean
- .has(key)
- .update(key, fn)
- .add(key, value) ⇒
number
- .substract(key, value) ⇒
number
- .substr()
- .push(key, ...value) ⇒
Array.<any>
- .setByIndex(key, index, value)
- .setByValue(key, oldValue, newValue)
- .deleteByIndex(key, index) ⇒
Array.<any>
- .deleteByValue(key, value) ⇒
Array.<any>
- .all() ⇒
object
- .deleteAll() ⇒
boolean
new v30DB(options)
Options of the v30DB class.
Properties
Name | Type | Default | Description |
---|---|---|---|
[name] | string |
"db" |
Name of the database file. |
[language] | string |
"en" or "tr" |
Language of the error and warnings. |
[adapter] | string |
"JsonDB" or "YamlDB" |
Type of the stored data. |
[seperator] | string |
"." |
Seperator for each data. |
any
v30DB.set(key, value) ⇒ Sets data in database.
Kind: instance method of v30DB
Param | Type |
---|---|
key | string |
value | any |
Example
db.set('test.v3.db', 'hello');
// {"test": {"v3": {"db": "hello"} } }
db.set('number', 85);
// {"number": 85}
any
v30DB.get(key) ⇒ Gets data from database.
Kind: instance method of v30DB
Param | Type |
---|---|
key | string |
Example
db.get('test.v3');
// {"db": "hello"}
v30DB.fetch()
Clone of get function.
Kind: instance method of v30DB
boolean
v30DB.delete(key) ⇒ Deletes data from database.
Kind: instance method of v30DB
Param | Type |
---|---|
key | string |
Example
db.delete('test.v3.db');
// true
boolean
v30DB.has(key) ⇒ Checks data in database.
Kind: instance method of v30DB
Param | Type |
---|---|
key | string |
Example
db.has('test');
// true
v30DB.update(key, fn)
Updates data in database.
Kind: instance method of v30DB
Param | Type |
---|---|
key | string |
fn | function |
Example
db.update('number', (x) => x + 15);
// {"number": 100 }
number
v30DB.add(key, value) ⇒ Adds value to data in created database.
Kind: instance method of v30DB
Param | Type |
---|---|
key | string |
value | number |
Example
db.add('number', 10);
// 110
number
v30DB.substract(key, value) ⇒ Substracts value to data in created database.
Kind: instance method of v30DB
Param | Type |
---|---|
key | string |
value | number |
Example
db.substract('number', 20);
// 90
v30DB.substr()
Clone of substract function.
Kind: instance method of v30DB
Array.<any>
v30DB.push(key, ...value) ⇒ Pushs element to data in database.
Kind: instance method of v30DB
Param | Type |
---|---|
key | string |
...value | any |
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
Param | Type |
---|---|
key | string |
index | number |
value | any |
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
Param | Type |
---|---|
key | string |
oldValue | any |
newValue | any |
Example
db.setByValue('pushed', 'haha', 'not funny');
// {"pushed": ['hi', 'not funny'] }
Array.<any>
v30DB.deleteByIndex(key, index) ⇒ Deletes element from data in database by index.
Kind: instance method of v30DB
Param | Type |
---|---|
key | string |
index | number |
Example
db.deleteByIndex('pushed', 0);
// {"pushed": ['not funny'] }
Array.<any>
v30DB.deleteByValue(key, value) ⇒ Deletes element from data in database by value.
Kind: instance method of v30DB
Param | Type |
---|---|
key | string |
value | any |
Example
db.deleteByValue('pushed', 'not funny');
// {"pushed": [] }
object
v30DB.all() ⇒ Returns all data in database.
Kind: instance method of v30DB
Example
db.all();
// {"test": {"v3": {} }, "number": 75, "pushed": [] }
boolean
v30DB.deleteAll() ⇒ Deletes all data from database.
Kind: instance method of v30DB
Example
db.deleteAll();
// true