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.

Signature:

export declare class FilterBuilder<MT extends object = AnyObject> 

Example

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

Constructors

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

Properties

Property Modifiers Type Description
filter   Filter<MT>  

Methods

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