Page Contents

Home > @loopback/repository > WhereBuilder

WhereBuilder class

A builder for Where object. It provides fluent APIs to add clauses such as and, or, and other operators.

Signature:

export declare class WhereBuilder<MT extends object = AnyObject> 

Constructors

Constructor Modifiers Description
(constructor)(w)   Constructs a new instance of the WhereBuilder class

Properties

Property Modifiers Type Description
where   Where<MT>  

Methods

Method Modifiers Description
and(w)   Add an and clause.
between(key, val1, val2)   Add a between condition
build()   Get the where object
cast(clause)    
eq(key, val)   Add an = condition
exists(key, val)   Add a exists condition
gt(key, val)   Add a > condition
gte(key, val)   Add a >= condition
impose(where)   Add a where object. For conflicting keys with the existing where object, create an and clause.
inq(key, val)   Add a inq condition
lt(key, val)   Add a < condition
lte(key, val)   Add a <= condition
neq(key, val)   Add a != condition
nin(key, val)   Add a nin condition
or(w)   Add an or clause.

Example

const whereBuilder = new WhereBuilder();
const where = whereBuilder
  .eq('a', 1)
  .and({x: 'x'}, {y: {gt: 1}})
  .and({b: 'b'}, {c: {lt: 1}})
  .or({d: 'd'}, {e: {neq: 1}})
  .build();