Class ModelBuilder<T>

Implementation of the abstract builder whose results yield instances of a given Model, T.

Type Parameters

Hierarchy

Constructors

Properties

ModelClass: Function & {
    prototype: T;
} & (new (...args: any[]) => T) & typeof Model & Instantiable<T>

The model class that is created for results of this query.

appliedScopes: Collection<{
    accessor: string | Instantiable<Scope>;
    scope: ScopeClosure;
}> = ...
constraints: Constraint[] = []

Constraints applied to this query.

databaseService: DatabaseService
eagerLoadRelations: (keyof T)[] = []
rawSql?: string

Raw SQL to use instead. Overrides builder methods.

registeredConnection?: Connection

The connection on which the query should be executed.

registeredDistinct: boolean = false

If true, the query should refer to distinct records.

registeredFields: SpecifiedField[] = []

The fields to query from the table.

registeredGroupings: string[] = []

Array of SQL group-by clauses.

registeredOrders: OrderStatement[] = []

Array of SQL order-by clauses.

registeredSkip?: number

The number of records to skip before the result set.

registeredTake?: number

The max number of records to include in the result set.

source?: QuerySource

The source table to query from.

Accessors

  • get appliedGroupings(): string[]
  • Get the SQL group-by clauses applied to this query.

    Returns string[]

  • get appliedPagination(): {
        skip: undefined | number;
        take: undefined | number;
    }
  • Get the skip/take values of this query.

    Returns {
        skip: undefined | number;
        take: undefined | number;
    }

    • skip: undefined | number
    • take: undefined | number

Methods

  • Get the method with the given name from this class, bound to this class.

    Returns

    function

    Parameters

    • methodName: string

    Returns ((...args: any[]) => any)

      • (...args: any[]): any
      • Get the method with the given name from this class, bound to this class.

        Returns

        function

        Parameters

        • Rest ...args: any[]

        Returns any

  • Insert the given rows into the table for this query, returning the fields specified in this query.

    Example

    const rows = [
    { name: 'A' },
    { name: 'B' },
    ]

    query.table('my_table')
    .returning('id', 'name')
    .insert(rows)

    This is equivalent to:

    INSERT INTO my_table (name)
    VALUES ('A'), ('B')
    RETURNING id, name

    Parameters

    Returns Promise<QueryResult>

  • Call the make() method on the global container.

    Type Parameters

    • T

    Parameters

    • target: any
    • Rest ...parameters: any[]

    Returns T

  • Run a batch update on all rows matched by this query, setting the values for discrete rows based on some key.

    This is a more efficient way of combining discrete update queries.

    Example

    query.table('my_table')
    .updateMany('id_col', [
    {id_col: 1, val1_col: 'a'},
    {id_col: 2, val2_col: 'b'},
    ])

    This will set the val1_col to a for rows where id_col is 1 and so on.

    Parameters

    Returns Promise<QueryResult>