QueryBuilder <Entity, RootAlias, Hint, Context>
Hierarchy
- QueryBuilder
Index
Accessors
Methods
- addSelect
- andHaving
- andWhere
- applyFilters
- as
- cache
- clone
- comment
- count
- delete
- distinct
- distinctOn
- execute
- from
- getCount
- getFormattedQuery
- getKnex
- getKnexQuery
- getLoggerContext
- getParams
- getQuery
- getResult
- getResultAndCount
- getResultList
- getSingleResult
- groupBy
- hasFlag
- having
- hintComment
- ignore
- indexHint
- innerJoin
- innerJoinAndSelect
- innerJoinLateral
- innerJoinLateralAndSelect
- insert
- join
- joinAndSelect
- leftJoin
- leftJoinAndSelect
- leftJoinLateral
- leftJoinLateralAndSelect
- limit
- merge
- offset
- onConflict
- orderBy
- orHaving
- orWhere
- returning
- select
- setFlag
- setFlushMode
- setLockMode
- setLoggerContext
- then
- toQuery
- truncate
- unsetFlag
- update
- where
- withSchema
- withSubQuery
Accessors
alias
- Returns string
helper
- Returns QueryBuilderHelper
mainAlias
- Returns Alias<Entity>
Methods
addSelect
- Parameters- Returns SelectQueryBuilder<Entity, RootAlias, Hint, Context>
andHaving
- Parameters- optionalcond: string | QBFilterQuery
- optionalparams: any[]
 - Returns SelectQueryBuilder<Entity, RootAlias, Hint, Context>
andWhere
- Parameters- cond: QBFilterQuery<Entity>
 - Returns this
applyFilters
- Apply filters to the QB where condition. - Parameters- filterOptions: boolean | string[] | Dictionary<boolean | Dictionary> = {}
 - Returns Promise<void>
as
- Returns knex instance with sub-query aliased with given alias. You can provide - EntityName.propNameas alias, then the field name will be used based on the metadata- Parameters- alias: string
 - Returns QueryBuilder<any, any>
cache
- Parameters- config: number | boolean | [string, number] = true
 - Returns this
clone
- Parameters- optionalreset: boolean | string[]
 - Returns QueryBuilder<Entity, never, never, never>
comment
- Prepend comment to the sql query using the syntax - /* ... *‍/. Some characters are forbidden such as- /*, *‍/and- ?.- Parameters- comment: string | string[]
 - Returns this
count
- Parameters- optionalfield: EntityKeyOrString<Entity> | EntityKeyOrString<Entity>[]
- distinct: boolean = false
 - Returns CountQueryBuilder<Entity>
delete
- Parameters- optionalcond: QBFilterQuery
 - Returns DeleteQueryBuilder<Entity>
distinct
- Returns SelectQueryBuilder<Entity, RootAlias, Hint, Context>
distinctOn
- postgres only - Parameters- fields: EntityKeyOrString<Entity> | EntityKeyOrString<Entity>[]
 - Returns SelectQueryBuilder<Entity, RootAlias, Hint, Context>
execute
- Executes this QB and returns the raw results, mapped to the property names (unless disabled via last parameter). Use - methodto specify what kind of result you want to get (array/single/meta).- Parameters- optionalmethod: get | all | run
- optionaloptions: boolean | ExecuteOptions
 - Returns Promise<U>
from
- 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, RootAlias, Hint, Context>
getCount
- Executes count query (without offset and limit), returning total count of results - Parameters- optionalfield: EntityKeyOrString<Entity> | EntityKeyOrString<Entity>[]
- optionaldistinct: boolean
 - Returns Promise<number>
getFormattedQuery
- Returns raw interpolated query string with all the parameters inlined. - Returns string
getKnex
- Parameters- processVirtualEntity: boolean = true
 - Returns QueryBuilder<any, any>
getKnexQuery
- Parameters- processVirtualEntity: boolean = true
 - Returns QueryBuilder<any, any>
getLoggerContext
- Gets logger context for this query builder. - Returns T
getParams
- Returns the list of all parameters for this query. - Returns readonly Value[]
getQuery
- Returns the query with parameters as wildcards. - Returns string
getResult
- Alias for - qb.getResultList()- Returns Promise<Loaded<Entity, Hint>[]>
getResultAndCount
- Executes the query, returning both array of results and total count query (without offset and limit). - Returns Promise<[Entity[], number]>
getResultList
- Executes the query, returning array of results - Parameters- optionallimit: number
 - Returns Promise<Loaded<Entity, Hint>[]>
getSingleResult
- Executes the query, returning the first result or null - Returns Promise<null | Entity>
groupBy
- Parameters- fields: EntityKeyOrString<Entity> | readonly EntityKeyOrString<Entity>[]
 - Returns SelectQueryBuilder<Entity, RootAlias, Hint, Context>
hasFlag
- Parameters- flag: QueryFlag
 - Returns boolean
having
- Parameters- cond: string | QBFilterQuery = {}
- optionalparams: any[]
- optionaloperator: $and | $or
 - Returns SelectQueryBuilder<Entity, RootAlias, Hint, Context>
hintComment
- Add hints to the query using comment-like syntax - /*+ ... *‍/. 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
ignore
- Returns this
indexHint
- Adds index hint to the FROM clause. - Parameters- sql: string
 - Returns this
innerJoin
- Parameters- field: QueryBuilder<any, any> | QueryBuilder<any, never, never, never> | Field
- alias: Alias
- cond: QBFilterQuery = {}
- optionalschema: string
 - Returns SelectQueryBuilder<Entity, RootAlias, Hint, { [ K in string | number | symbol ]: IsNever<Context, true, false> extends true ? AddToContext<GetType<Entity, object, Field>, object, Field, Alias, false> : Context & AddToContext<GetType<Entity, Context, Field>, Context, Field, Alias, false>[K] }>
innerJoinAndSelect
- 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, RootAlias, ModifyHint<RootAlias, Context, Hint, Field, true> & {}, { [ K in string | number | symbol ]: IsNever<Context, true, false> extends true ? AddToContext<GetType<Entity, object, Field>, object, Field, Alias, true> : Context & AddToContext<GetType<Entity, Context, Field>, Context, Field, Alias, true>[K] }>
innerJoinLateral
- Parameters- field: QueryBuilder<any, any> | QueryBuilder<any, never, never, never>
- alias: string
- cond: QBFilterQuery = {}
- optionalschema: string
 - Returns this
innerJoinLateralAndSelect
- Parameters- field: [field: Field, qb: QueryBuilder<any, any> | QueryBuilder<any, never, never, never>]
- alias: Alias
- cond: QBFilterQuery = {}
- optionalfields: string[]
- optionalschema: string
 - Returns SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field, true> & {}, { [ K in string | number | symbol ]: IsNever<Context, true, false> extends true ? AddToContext<GetType<Entity, object, Field>, object, Field, Alias, true> : Context & AddToContext<GetType<Entity, Context, Field>, Context, Field, Alias, true>[K] }>
insert
- Parameters- data: RequiredEntityData<Entity> | RequiredEntityData<Entity>[]
 - Returns InsertQueryBuilder<Entity>
join
- Parameters- field: QueryBuilder<any, any> | Field | QueryBuilder<any, never, never, never>
- alias: Alias
- cond: QBFilterQuery = {}
- type: JoinType = JoinType.innerJoin
- optionalpath: string
- optionalschema: string
 - Returns SelectQueryBuilder<Entity, RootAlias, Hint, { [ K in string | number | symbol ]: IsNever<Context, true, false> extends true ? AddToContext<GetType<Entity, object, Field>, object, Field, Alias, false> : Context & AddToContext<GetType<Entity, Context, Field>, Context, Field, Alias, false>[K] }>
joinAndSelect
- 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, RootAlias, ModifyHint<RootAlias, Context, Hint, Field, true> & {}, { [ K in string | number | symbol ]: IsNever<Context, true, false> extends true ? AddToContext<GetType<Entity, object, Field>, object, Field, Alias, true> : Context & AddToContext<GetType<Entity, Context, Field>, Context, Field, Alias, true>[K] }>
leftJoin
- Parameters- field: QueryBuilder<any, any> | QueryBuilder<any, never, never, never> | Field
- alias: Alias
- cond: QBFilterQuery = {}
- optionalschema: string
 - Returns SelectQueryBuilder<Entity, RootAlias, Hint, { [ K in string | number | symbol ]: IsNever<Context, true, false> extends true ? AddToContext<GetType<Entity, object, Field>, object, Field, Alias, false> : Context & AddToContext<GetType<Entity, Context, Field>, Context, Field, Alias, false>[K] }>
leftJoinAndSelect
- 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, RootAlias, ModifyHint<RootAlias, Context, Hint, Field, true> & {}, { [ K in string | number | symbol ]: IsNever<Context, true, false> extends true ? AddToContext<GetType<Entity, object, Field>, object, Field, Alias, true> : Context & AddToContext<GetType<Entity, Context, Field>, Context, Field, Alias, true>[K] }>
leftJoinLateral
- Parameters- field: QueryBuilder<any, any> | QueryBuilder<any, never, never, never>
- alias: string
- cond: QBFilterQuery = {}
- optionalschema: string
 - Returns this
leftJoinLateralAndSelect
- Parameters- field: [field: Field, qb: QueryBuilder<any, any> | QueryBuilder<any, never, never, never>]
- alias: Alias
- cond: QBFilterQuery = {}
- optionalfields: string[]
- optionalschema: string
 - Returns SelectQueryBuilder<Entity, RootAlias, ModifyHint<RootAlias, Context, Hint, Field, true> & {}, { [ K in string | number | symbol ]: IsNever<Context, true, false> extends true ? AddToContext<GetType<Entity, object, Field>, object, Field, Alias, true> : Context & AddToContext<GetType<Entity, Context, Field>, Context, Field, Alias, true>[K] }>
limit
- Parameters- optionallimit: number
- offset: number = 0
 - Returns SelectQueryBuilder<Entity, RootAlias, Hint, Context>
merge
- Parameters- optionaldata: Field<Entity>[] | EntityData<Entity>
 - Returns this
offset
- Parameters- optionaloffset: number
 - Returns SelectQueryBuilder<Entity, RootAlias, Hint, Context>
onConflict
- Parameters- Returns InsertQueryBuilder<Entity>
orderBy
- Parameters- orderBy: QBQueryOrderMap<Entity> | QBQueryOrderMap<Entity>[]
 - Returns SelectQueryBuilder<Entity, RootAlias, Hint, Context>
orHaving
- Parameters- optionalcond: string | QBFilterQuery
- optionalparams: any[]
 - Returns SelectQueryBuilder<Entity, RootAlias, Hint, Context>
orWhere
- Parameters- cond: QBFilterQuery<Entity>
 - Returns this
returning
select
- Parameters- Returns SelectQueryBuilder<Entity, RootAlias, Hint, Context>
setFlag
- Parameters- flag: QueryFlag
 - Returns this
setFlushMode
- Parameters- optionalflushMode: FlushMode
 - Returns this
setLockMode
- Parameters- optionalmode: LockMode
- optionaltables: string[]
 - Returns this
setLoggerContext
- Sets logger context for this query builder. - Parameters- context: LoggingOptions & Dictionary
 - Returns void
then
- Provides promise-like interface so we can await the QB instance. - Parameters- optionalonfulfilled: null | (value) => TResult1 | PromiseLike<TResult1>
- optionalonrejected: null | (reason) => TResult2 | PromiseLike<TResult2>
 - Returns Promise<number | Loaded<Entity, Hint>[] | QueryResult<Entity>>
toQuery
- Returns { _sql: Sql; params: readonly unknown[]; sql: string }- _sql: Sql
- params: readonly unknown[]
- sql: string
 
truncate
- Returns TruncateQueryBuilder<Entity>
unsetFlag
- Parameters- flag: QueryFlag
 - Returns this
update
- Parameters- data: EntityData<Entity>
 - Returns UpdateQueryBuilder<Entity>
where
- Parameters- cond: QBFilterQuery<Entity>
- optionaloperator: $and | $or
 - Returns this
withSchema
- Parameters- optionalschema: string
 - Returns this
withSubQuery
- Parameters- subQuery: QueryBuilder<any, any>
- alias: string
 - Returns this
SQL query builder with fluent interface.