Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Queryable<TDocument>

label

COMMON

interface

Queryable

description

This concern requires the presence of fields that consist in delivering queryable information.

example

Extending and using the Queryable

 import { Queryable } from "./Queryable";

export class ExampleQuery extends Queryable<ExampleDocument> {
public constructor(
document?: ExampleDocument,
queryParams: QueryParameters = undefined,
) {
super(document, queryParams);
}
}
since

v0.2.0

Type Parameters

Hierarchy

Implements

Index

Constructors

  • new Queryable<TDocument>(document?: TDocument, __namedParameters?: QueryParameters, filterQuery?: FilterQuery<TDocument>): Queryable<TDocument>
  • Copy constructor for pageable generic queries. The query parameters that are optionally passed to this method are used to mimic a copy construction logic and set default parameters for the query given any of these is undefined.

    Destructured query parameters include:

    • pageNumber: The page number of the query (defaults to 1).
    • pageSize: The number of entities/documents in one page (defaults to 20).
    • sort: The field used for sorting (defaults to "_id").
    • order: The sorting direction, must be one of "asc" and "desc" (defaults to "asc")

    Type Parameters

    Parameters

    • Optional document: TDocument

      The document instance (defaults to undefined).

    • __namedParameters: QueryParameters = ...
    • Optional filterQuery: FilterQuery<TDocument>

    Returns Queryable<TDocument>

Properties

document?: TDocument

The document entry used as a filter. This property can be used to query documents by equality of fields.

Note that queries with more complex operators must use the filterQuery property instead and leave this one blank.

example

Setting a document

 document: {} as Document
document: { field: value } as Document
access

public

var

{TDocument}

filterQuery?: FilterQuery<TDocument>

The custom filter query that must be used. This property can be used to filter results using enhanced mongodb operators, including: $ne, $in, $gte, $lte, etc.

Note that queries that use only the equality operator can use the document property as well which removes the need to specify the operators (always uses equality).

example

Setting a filterQuery

 filterQuery: {
$ne: { field: value },
$gte: { otherField: otherValue }
} as FilterQuery<Document>
access

public

var

{FilterQuery}

order: string

Determines the order direction that is being requested. This will define the order direction of results that are returned.

Possible values are:

  • "asc": Sorts the results in ascending order, i.e. "first in, first out".
  • "desc": Sorts the results in descendeing order, i.e. "last in, first out".

example

Setting a order direction

 order: "asc"
order: "desc"
access

public

see

{Sortable}

var

{string}

pageNumber: number

Determines the page number that is being requested. This will also define the offset of results that are returned.

example

Setting a pageNumber

 pageNumber: 3
access

public

see

{Pageable}

var

{number}

pageSize: number

Determines the page size that is being requested. This will also define the maximum number of results that are returned.

example

Setting a document

 pageSize: 100
access

public

see

{Pageable}

var

{number}

sort: string

Determines the sort field that is being requested. This will define the field used to sort results that are returned.

example

Setting a sort field name

 sort: "address"
access

public

see

{Sortable}

var

{string}

Methods

  • forDocument(): Record<string, unknown>
  • This method must return an object that can be used as the value for the mongodb find operations to represent one document. Typically, this method returns an object where keys are the primary key(s) of the entity and values are those of the document represented by the current instance.

    Returns Record<string, unknown>

    The individual document data that is used in a query.

  • getDocument(): TDocument
  • This method implements the getter logic for the current queryable document. Typically, the document property contains an individual document with primary keys set.

    Returns TDocument

  • setDocument(document: TDocument): Queryable<TDocument>

Generated using TypeDoc