Documentation
    Preparing search index...

    A fluent interface for building and executing database queries across all backend adapters. Manages filters, sort orders, and pagination limits dynamically.

    const query = new Query(User);
    query.where('status', 'active').sortBy('createdAt', 'desc').batch(20);
    const results = await query.execute(returnAs.AS_INSTANCES);

    Type Parameters

    Index

    Constructors

    Properties

    _obj: T
    _parent: T | undefined
    filters: Filter[]

    Array of instantiated Filter objects defining the query conditions.

    limits: Limits

    Pagination rules defining limits, batches, and offsets.

    meta: any

    Execution metadata populated by the backend after fetching (e.g. total count, execution time).

    sortings: Sorting[]

    Array of Sorting conditions dictating the order of returned results.

    Accessors

    • get obj(): T

      Returns T

    • get parent(): T | undefined

      Returns T | undefined

    • set parent(parent: T | undefined): void

      Declare query parent record This may be need in some NoSQL backend to query subcollections

      Parameters

      • parent: T | undefined

      Returns void

    Methods

    • Executes an average aggregation query on the target property.

      Parameters

      • property: string

        The name of the numeric property to average.

      • backend: BackendInterface = ...

        The backend adapter to query against. Defaults to the global default backend.

      Returns Promise<number>

      A promise resolving to the average of the property values.

    • Sets the maximum number of records to return (batch size).

      Parameters

      • batch: number = 10

        The limit of records to fetch. Defaults to 10.

      Returns Query<T>

      The query instance for chaining.

    • Executes a count aggregation query.

      Parameters

      • backend: BackendInterface = ...

        The backend adapter to query against. Defaults to the global default backend.

      Returns Promise<number>

      A promise resolving to the count of matching items.

    • Executes a distinct aggregation query on the target property.

      Parameters

      • property: string

        The name of the property.

      • backend: BackendInterface = ...

        The backend adapter to query against. Defaults to the global default backend.

      Returns Promise<any[]>

      A promise resolving to an array of unique values.

    • Primary execution handler for the query. Transforms the output based on the requested returnAs format.

      Parameters

      • as: returnAs = returnAs.AS_DATAOBJECTS

        The desired output format (AS_DATAOBJECTS, AS_OBJECTURIS, or AS_INSTANCES).

      • backend: BackendInterface = ...

        The backend adapter to query against.

      Returns Promise<QueryResultType<any>>

      A promise resolving to the query results in the specified format.

      If an unknown output mode is requested.

    • Internal: Executes the query against the backend and returns raw DataObjectClass wrappers.

      Parameters

      • backend: BackendInterface = ...

        The backend adapter to query against. Defaults to the global default backend.

      Returns Promise<QueryResultType<DataObjectClass<any>>>

      A promise resolving to the raw DataObject results and execution metadata.

    • Executes the query and fully hydrates the results into instances of the target class. This is the standard data retrieval path for applications.

      Parameters

      Returns Promise<QueryResultType<T>>

      A promise resolving to an array of fully instantiated model classes.

    • Executes the query and returns only the ObjectUri references of the matching records. Efficient for relational operations where full object hydration is unnecessary.

      Parameters

      Returns Promise<QueryResultType<ObjectUri>>

      A promise resolving to an array of URIs.

    • Executes a maximum aggregation query on the target property.

      Parameters

      • property: string

        The name of the property.

      • backend: BackendInterface = ...

        The backend adapter to query against. Defaults to the global default backend.

      Returns Promise<number | undefined>

      A promise resolving to the maximum value found, or undefined.

    • Executes a minimum aggregation query on the target property.

      Parameters

      • property: string

        The name of the property.

      • backend: BackendInterface = ...

        The backend adapter to query against. Defaults to the global default backend.

      Returns Promise<number | undefined>

      A promise resolving to the minimum value found, or undefined.

    • Sets the starting offset for pagination.

      Parameters

      • offset: number = 0

        The number of records to skip before returning results. Defaults to 0.

      Returns Query<T>

      The query instance for chaining.

    • Directly assigns a preconfigured Limits object for pagination.

      Parameters

      • limits: Limits

        The Limits pagination configuration.

      Returns Query<T>

      The query instance for chaining.

    • Updates the parent property of the current object. This method is useful for SQL backends where a model may have two parent records and requires dynamically setting the name of one of them.

      Parameters

      • parent: string

      Returns void

    • Specifies a sorting rule for the query results.

      Parameters

      • param: string | Sorting

        The Sorting object or the string name of the field to sort by.

      • order: any = 'asc'

        The direction of the sort: 'asc' or 'desc'.

      Returns Query<T>

      The query instance for chaining.

    • Executes a sum aggregation query on the target property.

      Parameters

      • property: string

        The name of the numeric property to sum.

      • backend: BackendInterface = ...

        The backend adapter to query against. Defaults to the global default backend.

      Returns Promise<number>

      A promise resolving to the sum of the property values.

    • Appends a new filter condition to the query. Can accept an instantiated Filter object or raw field parameters.

      Parameters

      • param: any

        The Filter object or the string name of the field to filter on.

      • value: any = null

        The value to match (ignored if param is a Filter).

      • operator: OperatorKeys = OperatorKeys.equals

        The OperatorKeys comparison operator (e.g., equals, gt, lt). Defaults to equals.

      Returns Query<T>

      The query instance for chaining.