Options
All
  • Public
  • Public/Protected
  • All
Menu

Class QueryBuilder

Helper function to easily generate queries

example

Simple example showing a basic set of where's (&& together) to get documents with a value between (inclusive) 40 and 50

const query = QueryBuilder
  .where('myKey', '>=' 40)
  .where('myKey', '<=', 50)
example

Using the orWhere function to generate OR queries

const query = QueryBuilder
  .orWhere(or => or
    .where('myKey', '===', true)
    .where('mySecondKey', '===', 52, true)
  )
-- The equivalent SQL query would be as follows --
SELECT
  *
FROM
  collection
WHERE
  myKey = TRUE
  AND mySecondKey != 52
example

Nested AND queries in an OR query

const query = QueryBuilder
  .orWhere(or => or
    .andWhere(
      and => and
        .where('key1', '===', 21)
        .where('key2', '===', 'boop')
    )
    .andWhere(
      and => and
        .where('key3', '>=', 1)
        .where('key4', '<=', 100)
    )
  )
// The above is kind of like the following if statement
if(
  (
    key1 === 21 &&
    key2 === 'boop'
  ) ||
  (
    key3 >= 1 &&
    key4 <= 100
  )
)
-- Or like the following SQL query --
SELECT
  *
FROM
  collection
WHERE
  (
    key1 = 21
    AND key2 = 'boop'
  )
  OR (
    key3 >= 1
    AND key4 <= 100
  )

Hierarchy

  • QueryBuilder

Index

Constructors

Properties

Methods

Constructors

constructor

Properties

queries

queries: Query[] = []

Methods

andWhere

  • Generate && queries for nesting within || queries

    Parameters

    • queryFunc: WhereCallback

      callback for generating queries with a nested QueryBuilder

    Returns QueryBuilder

orWhere

  • Generate a nested || query

    Parameters

    • queryFunc: WhereCallback

      callback for generating || queries with a nested QueryBuilder

    Returns QueryBuilder

where

  • where(key: string, operation: Operators, comparison: any, inverse?: boolean): QueryBuilder
  • Generate a new query for the array

    Parameters

    • key: string

      Key to search on (run through nestedKey function)

    • operation: Operators

      Comparison operation to use

    • comparison: any

      What to compare against

    • inverse: boolean = false

      Inverse the result of the where query

    Returns QueryBuilder

Static andWhere

  • Generate && queries for nesting within || queries

    Parameters

    • queryFunc: WhereCallback

      callback for generating queries with a nested QueryBuilder

    Returns QueryBuilder

Static orWhere

  • Generate a nested || query

    Parameters

    • queryFunc: WhereCallback

      callback for generating || queries with a nested QueryBuilder

    Returns QueryBuilder

Static where

  • where(key: string, operation: Operators, comparison: any, inverse?: boolean): QueryBuilder
  • Generate a new query for the array

    Parameters

    • key: string

      Key to search on (run through nestedKey function)

    • operation: Operators

      Comparison operation to use

    • comparison: any

      What to compare against

    • inverse: boolean = false

      Inverse the result of the where query

    Returns QueryBuilder

Generated using TypeDoc