Documentation
.all()
⇒
.all()
⇒Gets all the elements from the database.
Returns: All the elements in the database.
Clears all elements from the database.
Returns: Promise
<
undefined
>
— Returns undefined
.delete(key)
⇒
.delete(key)
⇒Deletes an element from the database by key.
Parameters
The key(s) of the element to remove from the database.
Returns: — true
if the element(s) is deleted successfully, otherwise false
.
Ensures if an element exists in the database. If the element does not exist, sets the element to the database and returns the value.
Parameters
key
:string
Required*
The key of the element to ensure.
value
:*
Required*
The value of the element to ensure.
path
:string
Default: null
Returns: Promise
<any |
undefined
>
— The (default) value of the element.
Example
Finds a single item where the given function returns a truthy value. Behaves like The database elements is mapped by their
key
. If you want to find an element by key, you should use theget
method instead. See MDN for more details.
Parameters
fn
:function
Required*
The function to execute on each value in the element.
thisArg
:*
Default: undefined
Object to use as this
inside callback.
Returns: Promise
<*|
undefined
>
— The first element in the database that satisfies the provided testing function. Otherwise undefined
is returned
Example
Gets the value of an element from the database by key.
Parameters
key
:string
Required*
The key of the element to get.
path
:string
Default: null
The path of the property to get from the value.
Returns: Promise
<*|
undefined
>
— The value of the element, or undefined
if the element cannot be found in the database.
Example
Checks whether an element exists in the database or not.
Parameters
key
:string
Required*
The key of an element to check for.
path
:string
Default: null
The path of the property to check.
Returns: Promise
<
boolean
>
— true
if the element exists in the database, otherwise false
.
.keys()
⇒
.keys()
⇒Returns an array that contains the keys of each element.
Returns: — An array that contains the keys of each element.
.math(key, operation, operand, path=null)
⇒true
.math(key, operation, operand, path=null)
⇒true
Performs a mathematical operation on a value of an element.
Parameters
key
:string
Required*
The key of the element.
operation
:string
Required*
The mathematical operation to perform.
operand
:number
Required*
The right-hand operand.
path
:string
Default: null
The path of the property to perform mathematical operation on.
Returns: true
Example
.multi(names, options=DreamyOptions)
⇒Object
.multi(names, options=DreamyOptions)
⇒Object
Creates multiple instances of Dreamy-db.
Parameters
An array of strings. Each element will create new instance.
options
:DreamyOptions
Default: DreamyOptions
The options for the instances.
Returns: Object
— An object containing created Dreamy-db instances.
Example
The options the database was instantiated with.
Pushes an item to the array value in the database.
Parameters
key
:string
Required*
The key of the element to push to.
value
:*
Required*
The value to push.
path
:string
Default: null
The path of the property of the value to push.
allowDuplicates
:boolean
Default: false
Whether or not, allow duplicates elements in the value.
Returns: Promise
<*>
— The value to push.
Removes an item from the array value of an element in the database.
structured or complex data types such as arrays or objects cannot be removed from the value of the element.
Parameters
key
:string
Required*
The key of the element to remove.
value
:*
Required*
The value to remove. Must be a string.
path
:string
Default: null
The path of the property to remove.
Returns: Promise
<*>
— The value to remove.
Sets an element to the database.
Parameters
key
:string
Required*
The key of the element to set to the database.
value
:*
Required*
The value of the element to set to the database.
path
:string
Default: null
The path of the property to set in the value.
Returns: Promise
<true>
— Returns true
.
Example
.values()
⇒
.values()
⇒Returns an array that contains the values of each element.
Returns: — Array that contains the values of each element.
Last updated
Was this helpful?