Options
All
  • Public
  • Public/Protected
  • All
Menu

Class QuerySelect

A 'select' query is used to retrieve records from one or more tables. The query does support multiple tables but those need to be related (joined). Optional filter can be set for each table used on the query.

since

1.1.0

Hierarchy

  • QuerySelect

Index

Constructors

constructor

  • new QuerySelect(conn: Connection, table: string, filter?: Filter, offset?: number, limit?: number): QuerySelect
  • Creates a select query for one or more tables of an API connection.

    Parameters

    • conn: Connection
    • table: string

      The name of the table to select the records from.

    • Optional filter: Filter

      The filter condition for the table.

    • Optional offset: number
    • Optional limit: number

    Returns QuerySelect

Accessors

tables

  • The information on tables used on this query.

    Returns ISelectTable[]

Methods

all

  • all(timeout?: number): Promise<Record[]>
  • Asynchronously executes the select query and, when fulfilled, returns all the rows that satisfy the filter condition.

    Parameters

    • Optional timeout: number

      The query execution timeout (milliseconds).

    Returns Promise<Record[]>

build

count

  • count(timeout?: number): Promise<number>
  • Asynchronously executes the select query and, when fulfilled, returns the number of rows that satisfy the filter condition.

    Parameters

    • Optional timeout: number

      The query execution timeout (milliseconds).

    Returns Promise<number>

fields

  • Specify the fields to retrieve for the last table addted to the query. Field information can be just the name or a structure with name, alias and extent where only the name is mandatory.

    To select all fields the wildcard character ('*') can be used.

    If the the extent information is set, either in the field structure or inside the name using the square bracket notation (MonthQuota[2]), then only that entry from the array field is retrieved otherwise all values are returned as an array.

    Parameters

    • field: string | ISelectField | Array<string | ISelectField>

      At least one field information is required.

    • Rest ...fields: (string | ISelectField)[]

      Extra entries with field information.

    Returns QuerySelect

filter

  • Set additional filter for the last table added to the query.

    Parameters

    • filter: Filter

      The filter condition to set on the table

    Returns QuerySelect

    Returns the current query instance (fluent interface).

join

  • Joins another table to the query.

    Parameters

    • table: string

      The name of the joined table.

    • parent: string

      The parent table to join on.

    • Optional mode: SelectionMode
    • Optional outer: boolean
    • Optional alias: string
    • Optional filter: Filter
    • Optional joinMap: QueryJoinMap

    Returns QuerySelect

    Returns the current query instance (fluent interface).

limit

  • Set the maximum number of records selected when pagination is used.

    Parameters

    • limit: number

      The select limit, must be greater or equal to one.

    Returns QuerySelect

    Returns the current query instance (fluent interface).

offset

  • Set the start offset when pagination is used.

    Parameters

    • offset: number

      The start offset, must be greater or equal to one.

    Returns QuerySelect

    Returns the current query instance (fluent interface).

on

  • on(parentField: string, childField?: string): QuerySelect
  • Adds an additional field mapping for the last table joined to the query.

    Parameters

    • parentField: string

      The name of the field in the parent table.

    • Optional childField: string

    Returns QuerySelect

    Returns the current query instance (fluent interface).

open

  • open(preselect?: boolean, timeout?: number): Promise<Query>
  • Open a query for sequential data access (fetch one row at a time).

    Parameters

    • Default value preselect: boolean = false
    • Optional timeout: number

      The query execution timeout (milliseconds).

    Returns Promise<Query>

    The query object that can be used to navigate through the records.

sort

  • Specify the sort order for records selection. Each sort field information can be either a string - the field name or an object with a single property and a logical value (true for descending). When only the field name is specified the sort order is ascending.

    Parameters

    • field: string | SelectSort | Array<string | SelectSort>

      At least one sort field information is required.

    • Rest ...fields: (string | object)[]

      Extra entries with sort field information.

    Returns QuerySelect

Static execute

  • execute(connection: Connection, query: IQuerySelect, timeout?: number): Promise<Record[]>
  • Asynchronously executes a select query and, when fulfilled, returns all the rows that satisfy the filter condition.

    Parameters

    • connection: Connection

      An open connection on which the query is to be executed.

    • query: IQuerySelect

      The select query to execute.

    • Optional timeout: number

      The query execution timeout (milliseconds).

    Returns Promise<Record[]>