Database

Database

Represents XenDB Database class

Constructor

# new Database(databaseFileopt, optionsopt)

XenDB Database

Parameters:
Name Type Attributes Default Description
databaseFile String <optional>
"json.sqlite"

The database's file

options Object <optional>

Database options

Properties
Name Type Attributes Default Description
database SQLite.Database <optional>

The SQLite Database

path String <optional>
"./"

The database's path file

table String <optional>
"JSON"

The database's table name

useWalMode Boolean <optional>

Whether to use wal mode or not

Properties
Name Type Description
database SQLite.Database

The main SQLite3 Database

name String

The name of the database

options Object

XenDB options

rowCount Number

The database table's rows count

Source:

Extends

  • EventEmitter

Members

# database :SQLite.Database

Returns the SQLite3-Database Manager

Type:
  • SQLite.Database
Source:

# length :Number

Returns length of this database

Type:
  • Number

# rowCount :Number

Returns number of rows count

Type:
  • Number
Source:

Methods

# add(key, value, options)

Add numbers to a key in the database

Parameters:
Name Type Description
key String

Key of the data

value Number

Any numerical value

options Object

Options

# all(options)

Returns used table (or specific table) as array

Parameters:
Name Type Description
options Object

# allTableArray()

Returns all table(s) as array.

# array()

Returns an array of this table

# createTable(name)

Creates new instance of this database with the specified table

Parameters:
Name Type Default Description
name String JSON

Table name

# delete(key, options) → {Boolean}

Deletes a data from the specified key

Parameters:
Name Type Description
key String

Key to be delete

options Object

Options

Returns:
Type
Boolean

# deleteAll(optionsopt)

Delete all data in the database

Parameters:
Name Type Attributes Description
options Object <optional>

Options

# divide(key, value, options)

Divide numbers to a key in the database

Parameters:
Name Type Description
key String

Key of the data

value Number

Any numerical value

options Object

Options

# drop(options) → {Boolean}

Drops currently active/specified table

Parameters:
Name Type Description
options Object

Options

Returns:
Type
Boolean

# endsWith(key, options)

Alias of Database.all() but easier to sort by key

Parameters:
Name Type Description
key String

The key of the data

options Object

Options

# eval(x)

Evaluate anything inside the Database class using this

Parameters:
Name Type Description
x any

Value to be evaluated

# every(fn, options)

Identical to Array.every

Parameters:
Name Type Description
fn function

A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array.

options Object

Options

# export(options)

Exports this db

Parameters:
Name Type Description
options Object

Export options

Deprecated:
  • Yes

# extract(key, value, options)

Extract a value from an array. Alias of Database.pull()

Parameters:
Name Type Description
key String

Key of the data

value any

The value that wanted to be extracted

options Object

Options

# fetch(key, options)

Returns saved data from this database. Alias of Database.get()

Parameters:
Name Type Description
key String

Key of the data

options Object

Options

# fetchAll(options)

Alias of Database.all()

Parameters:
Name Type Description
options Object

Options

# fetchOne(key, value, options)

Fetch a specific value from the database

Parameters:
Name Type Description
key String

Key of the data

value any

The value that wanted to be fetched

options Object

Options

# filter(fn, options)

Identical to Array.filter

Parameters:
Name Type Description
fn function

A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.

options Object

Options

# find(fn, options)

Identical to Array.find

Parameters:
Name Type Description
fn function

find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, find immediately returns that element value. Otherwise, find returns undefined.

options Object

Options

# findIndex(fn, options)

Identical to Array.findIndex

Parameters:
Name Type Description
fn function

find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, findIndex immediately returns that element index. Otherwise, findIndex returns -1.

options Object

Options

# flatMap(fn, options)

Identical to Array.flatMap

Parameters:
Name Type Description
fn function

Function that produces an element of the new Array, taking three arguments.

options Object

Options

# forEach(fn, options)

Identical to Array.forEach

Parameters:
Name Type Description
fn function

A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.

options Object

Options

# get(key, options)

Returns saved data from this database. Alias of Database.fetch()

Parameters:
Name Type Description
key String

Key of the data

options Object

Options

# getOne(key, value, options)

Get a specific value from the database. Alias of Database.fetchOne()

Parameters:
Name Type Description
key String

Key of the data

value any

The value that wanted to be fetched

options Object

Options

# has(key, options) → {Boolean}

Checks if there is any matching value with provided key

Parameters:
Name Type Description
key String

Key to match

options Object

Options

Returns:
Type
Boolean

# includes(key, options) → {Boolean}

Alias of db.has

Parameters:
Name Type Description
key String

Key

options Object

Options

Returns:
Type
Boolean

# indexOf(searchElement, fromIndex, options)

Identical to Array.indexOf

Parameters:
Name Type Default Description
searchElement any

The value to locate in the array.

fromIndex Number 0

The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.

options Object

Options

# init() → {void}

Fired when the database is ready

Source:
Returns:
Type
void

# keyArray(options)

Returns array of keys

Parameters:
Name Type Description
options Object

Options

# map(fn, options)

Identical to Array.map

Parameters:
Name Type Description
fn function

A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.

options Object

Options

# modulus(key, value, options)

Modulus for existing data with the given numerical value.

Parameters:
Name Type Description
key String

Key of the data

value Number

Numerical value

options Object

Options

# multiply(key, value, options)

Multiply numbers to a key in the database

Parameters:
Name Type Description
key String

Key of the data

value Number

Any numerical value

options Object

Options

# prepareTable(nameopt)

Prepares a tabe

Parameters:
Name Type Attributes Description
name String <optional>

The table name

Source:

# pull(key, value, options)

Extract a value from an array (Reverse of Database.push())

Parameters:
Name Type Description
key String

Key of the data

value any

The value that wanted to be extracted/pull

options Object

Options

# push(key, value, options)

Push an array type value into the database key

Parameters:
Name Type Description
key String

Key of the data

value any

Value to store (or push into the key)

options Object

Options

# reduce(fn, initialValue, options)

Identical to Array.reduce

Parameters:
Name Type Description
fn function

A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.

initialValue Object

If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.

options Object

Options

# reduceRight(fn, initialValue, options)

Identical to Array.reduceRight

Parameters:
Name Type Description
fn function

A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.

initialValue Object

If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.

options Object

Options

# set(key, value, options)

Set or re-writes data in this database key

Parameters:
Name Type Description
key String

Key of the data

value any

Value to store

options Object

Options

# size()

Returns the database file size in bytes

# some(fn, options)

Identical to Array.some

Parameters:
Name Type Description
fn function

A function that accepts up to three arguments. The some method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value true, or until the end of the array.

options Object

Options

# sort(fn, options)

Identical to Array.sort

Parameters:
Name Type Description
fn function

Function used to determine the order of the elements. It is expected to return a negative value if first argument is less than second argument, zero if they're equal and a positive value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.

options Object

Options

# startsWith(key, options)

Alias of Database.all() but easier to sort by key

Parameters:
Name Type Description
key String

The key of the data

options Object

Options

# subtract(key, value, options)

Subtract numbers to a key from the database

Parameters:
Name Type Description
key String

Key of the data

value Number

Any numerical value

options Object

Options

# tables()

Returns all table name

# toJSON(options)

Used by the JSON.stringify method to enable the transformation of an object's data for JavaScript Object Notation (JSON) serialization.

Parameters:
Name Type Description
options Object

Options

# toString()

Returns a value representation of an array

# type(key, options)

Returns data type of fetched data

Parameters:
Name Type Description
key String

Key of the data

options Object

Options

# use(database)

This method updates current database manager with a new one. Database parameter can either be Database instance or BetterSQLite3.Database instance

Parameters:
Name Type Description
database any

The database

# valueArray(options)

Returns array of values

Parameters:
Name Type Description
options Object

Options