Page Contents

Home > @loopback/filter > FilterBuilder

FilterBuilder class

A builder for Filter. It provides fleunt APIs to add clauses such as fields, order, where, limit, offset, and include.


export declare class FilterBuilder<MT extends object = AnyObject> 


const filterBuilder = new FilterBuilder();
const filter = filterBuilder
  .fields('id', 'a', 'b')
  .order(['a ASC', 'b DESC'])
  .where({id: 1})


Constructor Modifiers Description
(constructor)(f)   Constructs a new instance of the FilterBuilder class


Property Modifiers Type Description
filter   Filter<MT>  


Method Modifiers Description
build()   Return the filter object
fields(f)   Describe what fields to be included/excluded
impose(constraint)   Add a Filter or Where constraint object. If it is a filter object, create an and clause for conflicting keys with its where object. For any other properties, throw an error. If it’s not a Filter, coerce it to a filter, and carry out the same logic.
include(i)   Declare include
limit(limit)   Set limit
offset(offset)   Set offset
order(o)   Describe the sorting order
skip(skip)   Alias to offset
where(w)   Declare a where clause