Options
All
  • Public
  • Public/Protected
  • All
Menu

Type parameters

  • T

Hierarchy

  • QueryBuilder

Index

Constructors

constructor

Methods

average

  • average(key: string): Promise<number>
  • Returns the average of all the values for the given key.

    Parameters

    • key: string

    Returns Promise<number>

count

  • count(): Promise<number>
  • Returns the number of documents matching the given query.

    Example

    const numberOfPayingCustomers = await Customer.where('hasPaidTheLastInvoice', true).count();
    

    Returns Promise<number>

create

  • create(attributes: {}): Promise<string>
  • Creates a new document with the given attributes.

    internal

    Parameters

    • attributes: {}
      • [index: string]: any

    Returns Promise<string>

delete

  • delete(): Promise<number>
  • Deletes the Models matching the current query options.

    Returns Promise<number>

    Returns the number of models deleted.

find

  • find(id: string): Promise<T | null>
  • Returns the model with the given id or null if there is no matching model.

    Parameters

    • id: string

    Returns Promise<T | null>

findOne

  • findOne(query: Query): Promise<T | null>
  • Returns the first model matching the query options.

    internal

    Parameters

    Returns Promise<T | null>

first

  • first(): Promise<T | null>
  • Returns the first model matching the query options.

    Returns Promise<T | null>

get

  • get(): Promise<T[]>
  • Returns an array of models matching the query options.

    Returns Promise<T[]>

limit

  • Limits the number of models returned.

    Parameters

    • length: number

    Returns QueryBuilder<T>

max

  • max(key: string): Promise<number>
  • Returns the largest value for the given key.

    Parameters

    • key: string

    Returns Promise<number>

min

  • min(key: string): Promise<number>
  • Returns the smallest value for the given key.

    Parameters

    • key: string

    Returns Promise<number>

orderBy

  • orderBy(key: string, order?: "asc" | "desc"): QueryBuilder<T>
  • Sorts the models by the given key.

    Parameters

    • key: string

      The key you want to sort by.

    • Default value order: "asc" | "desc" = "asc"

      Defaults to ascending order.

    Returns QueryBuilder<T>

percentile

  • percentile(key: string, n: number): Promise<number>
  • Returns the nth percentile of all the values for the given key.

    Parameters

    • key: string
    • n: number

    Returns Promise<number>

pluck

  • pluck(...keys: string[]): Promise<any[]>
  • The pluck method retrieves all of the values for a given key.

    You may also specify how you wish the resulting collection to be keyed.

    Example

    await Posts.where('categoryId', 2).pluck('id');
    // => [ '1', '2', '3' ]
    
    await Products.where('size', 'large').pluck('price', 'name');
    // => [ { name: 'Shirt 1', price: 14.99 } ]
    

    Parameters

    • Rest ...keys: string[]

    Returns Promise<any[]>

save

  • Persist the provided attributes.

    internal

    Parameters

    Returns Promise<string>

sum

  • sum(key: string): Promise<number>
  • Returns the sum of all the values for the given key.

    Parameters

    • key: string

    Returns Promise<number>

where

  • Adds a constraint to the current query.

    oaram

    value

    Parameters

    Returns QueryBuilder<T>

  • Parameters

    • key: string
    • value: any

    Returns QueryBuilder<T>

whereIn

  • whereIn(fieldName: string, values: any[]): QueryBuilder<T>
  • Returns all the models with fieldName in the array of values.

    Parameters

    • fieldName: string
    • values: any[]

    Returns QueryBuilder<T>

Legend

  • Constructor
  • Property
  • Method

Generated using TypeDoc