Options
All
  • Public
  • Public/Protected
  • All
Menu

Class GetOperation<T>

This operation gets objects from the database.

Usage

See Datastore.get.

Type parameters

  • T: Model<T>

    The model of the Datastore. T must extend from Model.

Hierarchy

  • GetOperation

Implements

Index

Constructors

constructor

Properties

Private _filter

_filter: FilterOperator<T> = null

Filter data to use. Defaults to null - do not filter.

Private _sort

_sort: SortOperator<T> = null

Sorting data to use. Defaults to null - do not sort.

Private store

store: Datastore<T>

The datastore where the operation takes place.

Methods

count

  • count(): Promise<number>

filter

  • Set the filtering method.

    Usage

    const store = new Datastore<Human>(...)
    const items = await store.get().filter((human) => human.age > 18).run()
    console.log(items)

    Parameters

    • method: function

      Filtering method to use. method is a user-defined callback, and it is fired on every object in the database. If the callback returns true, object is said to 'pass' the filter, and is added to the final list.

        • Parameters

          Returns boolean

    Returns GetOperation<T>

    Returns this operation again, to make chaining methods possible.

first

  • first(): Promise<T>

last

  • last(): Promise<T>

orderBy

paginate

result

  • result(): Promise<T[]>

run

  • run(): Promise<T[]>
  • Runs the operation.

    Returns Promise<T[]>

    Array of objects that are filtered (if you have set the filter), sorted (if you have set the sorting data) and paginated (if you have set the pagination data).

skip

sort

  • Set the sorting method.

    Usage

    const store = new Datastore<Human>(...)
    const items = await store.get().sort({age: {sort: SortDirection.Ascending}}).run()
    console.log(items)

    Parameters

    • data: ISort<T>

      Sorting method to use. method must be a type of ISort<T>.

    Returns GetOperation<T>

    Returns this operation again, to make chaining methods possible.

take

where

Object literals

Private _pagination

_pagination: object

Pagination data to use. Defaults to {skip: 0, take: Infinity}

skip

skip: number = 0

take

take: number = Infinity

Generated using TypeDoc