CountQueryBuilder <T>
Hierarchy
- QueryBuilder<T>
- CountQueryBuilder
Index
Accessors
Methods
- [custom]
- addSelect
- andWhere
- as
- cache
- clone
- comment
- count
- delete
- distinct
- distinctOn
- execute
- from
- getCount
- getFormattedQuery
- getKnex
- getKnexQuery
- getParams
- getQuery
- getResult
- getResultAndCount
- getResultList
- getSingleResult
- groupBy
- having
- hintComment
- ignore
- indexHint
- innerJoinAndSelect
- insert
- join
- joinAndSelect
- leftJoin
- leftJoinAndSelect
- limit
- merge
- offset
- onConflict
- orWhere
- orderBy
- raw
- returning
- select
- setFlag
- setFlushMode
- setLockMode
- then
- truncate
- unsetFlag
- update
- where
- withSchema
- withSubQuery
Accessors
alias
Returns string
helper
Returns QueryBuilderHelper
mainAlias
Returns Alias<T>
Methods
[custom]
Parameters
depth: number
Returns string
addSelect
Parameters
fields: Field<T> | Field<T>[]
Returns SelectQueryBuilder<T>
andWhere
Parameters
cond: QBFilterQuery<T>
Returns CountQueryBuilder<T>
as
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 metadataParameters
alias: string
Returns QueryBuilder<any, any>
cache
Parameters
config: number | boolean | [string, number] = true
Returns CountQueryBuilder<T>
clone
Returns QueryBuilder<T>
comment
Prepend comment to the sql query using the syntax
/* ... *‍/
. Some characters are forbidden such as/*, *‍/
and?
.Parameters
comment: string | string[]
Returns CountQueryBuilder<T>
count
Parameters
optionalfield: string | string[]
distinct: boolean = false
Returns CountQueryBuilder<T>
delete
Parameters
optionalcond: QBFilterQuery
Returns DeleteQueryBuilder<T>
distinct
Returns SelectQueryBuilder<T>
distinctOn
postgres only
Parameters
fields: string | string[]
Returns SelectQueryBuilder<T>
execute
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).Type parameters
- U = { count: number }[]
Parameters
optionalmethod: get | all | run
optionalmapResults: boolean
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.
Type parameters
- T: Partial<T> = Partial<any>
Parameters
target: QueryBuilder<T>
optionalaliasName: string
Returns QueryBuilder<T>
getCount
Executes count query (without offset and limit), returning total count of results
Parameters
optionalfield: string | string[]
optionaldistinct: boolean
Returns Promise<number>
getFormattedQuery
Returns raw interpolated query string with all the parameters inlined.
Returns string
getKnex
Returns QueryBuilder<any, any>
getKnexQuery
Returns QueryBuilder<any, any>
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<T[]>
getResultAndCount
Executes the query, returning both array of results and total count query (without offset and limit).
Returns Promise<[T[], number]>
getResultList
Executes the query, returning array of results
Returns Promise<T[]>
getSingleResult
Executes the query, returning the first result or null
Returns Promise<null | T>
groupBy
Parameters
fields: string | keyof T | readonly (string | keyof T)[]
Returns CountQueryBuilder<T>
having
Parameters
cond: string | QBFilterQuery = {}
optionalparams: any[]
Returns CountQueryBuilder<T>
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 CountQueryBuilder<T>
ignore
Returns CountQueryBuilder<T>
indexHint
Adds index hint to the FROM clause.
Parameters
sql: string
Returns CountQueryBuilder<T>
innerJoinAndSelect
Parameters
field: string
alias: string
cond: QBFilterQuery = {}
optionalfields: string[]
Returns SelectQueryBuilder<T>
insert
Parameters
data: RequiredEntityData<T> | RequiredEntityData<T>[]
Returns InsertQueryBuilder<T>
join
Parameters
field: string
alias: string
cond: QBFilterQuery = {}
type: leftJoin | innerJoin | pivotJoin = 'innerJoin'
optionalpath: string
Returns CountQueryBuilder<T>
joinAndSelect
Parameters
field: string
alias: string
cond: QBFilterQuery = {}
type: leftJoin | innerJoin | pivotJoin = 'innerJoin'
optionalpath: string
optionalfields: string[]
Returns SelectQueryBuilder<T>
leftJoin
Parameters
field: string
alias: string
cond: QBFilterQuery = {}
Returns CountQueryBuilder<T>
leftJoinAndSelect
Parameters
field: string
alias: string
cond: QBFilterQuery = {}
optionalfields: string[]
Returns SelectQueryBuilder<T>
limit
Parameters
optionallimit: number
offset: number = 0
Returns CountQueryBuilder<T>
merge
Parameters
optionaldata: Field<T>[] | EntityData<T>
Returns CountQueryBuilder<T>
offset
Parameters
optionaloffset: number
Returns CountQueryBuilder<T>
onConflict
Parameters
fields: Field<T> | Field<T>[] = []
Returns CountQueryBuilder<T>
orWhere
Parameters
cond: QBFilterQuery<T>
Returns CountQueryBuilder<T>
orderBy
Parameters
orderBy: QBQueryOrderMap<T> | QBQueryOrderMap<T>[]
Returns CountQueryBuilder<T>
raw
Type parameters
- R = Raw<any>
Parameters
sql: string
bindings: ValueDict | RawBinding[] = []
Returns R
returning
Parameters
optionalfields: Field<T> | Field<T>[]
Returns CountQueryBuilder<T>
select
Parameters
fields: Field<T> | Field<T>[]
distinct: boolean = false
Returns SelectQueryBuilder<T>
setFlag
Parameters
flag: QueryFlag
Returns CountQueryBuilder<T>
setFlushMode
Parameters
optionalflushMode: FlushMode
Returns CountQueryBuilder<T>
setLockMode
Parameters
optionalmode: LockMode
optionaltables: string[]
Returns CountQueryBuilder<T>
then
Provides promise-like interface so we can await the QB instance.
Type parameters
- TResult1 = number
- TResult2 = never
Parameters
optionalonfulfilled: null | (value: number) => TResult1 | PromiseLike<TResult1>
optionalonrejected: null | (reason: any) => TResult2 | PromiseLike<TResult2>
Returns Promise<number>
truncate
Returns TruncateQueryBuilder<T>
unsetFlag
Parameters
flag: QueryFlag
Returns CountQueryBuilder<T>
update
Parameters
data: EntityData<T>
Returns UpdateQueryBuilder<T>
where
Parameters
cond: QBFilterQuery<T>
optionaloperator: $and | $or
Returns CountQueryBuilder<T>
withSchema
Parameters
optionalschema: string
Returns CountQueryBuilder<T>
withSubQuery
Parameters
subQuery: QueryBuilder<any, any>
alias: string
Returns CountQueryBuilder<T>
SQL query builder with fluent interface.