Connection Functions

Connection functions to interact with the database

All the properties and methods of the connection class are described below with external links to further documentation.

Properties

.Datalength

The amount of tables of the current database.
Type - Number

.Datatype

The base instance of the database.
Type - String<"Object" | "Array">

.Pool

Whether the connection is in a pool, returns a circular to the pool itself.
Type - Pool | Null

Methods

.Set(Key, DBObject, Path?)

Manages the elements of the database.

Parameter Type Description
Key KeyResolvable Key to specify on what table to set the element at. If none, the DBObject is the new database instance itself.
DBObject Any Data to set into the database at the key.
Path? Dotaccess Optional dotaccess path.

Returns - DBObject
Returns the set object.

.Fetch(Key, Path?)

Manages the retrieval of the database.

Parameter Type Description
Key KeyResolvable Key to specify retrieval of a table. If none, QDB will return the entire database itself. You may use the first argument to also refer to the main database model for properties, such as `[].length`.
Path? Dotaccess Optional dotaccess path.

Returns - Any
The database, table, or specific element or property when using dotaccess.

.Append(Key, DBObject)

Inserts a unique data model into the database.

Parameter Type Description
Key KeyResolvable Context key to specify under what key the data should be inserted as. If none, QDB will try to push the DBObject to the origin instead.
DBObject Any Data to set or push into the database.

Returns - DBObject | Null
Returns a nill value when the key is not unique and will not overwrite, otherwise, QDB inserts the data model and returns it.

.Insert(DBObject)

Pushes a new data model into the database.

Parameter Type Description
DBObject Any Data to insert into the database.

Returns - DBObject
Returns the inserted model.

.Push(DBObject, Path?)

Pushes a new data model into the database.

Parameter Type Description
DBObject Any Data to push into the database.
Path Dotaccess Optional dotaccess path. If not specified, this behaves as DB.Insert();.

Returns - DBObject
Returns the inserted model.

.Update(Key, DBObject, Path?)

Edits an element of the database.

Parameter Type Description
Key KeyResolvable Key to specify what element to edit.
DBObject Any Data to replace the element with.
Path Dotaccess Optional dotaccess path.

Returns - DBObject | Null
Returns a nill value when the key doesn't exist and will not edit the element, otherwise, QDB updates the element and returns it.

.Edit(cfn, efn)

Finds a table in the database and edits it with a callback.

Parameter Type Description
cfn Function Function used to test with (should return a boolean).
efn Function Callback edit function, that has to return the new value of the found element.

Returns - DBObject_Old | Null
Returns a nill value when the tester function doesn't match, otherwise returns the old element.

.Modify(efn)

Uses a callback to provide the database and the returned value is the new database instance.

Parameter Type Description
efn Function Callback edit function, that has to return the new value of the database.

Returns - DB
Returns the new database instance.

.Map(efn, Path?)

Maps an object or array in the database.

Parameter Type Description
efn Function Function which returns the new value of the element.
Path Dotaccess Optional dotaccess path pointing towards the element to map.

Returns - Object | Array
The new and changed object or array.

.Ensure(Key, DBObject, Path?)

Ensures a value being there. This behaves as if (!DB.includes(Element)) DB.push(Element); or if (!DB[Key]) DB[Key] = Element; in context.

Parameter Type Description
Key KeyResolvable Context key to see if a table exists.
DBObject Any Data to insert if that specific element does not exist.
Path Dotaccess Optional dotaccess path.

Returns - Boolean
Returns whether or not the element was inserted. If true was returned, the element was not there.

.Invert(Path)

Inverts the boolean value on the given path.

Parameter Type Description
Path Dotaccess | KeyResolvable Key or a dotaccess path to the value to invert.

Returns - Boolean
The new value of the entry.

.Exists(Key, Path?)

Searches the given path if an element exists.

Parameter Type Description
Key KeyResolvable Key to specify what to search for.
Path Dotaccess Optional dotaccess path.

Returns - Boolean
A boolean value, either true or false.

.Has(Key, Path?)

Searches the given path if an element exists. Similar to DB.Exists();, but returns the value if it exists, else an empty object instead of a nill value.

Parameter Type Description
Key KeyResolvable Key to specify what to search for.
Path Dotaccess Optional dotaccess path.

Returns - Any | Object
If it exists, returns that value, otherwise an empty object.

.Expect(Key, Value, Path?, Overwrite?)

Similar to DB.Exists();, but expects a value. If the value doesn't match, it automatically returns a false boolean.

Parameter Type Description
Key KeyResolvable Context key to refer to a table.
Value Any Value to see if the key element has this specific value. If not, QDB will return a false boolean.
Path Dotaccess Optional dotaccess path.
Overwrite Boolean Overwrite the value regardless. If set, this behaves as a constant DB.Set();.

Returns - Boolean
Whether or not the expected value was there.

.Accumulate(Path, fn)

Performs a function on an item. Similar to DB.Edit();, but finds an element first.

Parameter Type Description
Path KeyResolvable | Dotaccess The key of the value to execute on, can be a dotaccess path.
fn Function Function to execute on the item.

Returns - Any
The new vaule of the element.

.Destroy()

Clears the entire database.

WARNING - Sets the database immediately to an empty object.

Returns - Undefined

.Sweep(cfn, Path?)

Sweeps elements from an array or object. If the element passes the tester function, it will be removed from the database.

Parameter Type Description
cfn Function Function used to test with. (Should return a boolean.) (If true, QDB will sweep the element.)
Path Dotaccess Optional dotaccess path. Without it, QDB refers to the main database object or array.

Returns - Number
Amount of elements swept from the database.

.Delete(Key, Path?)

Manages the deletion of the database.

Parameter Type Description
Key KeyResolvable Key to specify what table to delete.
Path Dotaccess Optional dotaccess path or just a key.

Returns - Undefined

.Return(Path, Ret)

Essentially a DB.Get();, but makes a callback instead.

Parameter Type Description
Path KeyResolvable | Dotaccess Optional dotaccess path. Without it, QDB refers to the main database object.
Ret Function Returns the value of the path.

Returns - Undefined

.Each(Path, Ret)

Iterates through an array or object. No changes are recorded on the database instance.

Parameter Type Description
Path KeyResolvable | Dotaccess Optional dotaccess path. Without it, QDB refers to the main database object.
Ret Function Function containing the value of the array or object it's iterating through.

Returns - Undefined

.Filter(Path, cfn)

Filter elements in the database and returns it. Database is not affected at all.

Parameter Type Description
Path Dotaccess Optional dotaccess path or just a key. Can be used to locate an array. Without it, QDB refers to the main database object.
cfn Function Function used to test with. (Should return a boolean.) (If true, QDB will filter it.)

Returns - Array
Array with the new elements that passed the test.

.Sort(Path, cfn)

Sorts elements in the database and returns it. Database is not affected at all.

NOTE - This method uses the native sorting function for Arrays and it sorts by their unicode representative.

Parameter Type Description
Path Dotaccess Optional dotaccess path or just a key. Can be used to locate an array or object. Without it, QDB refers to the main database object.
efn Function Function used to test with. (Should return a boolean.) (If true, QDB will sort it out and return it.)

Returns - Array
Array with the sorted elements.

.Find(Path?, cfn)

Finds an element in the given, optional path.

Parameter Type Description
Path Dotaccess Optional dotaccess path or just a key. Can be used to locate the root object or array. If none, QDB refers to the main database object.
cfn Function Function used to test with. (Should return a boolean.) (If true, QDB will filter it out.)

Returns - Any
The found element of this search.