Database
Summary
Defines base database for all databases.
This should not be used directly, use one of its subclasses instead.
Constructor
Database
Syntax
Database
-
configuration
Summary
Parameters:
-
configuration
ObjectA database configuration object depending on the database type
Item Index
Methods
Methods
add
Syntax
add
-
location
-
resources
-
[callback]
Summary
Adds resources to the storage.Parameters:
-
location
StringThe storage location where the resource will be added
-
resources
ArrayThe list of resources to store
-
[callback]
Function optionalThe function to call when it's done
- Error The error if an error occurred, null otherwise
- Number The total amount of resources inserted
- Array The list of inserted resources
close
Syntax
close
-
callback
Summary
Closes connection to the database.
Parameters:
-
callback
FunctionThe function to call when connection is closed
- Error The error if an error occurred, null otherwise
connect
Syntax
connect
-
callback
Summary
Establishes connection to the database.
Parameters:
-
callback
FunctionThe function to call when connection to the database is established
- Error The error if an error occurred, null otherwise
createIndexes
Syntax
createIndexes
-
collection
-
indexes
-
callback
Summary
Creates indexes for a collection.
dropIndex
Syntax
dropIndex
-
collection
-
indexName
-
callback
Summary
Drops index from a collection.
get
Syntax
get
-
location
-
[filter]
-
[fields]
-
[limit]
-
[page]
-
[sort]
-
callback
Summary
Fetches resources from the storage.Parameters:
-
location
StringThe storage location where to search for resources
-
[filter]
ResourceFilter optionalRules to filter resources
-
[fields]
Object optionalExpected resource fields to be included or excluded from the response, by default all fields are returned. Only "exclude" or "include" can be specified, not both
-
[limit]
Number optionalA limit number of resources to retrieve (10 by default)
-
[page]
Number optionalThe page number started at 0 for the first page
-
[sort]
Object optionalThe list of fields to sort by with the field name as key and the sort order as value (e.g. {field1: 'asc', field2: 'desc'})
-
callback
FunctionThe function to call when it's done
- Error The error if an error occurred, null otherwise
- Array The list of retrieved resources
- Object Pagination information
- Number limit The specified limit
- Number page The actual page
- Number pages The total number of pages
- Number size The total number of resources
getIndexes
Syntax
getIndexes
-
collection
-
callback
Summary
Gets the list of indexes for a collection.
getOne
Syntax
getOne
-
location
-
[filter]
-
[fields]
-
callback
Summary
Fetches a single resource from the storage.Parameters:
-
location
StringThe storage location where to search for the resource
-
[filter]
ResourceFilter optionalRules to filter resources
-
[fields]
Object optionalExpected resource fields to be included or excluded from the response, by default all fields are returned. Only "exclude" or "include" can be specified, not both
-
callback
FunctionThe function to call when it's done
- Error The error if an error occurred, null otherwise
- Object The resource
getStore
Syntax
getStore
-
collection
Summary
Gets an express-session store for the database.
Parameters:
-
collection
StringThe collection to work on
Returns:
An express-session store
remove
Syntax
remove
-
location
-
filter
-
[callback]
Summary
Removes resources from the storage.Parameters:
-
location
StringThe storage location where to find the resources to remove
-
filter
ResourceFilterRules to filter resources to remove
-
[callback]
Function optionalThe function to call when it's done
- Error The error if an error occurred, null otherwise
- Number The number of removed resources
removeCollection
Syntax
removeCollection
-
collection
-
callback
Summary
Removes a collection from the database.
removeField
Syntax
removeField
-
location
-
field
-
[filter]
-
[callback]
Summary
Removes a field from resources of a storage location.Parameters:
-
location
StringThe storage location where to find the resources
-
field
StringThe field to remove from resources
-
[filter]
ResourceFilter optionalRules to filter resources to update
-
[callback]
Function optionalThe function to call when it's done
- Error The error if an error occurred, null otherwise
- Number The number of updated resources
renameCollection
Syntax
renameCollection
-
collection
-
target
-
callback
Summary
Renames a collection.
updateOne
Syntax
updateOne
-
location
-
filter
-
data
-
[callback]
Summary
Updates a resource in the storage.Parameters:
-
location
StringThe storage location where to find the resource to update
-
filter
ResourceFilterRules to filter the resource to update
-
data
ObjectThe modifications to perform
-
[callback]
Function optionalThe function to call when it's done
- Error The error if an error occurred, null otherwise
- Number 1 if everything went fine