QueryService that wraps a store that does not support the query options natively (e.g. An in memory collection of objects such as a static array of objects).
All examples will be based on the following DTO definition.
applyFilter
TheapplyFilter helper applies a Filter to a single object or an array of objects.
Arguments
-
dto: DTO|DTO[]- If a single object a function that will test the dto against the filter, returning
truewhen if it matches the filter. - If an array of objects is provided the array will be filtered returning a new array with all elements that match the filter.
- If a single object a function that will test the dto against the filter, returning
-
filter: Filter<DTO>- The filter to check the object[s] against. SeeFiltering
Example
applySort
TheapplySort will sort an array of dtos.
Because
applySort uses the native Array#sort method it may not exactly match the ordering you would expect from a database.Arguments
dto: DTO[]- The array of DTOs to sort.sortFields: SortField<DTO>[]- The sorting criteria. SeeSorting
Example
applyPaging
TheapplyPaging method will apply a limit and/or offset to an array of dtos.
Arguments
dto: DTO[]- The array of DTOs to page.paging: Paging- The paging arguments to apply. SeePaging
Example
applyQuery
TheapplyQuery uses the applyFilter, applySorting, and applyPaging methods to apply a Query to an array of DTOs.
Arguments
dto: DTO[]- The array of DTOs to page.query: Query<DTO>- The query to apply to the array of dtos. SeeQueries
Example
transformFilter
The transformFilter is used to remap fields in aFilter. This method is commonly used when defining a custom Assembler.
Arguments
filter: Filter<From>- The filter you want to transform.fieldMap: QueryFieldMap<From, To>- A map of fields where the key is a key in the From type, and the value is a key in the to type.
Example
transformSort
ThetransformSort is used to remap fields in an array of SortField<DTO>[]. This method is commonly used when defining a custom Assembler.
Arguments
sortFields: SortField<From>[]- The array of sorting criteria to transform.fieldMap: QueryFieldMap<From, To>- A map of fields where the key is a key in the From type, and the value is a key in the to type.
Example
transformQuery
ThetransformQuery method uses the transformFilter and transformSort methods to remap a Query. This method is commonly used when defining a custom Assembler.
Arguments
sortFields: Query<From>- The query to transform.fieldMap: QueryFieldMap<From, To>- A map of fields where the key is a key in the From type, and the value is a key in the to type.
Example
getFilterComparisons
Used to search a filter get a list of comparison objects for a given key.Arguments
filter: Filter<DTO>- The filter to search.key: keyof DTO- The key in the DTO object to search for in the filter object.
Example
getFilterOmitting
Used to get a filter with a given key removed.Arguments
filter: Filter<DTO>- The filter containing the unwanted key.key: keyof DTO- The key in the DTO object to remove in the filter object.