v30dbdeprecated

Fast and simple database handler for NodeJS.

Usage no npm install needed!

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

README

v30DB


Contributors Downloads CodeFactor

Fast and simple database handler for NodeJS.

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

Options : object

Options of the v30DB class.

v30DB

v30DB class

Kind: global class

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.

v30DB.set(key, value) ⇒ any

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}

v30DB.get(key) ⇒ any

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

v30DB.delete(key) ⇒ boolean

Deletes data from database.

Kind: instance method of v30DB

Param Type
key string

Example

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

v30DB.has(key) ⇒ boolean

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 }

v30DB.add(key, value) ⇒ number

Adds value to data in created database.

Kind: instance method of v30DB

Param Type
key string
value number

Example

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

v30DB.substract(key, value) ⇒ number

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

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

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'] }

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

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'] }

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

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": [] }

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