EntityProvider
Summary
Defines a provider holding a single type of resources.
An entity provider manages a single type of resources. These resources are stored into the given storage / location.
Constructor
Item Index
Methods
Methods
add
Syntax
add
-
entities
-
[callback]
Summary
Adds entities.
executeCallback
Syntax
executeCallback
-
[callback]
-
[error]
-
[callback]
Summary
Executes the given callback or log the error message if no callback specified. It assumes that the second argument is the error. All arguments, except the callback itself, will be specified as arguments when executing the callback.get
Syntax
get
-
[filter]
-
[fields]
-
[limit]
-
[page]
-
[sort]
-
callback
Summary
Fetches entities.
Parameters:
-
[filter]
ResourceFilter optionalRules to filter entities
-
[fields]
Object optionalFields 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 entities 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', field3: 'score'})
-
callback
FunctionThe function to call when it's done
- Error The error if an error occurred, null otherwise
- Array The list of retrieved entities
- 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 entities
getAll
Syntax
getAll
-
[filter]
-
[fields]
-
sort
-
callback
Summary
Gets all entities from storage iterating on all pages.
Parameters:
-
[filter]
ResourceFilter optionalRules to filter entities
-
[fields]
Object optionalFields to be included or excluded from the response, by default all fields are returned. Only "exclude" or "include" can be specified, not both
-
sort
ObjectThe list of fields to sort by with the field name as key and the sort order as value (e.g. {field1: 'asc', field2: 'desc', field3: 'score'})
-
callback
FunctionFunction to call when it's done with:
- Error An error if something went wrong, null otherwise
- Array The list of entities
getOne
Syntax
getOne
-
[filter]
-
[fields]
-
callback
Summary
Fetches an entity.
If filter corresponds to more than one entity, the first found entity will be the returned one.
Parameters:
-
[filter]
ResourceFilter optionalRules to filter entities
-
[fields]
Object optionalFields 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 entity
remove
Syntax
remove
-
[filter]
-
[callback]
Summary
Removes entities.
Parameters:
-
[filter]
ResourceFilter optionalRules to filter entities 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 entities
removeField
Syntax
removeField
-
field
-
[filter]
-
[callback]
Summary
Removes a field from entities.
Parameters:
-
field
StringThe field to remove from entities
-
[filter]
ResourceFilter optionalRules to filter entities 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 entities
updateOne
Syntax
updateOne
-
[filter]
-
data
-
[callback]
Summary
Updates an entity.
Parameters:
-
[filter]
ResourceFilter optionalRules to filter the entity 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