Skip to main content
Version: Next

RunQueryBuilder <Entity>

Hierarchy

Index

Properties

inheritedalias

alias: string

inheritedhelper

helper: QueryBuilderHelper

inheritedmainAlias

mainAlias: Alias<Entity>

Methods

inheritedaddSelect

inheritedandHaving

inheritedandWhere

  • andWhere(cond: QBFilterQuery<Entity>): this
  • andWhere(cond: string, params?: any[]): this
  • Parameters

    Returns this

inheritedapplyFilters

  • Apply filters to the QB where condition.


    Parameters

    Returns Promise<void>

inheritedas

  • as(alias: string): QueryBuilder<any, any>
  • Returns knex instance with sub-query aliased with given alias. You can provide EntityName.propName as alias, then the field name will be used based on the metadata


    Parameters

    • alias: string

    Returns QueryBuilder<any, any>

inheritedcache

  • cache(config?: number | boolean | [string, number]): this
  • Parameters

    • config: number | boolean | [string, number] = true

    Returns this

inheritedclone

  • clone(reset?: boolean | string[]): QueryBuilder<Entity, never, never, never>
  • Parameters

    • optionalreset: boolean | string[]

    Returns QueryBuilder<Entity, never, never, never>

inheritedcomment

  • comment(comment: string | string[]): this
  • Prepend comment to the sql query using the syntax /* ... *&#8205;/. Some characters are forbidden such as /*, *&#8205;/ and ?.


    Parameters

    • comment: string | string[]

    Returns this

inheritedcount

  • count(field?: EntityKeyOrString<Entity> | EntityKeyOrString<Entity>[], distinct?: boolean): CountQueryBuilder<Entity>
  • Parameters

    • optionalfield: EntityKeyOrString<Entity> | EntityKeyOrString<Entity>[]
    • distinct: boolean = false

    Returns CountQueryBuilder<Entity>

inheriteddelete

inheriteddistinct

inheriteddistinctOn

  • distinctOn(fields: EntityKeyOrString<Entity> | EntityKeyOrString<Entity>[]): SelectQueryBuilder<Entity, any, any, never>
  • postgres only


    Parameters

    • fields: EntityKeyOrString<Entity> | EntityKeyOrString<Entity>[]

    Returns SelectQueryBuilder<Entity, any, any, never>

execute

  • execute(method?: get | all | run, mapResults?: boolean): Promise<Result>
  • Executes this QB and returns the raw results, mapped to the property names (unless disabled via last parameter). Use method to specify what kind of result you want to get (array/single/meta).


    Parameters

    • optionalmethod: get | all | run
    • optionalmapResults: boolean

    Returns Promise<Result>

inheritedfrom

  • Specifies FROM which entity's table select/update/delete will be executed, removing all previously set FROM-s. Allows setting a main string alias of the selection data.


    Parameters

    • target: QueryBuilder<Entity, never, never, never>
    • optionalaliasName: string

    Returns SelectQueryBuilder<Entity, any, any, never>

inheritedgetCount

  • getCount(field?: EntityKeyOrString<Entity> | EntityKeyOrString<Entity>[], distinct?: boolean): Promise<number>
  • Executes count query (without offset and limit), returning total count of results


    Parameters

    • optionalfield: EntityKeyOrString<Entity> | EntityKeyOrString<Entity>[]
    • optionaldistinct: boolean

    Returns Promise<number>

inheritedgetFormattedQuery

  • getFormattedQuery(): string
  • Returns raw interpolated query string with all the parameters inlined.


    Returns string

inheritedgetKnex

  • getKnex(processVirtualEntity?: boolean): QueryBuilder<any, any>
  • Parameters

    • processVirtualEntity: boolean = true

    Returns QueryBuilder<any, any>

inheritedgetKnexQuery

  • getKnexQuery(processVirtualEntity?: boolean): QueryBuilder<any, any>
  • Parameters

    • processVirtualEntity: boolean = true

    Returns QueryBuilder<any, any>

inheritedgetLoggerContext

  • getLoggerContext(): T
  • Gets logger context for this query builder.


    Returns T

inheritedgetParams

  • getParams(): readonly Value[]
  • Returns the list of all parameters for this query.


    Returns readonly Value[]

inheritedgetQuery

  • getQuery(): string
  • Returns the query with parameters as wildcards.


    Returns string

inheritedgetResultAndCount

  • getResultAndCount(): Promise<[Entity[], number]>
  • Executes the query, returning both array of results and total count query (without offset and limit).


    Returns Promise<[Entity[], number]>

inheritedgroupBy

  • groupBy(fields: EntityKeyOrString<Entity> | readonly EntityKeyOrString<Entity>[]): SelectQueryBuilder<Entity, any, any, never>
  • Parameters

    • fields: EntityKeyOrString<Entity> | readonly EntityKeyOrString<Entity>[]

    Returns SelectQueryBuilder<Entity, any, any, never>

inheritedhasFlag

  • Parameters

    Returns boolean

inheritedhaving

  • Parameters

    • cond: string | QBFilterQuery = {}
    • optionalparams: any[]
    • optionaloperator: $and | $or

    Returns SelectQueryBuilder<Entity, any, any, never>

inheritedhintComment

  • hintComment(comment: string | string[]): this
  • Add hints to the query using comment-like syntax /*+ ... *&#8205;/. MySQL and Oracle use this syntax for optimizer hints. Also various DB proxies and routers use this syntax to pass hints to alter their behavior. In other dialects the hints are ignored as simple comments.


    Parameters

    • comment: string | string[]

    Returns this

inheritedignore

  • ignore(): this
  • Returns this

inheritedindexHint

  • indexHint(sql: string): this
  • Adds index hint to the FROM clause.


    Parameters

    • sql: string

    Returns this

inheritedinnerJoin

  • innerJoin(field: QueryBuilder<any, any> | QueryBuilder<any, never, never, never> | Field, alias: Alias, cond?: QBFilterQuery, schema?: string): SelectQueryBuilder<Entity, any, any, { [ K in string ]: AddToContext<GetType<Entity, object, Field>, object, Field, Alias, false>[K] }>
  • Parameters

    • field: QueryBuilder<any, any> | QueryBuilder<any, never, never, never> | Field
    • alias: Alias
    • cond: QBFilterQuery = {}
    • optionalschema: string

    Returns SelectQueryBuilder<Entity, any, any, { [ K in string ]: AddToContext<GetType<Entity, object, Field>, object, Field, Alias, false>[K] }>

inheritedinnerJoinAndSelect

  • innerJoinAndSelect(field: Field | [field: Field, qb: QueryBuilder<any, any> | QueryBuilder<any, never, never, never>], alias: Alias, cond?: QBFilterQuery, fields?: string[], schema?: string): SelectQueryBuilder<Entity, any, any, { [ K in string ]: AddToContext<GetType<Entity, object, Field>, object, Field, Alias, true>[K] }>
  • Parameters

    • field: Field | [field: Field, qb: QueryBuilder<any, any> | QueryBuilder<any, never, never, never>]
    • alias: Alias
    • cond: QBFilterQuery = {}
    • optionalfields: string[]
    • optionalschema: string

    Returns SelectQueryBuilder<Entity, any, any, { [ K in string ]: AddToContext<GetType<Entity, object, Field>, object, Field, Alias, true>[K] }>

inheritedinnerJoinLateral

  • innerJoinLateral(field: QueryBuilder<any, any> | QueryBuilder<any, never, never, never>, alias: string, cond?: QBFilterQuery, schema?: string): this
  • Parameters

    • field: QueryBuilder<any, any> | QueryBuilder<any, never, never, never>
    • alias: string
    • cond: QBFilterQuery = {}
    • optionalschema: string

    Returns this

inheritedinnerJoinLateralAndSelect

  • innerJoinLateralAndSelect(field: [field: Field, qb: QueryBuilder<any, any> | QueryBuilder<any, never, never, never>], alias: Alias, cond?: QBFilterQuery, fields?: string[], schema?: string): SelectQueryBuilder<Entity, any, any, { [ K in string ]: AddToContext<GetType<Entity, object, Field>, object, Field, Alias, true>[K] }>
  • Parameters

    • field: [field: Field, qb: QueryBuilder<any, any> | QueryBuilder<any, never, never, never>]
    • alias: Alias
    • cond: QBFilterQuery = {}
    • optionalfields: string[]
    • optionalschema: string

    Returns SelectQueryBuilder<Entity, any, any, { [ K in string ]: AddToContext<GetType<Entity, object, Field>, object, Field, Alias, true>[K] }>

inheritedinsert

inheritedjoin

  • join(field: QueryBuilder<any, any> | QueryBuilder<any, never, never, never> | Field, alias: Alias, cond?: QBFilterQuery, type?: JoinType, path?: string, schema?: string): SelectQueryBuilder<Entity, any, any, { [ K in string ]: AddToContext<GetType<Entity, object, Field>, object, Field, Alias, false>[K] }>
  • Parameters

    • field: QueryBuilder<any, any> | QueryBuilder<any, never, never, never> | Field
    • alias: Alias
    • cond: QBFilterQuery = {}
    • type: JoinType = JoinType.innerJoin
    • optionalpath: string
    • optionalschema: string

    Returns SelectQueryBuilder<Entity, any, any, { [ K in string ]: AddToContext<GetType<Entity, object, Field>, object, Field, Alias, false>[K] }>

inheritedjoinAndSelect

  • joinAndSelect(field: Field | [field: Field, qb: QueryBuilder<any, any> | QueryBuilder<any, never, never, never>], alias: Alias, cond?: QBFilterQuery, type?: JoinType, path?: string, fields?: string[], schema?: string): SelectQueryBuilder<Entity, any, any, { [ K in string ]: AddToContext<GetType<Entity, object, Field>, object, Field, Alias, true>[K] }>
  • Parameters

    • field: Field | [field: Field, qb: QueryBuilder<any, any> | QueryBuilder<any, never, never, never>]
    • alias: Alias
    • cond: QBFilterQuery = {}
    • type: JoinType = JoinType.innerJoin
    • optionalpath: string
    • optionalfields: string[]
    • optionalschema: string

    Returns SelectQueryBuilder<Entity, any, any, { [ K in string ]: AddToContext<GetType<Entity, object, Field>, object, Field, Alias, true>[K] }>

inheritedleftJoin

  • leftJoin(field: QueryBuilder<any, any> | QueryBuilder<any, never, never, never> | Field, alias: Alias, cond?: QBFilterQuery, schema?: string): SelectQueryBuilder<Entity, any, any, { [ K in string ]: AddToContext<GetType<Entity, object, Field>, object, Field, Alias, false>[K] }>
  • Parameters

    • field: QueryBuilder<any, any> | QueryBuilder<any, never, never, never> | Field
    • alias: Alias
    • cond: QBFilterQuery = {}
    • optionalschema: string

    Returns SelectQueryBuilder<Entity, any, any, { [ K in string ]: AddToContext<GetType<Entity, object, Field>, object, Field, Alias, false>[K] }>

inheritedleftJoinAndSelect

  • leftJoinAndSelect(field: Field | [field: Field, qb: QueryBuilder<any, any> | QueryBuilder<any, never, never, never>], alias: Alias, cond?: QBFilterQuery, fields?: string[], schema?: string): SelectQueryBuilder<Entity, any, any, { [ K in string ]: AddToContext<GetType<Entity, object, Field>, object, Field, Alias, true>[K] }>
  • Parameters

    • field: Field | [field: Field, qb: QueryBuilder<any, any> | QueryBuilder<any, never, never, never>]
    • alias: Alias
    • cond: QBFilterQuery = {}
    • optionalfields: string[]
    • optionalschema: string

    Returns SelectQueryBuilder<Entity, any, any, { [ K in string ]: AddToContext<GetType<Entity, object, Field>, object, Field, Alias, true>[K] }>

inheritedleftJoinLateral

  • leftJoinLateral(field: QueryBuilder<any, any> | QueryBuilder<any, never, never, never>, alias: string, cond?: QBFilterQuery, schema?: string): this
  • Parameters

    • field: QueryBuilder<any, any> | QueryBuilder<any, never, never, never>
    • alias: string
    • cond: QBFilterQuery = {}
    • optionalschema: string

    Returns this

inheritedleftJoinLateralAndSelect

  • leftJoinLateralAndSelect(field: [field: Field, qb: QueryBuilder<any, any> | QueryBuilder<any, never, never, never>], alias: Alias, cond?: QBFilterQuery, fields?: string[], schema?: string): SelectQueryBuilder<Entity, any, any, { [ K in string ]: AddToContext<GetType<Entity, object, Field>, object, Field, Alias, true>[K] }>
  • Parameters

    • field: [field: Field, qb: QueryBuilder<any, any> | QueryBuilder<any, never, never, never>]
    • alias: Alias
    • cond: QBFilterQuery = {}
    • optionalfields: string[]
    • optionalschema: string

    Returns SelectQueryBuilder<Entity, any, any, { [ K in string ]: AddToContext<GetType<Entity, object, Field>, object, Field, Alias, true>[K] }>

inheritedlimit

  • Parameters

    • optionallimit: number
    • offset: number = 0

    Returns SelectQueryBuilder<Entity, any, any, never>

inheritedmerge

  • Parameters

    Returns this

inheritedoffset

  • Parameters

    • optionaloffset: number

    Returns SelectQueryBuilder<Entity, any, any, never>

inheritedonConflict

inheritedorderBy

inheritedorHaving

inheritedorWhere

  • orWhere(cond: QBFilterQuery<Entity>): this
  • orWhere(cond: string, params?: any[]): this
  • Parameters

    Returns this

inheritedreturning

  • returning(fields?: Field<Entity> | Field<Entity>[]): this
  • Parameters

    Returns this

inheritedselect

  • Parameters

    • fields: Field<Entity> | Field<Entity>[]
    • distinct: boolean = false

    Returns SelectQueryBuilder<Entity, any, any, never>

inheritedsetFlag

  • Parameters

    Returns this

inheritedsetFlushMode

  • Parameters

    Returns this

inheritedsetLockMode

  • setLockMode(mode?: LockMode, tables?: string[]): this
  • Parameters

    • optionalmode: LockMode
    • optionaltables: string[]

    Returns this

inheritedsetLoggerContext

  • Sets logger context for this query builder.


    Parameters

    Returns void

then

  • then(onfulfilled?: null | (value: QueryResult<Entity>) => TResult1 | PromiseLike<TResult1>, onrejected?: null | (reason: any) => TResult2 | PromiseLike<TResult2>): Promise<QueryResult<Entity>>
  • Provides promise-like interface so we can await the QB instance.


    Parameters

    • optionalonfulfilled: null | (value: QueryResult<Entity>) => TResult1 | PromiseLike<TResult1>
      • optionalonrejected: null | (reason: any) => TResult2 | PromiseLike<TResult2>

        Returns Promise<QueryResult<Entity>>

      inheritedtoQuery

      • toQuery(): { _sql: Sql; params: readonly unknown[]; sql: string }
      • Returns { _sql: Sql; params: readonly unknown[]; sql: string }

        • _sql: Sql
        • params: readonly unknown[]
        • sql: string

      inheritedtruncate

      inheritedunsetFlag

      • Parameters

        Returns this

      inheritedupdate

      where

      • where(cond: string | QBFilterQuery<Entity>, params?: any[] | $and | $or, operator?: $and | $or): this
      • Parameters

        • cond: string | QBFilterQuery<Entity>
        • optionalparams: any[] | $and | $or
        • optionaloperator: $and | $or

        Returns this

      inheritedwithSchema

      • withSchema(schema?: string): this
      • Parameters

        • optionalschema: string

        Returns this

      inheritedwithSubQuery

      • withSubQuery(subQuery: QueryBuilder<any, any>, alias: string): this
      • Parameters

        • subQuery: QueryBuilder<any, any>
        • alias: string

        Returns this