QueryBuilder can be initialized from given Connection and QueryRunner objects or from given other QueryBuilder.
QueryBuilder can be initialized from given Connection and QueryRunner objects or from given other QueryBuilder.
可选queryRunner: QueryRunner只读@instanceof受保护conditions只读connectionConnection on which QueryBuilder was created.
只读expressionContains all properties of the QueryBuilder that needs to be build a final query.
受保护find受保护joins受保护order受保护parentIf QueryBuilder was created in a subquery mode then its parent QueryBuilder (who created subquery) will be stored here.
受保护 可选queryQuery runner used to execute query builder query.
受保护relation受保护selectsAdds CTE to query
可选options: QueryBuilderCteOptionsSpecifies FROM which entity's table select/update/delete will be executed. Also sets a main string alias of the selection data.
Specifies FROM which entity's table select/update/delete will be executed. Also sets a main string alias of the selection data.
Adds GROUP BY condition in the query builder.
Adds ORDER BY condition in the query builder.
可选order: "ASC" | "DESC"可选nulls: "NULLS FIRST" | "NULLS LAST"Adds new selection to the SELECT query.
可选selectionAliasName: stringAdds new selection to the SELECT query.
可选selectionAliasName: stringAdds new selection to the SELECT query.
Adds new AND HAVING condition in the query builder. Additionally you can add parameters used in where expression.
可选parameters: ObjectLiteralAdds new AND WHERE condition in the query builder. Additionally you can add parameters used in where expression.
可选parameters: ObjectLiteralAdds new AND WHERE with conditions for the given ids.
Ids are mixed. It means if you have single primary key you can pass a simple id values, for example [1, 2, 3]. If you have multiple primary keys you need to pass object with property names and values specified, for example [{ firstId: 1, secondId: 2 }, { firstId: 2, secondId: 3 }, ...]
受保护apply受保护build可选embedPrefix: string受保护build受保护build可选embedPrefix: string受保护build可选embedPrefix: string受保护build可选embedPrefix: string受保护build可选embedPrefix: stringEnables or disables query result caching.
Enables query result caching and sets in milliseconds in which cache will expire. If not set then global caching time will be used.
Enables query result caching and sets cache id and milliseconds in which cache will expire.
可选milliseconds: numberIndicates if listeners and subscribers must be called before and after query execution. Enabled by default.
Clones query builder as it is. Note: it uses new query runner, if you want query builder that uses exactly same query runner, you can create query builder using its constructor, for example new SelectQueryBuilder(queryBuilder) where queryBuilder is cloned QueryBuilder.
Includes a Query comment in the query builder. This is helpful for debugging purposes, such as finding a specific query in the database server's logs, or for categorization using an APM product.
受保护create受保护create受保护createSpecifies FROM which entity's table select/update/delete will be executed. Also sets a main string alias of the selection data.
可选aliasName: string受保护createCreates "GROUP BY" part of SQL query.
受保护createCreates "HAVING" part of SQL query.
受保护createCreates "JOIN" part of SQL query.
受保护createCreates "LIMIT" and "OFFSET" parts of SQL query.
受保护createCreates "LOCK" part of SQL query.
受保护create受保护createCreates "ORDER BY" part of SQL query.
受保护create受保护createCreates a property paths for a given ObjectLiteral.
可选prefix: stringCreates a completely new query builder. Uses same query runner as current QueryBuilder.
可选queryRunner: QueryRunner受保护createCreates "RETURNING" / "OUTPUT" expression.
受保护createCreates select | select distinct part of SQL query.
受保护createCreates "SELECT FROM" part of SQL query.
受保护createTime travel queries for CockroachDB
受保护create受保护createComputes given where argument - transforms to a where string all forms it can take.
可选alwaysWrap: boolean受保护createCreates "WHERE" expression.
Creates DELETE query.
Disables escaping.
Sets whether the selection is DISTINCT.
可选distinct: booleanSets the distinct on clause for Postgres.
Escapes table name, column name or alias name using current database's escaping character.
Executes sql generated by query builder and returns raw database results.
受保护execute受保护executeExecutes sql generated by query builder and returns object with raw results and entities created from them.
受保护execute受保护findSpecifies FROM which entity's table select/update/delete will be executed. Also sets a main string alias of the selection data. Removes all previously set from-s.
Specifies FROM which entity's table select/update/delete will be executed. Also sets a main string alias of the selection data. Removes all previously set from-s.
Gets count - number of entities selected by sql generated by this query builder. Count excludes all limitations set by offset, limit, skip, and take.
Gets exists Returns whether any rows exists matching current query.
受保护get受保护getGets name of the table where insert should be performed.
Gets entities returned by execution of generated query builder sql.
Executes built SQL query and returns entities and overall entities count (without limitation). This method is useful to build pagination.
Gets single entity returned by execution of generated query builder sql.
Gets the first entity returned by execution of generated query builder sql or rejects the returned promise on error.
Gets all parameters.
受保护getGets generated SQL query without parameters being replaced.
Gets query to be executed with all parameters used in it.
Gets all raw results returned by execution of generated query builder sql.
Gets first raw result returned by execution of generated query builder sql.
受保护getIf returning / output cause is set to array of column names, then this method will return all column metadatas of those column names.
Gets generated sql that will be executed. Parameters in the query are escaped for the currently used driver.
受保护getGets escaped table name with schema name if SqlServer driver used with custom schema name, otherwise returns escaped table name.
受保护get受保护get受保护getSets GROUP BY condition in the query builder. If you had previously GROUP BY expression defined, calling this function will override previously set GROUP BY conditions.
Sets GROUP BY condition in the query builder. If you had previously GROUP BY expression defined, calling this function will override previously set GROUP BY conditions.
受保护hasCheck the existence of a parameter for this query builder.
Checks if given relation exists in the entity. Returns true if relation exists, false otherwise.
todo: move this method to manager? or create a shortcut?
Checks if given relations exist in the entity. Returns true if relation exists, false otherwise.
todo: move this method to manager? or create a shortcut?
Sets HAVING condition in the query builder. If you had previously HAVING expression defined, calling this function will override previously set HAVING conditions. Additionally you can add parameters used in where expression.
可选parameters: ObjectLiteralINNER JOINs (without selection) given subquery. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralINNER JOINs (without selection) entity's property. Given entity property should be a relation. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralINNER JOINs (without selection) given entity's table. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralINNER JOINs (without selection) given table. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralINNER JOINs given subquery, SELECTs the data returned by a join and MAPs all that data to some entity's property. This is extremely useful when you want to select some data and map it to some virtual property. It will assume that there are multiple rows of selecting data, and mapped result will be an array. Given entity property should be a relation. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralINNER JOINs entity's property, SELECTs the data returned by a join and MAPs all that data to some entity's property. This is extremely useful when you want to select some data and map it to some virtual property. It will assume that there are multiple rows of selecting data, and mapped result will be an array. Given entity property should be a relation. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralINNER JOINs entity's table, SELECTs the data returned by a join and MAPs all that data to some entity's property. This is extremely useful when you want to select some data and map it to some virtual property. It will assume that there are multiple rows of selecting data, and mapped result will be an array. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralINNER JOINs table, SELECTs the data returned by a join and MAPs all that data to some entity's property. This is extremely useful when you want to select some data and map it to some virtual property. It will assume that there are multiple rows of selecting data, and mapped result will be an array. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralINNER JOINs given subquery, SELECTs the data returned by a join and MAPs all that data to some entity's property. This is extremely useful when you want to select some data and map it to some virtual property. It will assume that there is a single row of selecting data, and mapped result will be a single selected value. Given entity property should be a relation. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteral可选mapAsEntity: string | FunctionINNER JOINs entity's property, SELECTs the data returned by a join and MAPs all that data to some entity's property. This is extremely useful when you want to select some data and map it to some virtual property. It will assume that there is a single row of selecting data, and mapped result will be a single selected value. Given entity property should be a relation. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralINNER JOINs entity's table, SELECTs the data returned by a join and MAPs all that data to some entity's property. This is extremely useful when you want to select some data and map it to some virtual property. It will assume that there is a single row of selecting data, and mapped result will be a single selected value. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralINNER JOINs table, SELECTs the data returned by a join and MAPs all that data to some entity's property. This is extremely useful when you want to select some data and map it to some virtual property. It will assume that there is a single row of selecting data, and mapped result will be a single selected value. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralINNER JOINs given subquery and adds all selection properties to SELECT.. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralINNER JOINs entity's property and adds all selection properties to SELECT. Given entity property should be a relation. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralINNER JOINs entity and adds all selection properties to SELECT. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralINNER JOINs table and adds all selection properties to SELECT. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralCreates INSERT query.
受保护join可选condition: string可选parameters: ObjectLiteral可选mapToProperty: string可选isMappingMany: boolean可选mapAsEntity: string | FunctionLEFT JOINs (without selection) given subquery. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralLEFT JOINs (without selection) entity's property. Given entity property should be a relation. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralLEFT JOINs (without selection) entity's table. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralLEFT JOINs (without selection) given table. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralLEFT JOINs given subquery, SELECTs the data returned by a join and MAPs all that data to some entity's property. This is extremely useful when you want to select some data and map it to some virtual property. It will assume that there are multiple rows of selecting data, and mapped result will be an array. Given entity property should be a relation. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralLEFT JOINs entity's property, SELECTs the data returned by a join and MAPs all that data to some entity's property. This is extremely useful when you want to select some data and map it to some virtual property. It will assume that there are multiple rows of selecting data, and mapped result will be an array. Given entity property should be a relation. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralLEFT JOINs entity's table, SELECTs the data returned by a join and MAPs all that data to some entity's property. This is extremely useful when you want to select some data and map it to some virtual property. It will assume that there are multiple rows of selecting data, and mapped result will be an array. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralLEFT JOINs table, SELECTs the data returned by a join and MAPs all that data to some entity's property. This is extremely useful when you want to select some data and map it to some virtual property. It will assume that there are multiple rows of selecting data, and mapped result will be an array. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralLEFT JOINs given subquery, SELECTs the data returned by a join and MAPs all that data to some entity's property. This is extremely useful when you want to select some data and map it to some virtual property. It will assume that there is a single row of selecting data, and mapped result will be a single selected value. Given entity property should be a relation. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteral可选mapAsEntity: string | FunctionLEFT JOINs entity's property, SELECTs the data returned by a join and MAPs all that data to some entity's property. This is extremely useful when you want to select some data and map it to some virtual property. It will assume that there is a single row of selecting data, and mapped result will be a single selected value. Given entity property should be a relation. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralLEFT JOINs entity's table, SELECTs the data returned by a join and MAPs all that data to some entity's property. This is extremely useful when you want to select some data and map it to some virtual property. It will assume that there is a single row of selecting data, and mapped result will be a single selected value. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralLEFT JOINs table, SELECTs the data returned by a join and MAPs all that data to some entity's property. This is extremely useful when you want to select some data and map it to some virtual property. It will assume that there is a single row of selecting data, and mapped result will be a single selected value. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralLEFT JOINs given subquery and adds all selection properties to SELECT.. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralLEFT JOINs entity's property and adds all selection properties to SELECT. Given entity property should be a relation. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralLEFT JOINs entity and adds all selection properties to SELECT. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralLEFT JOINs table and adds all selection properties to SELECT. You also need to specify an alias of the joined data. Optionally, you can add condition and parameters used in condition.
可选condition: string可选parameters: ObjectLiteralSets LIMIT - maximum number of rows to be selected. NOTE that it may not work as you expect if you are using joins. If you want to implement pagination, and you are having join in your query, then use the take method instead.
可选limit: numberLoads all relation ids for all relations of the selected entity. All relation ids will be mapped to relation property themself. If array of strings is given then loads only relation ids of the given properties.
可选options: { disableMixedMap?: boolean; relations?: string[] }受保护loadCounts number of entities of entity's relation and maps the value into some entity's property. Optionally, you can add condition and parameters used in condition.
可选aliasName: string可选queryBuilderFactory: (qb: SelectQueryBuilder<any>) => SelectQueryBuilder<any>LEFT JOINs relation id and maps it into some entity's property. Optionally, you can add condition and parameters used in condition.
可选options: { disableMixedMap?: boolean }LEFT JOINs relation id and maps it into some entity's property. Optionally, you can add condition and parameters used in condition.
Set max execution time.
受保护mergeMerges into expression map given expression map properties.
受保护normalizeNormalizes a give number - converts to int if possible.
受保护obtainCreates a query builder used to execute sql queries inside this query builder.
Sets OFFSET - selection offset. NOTE that it may not work as you expect if you are using joins. If you want to implement pagination, and you are having join in your query, then use the skip method instead.
可选offset: numberSets ORDER BY condition in the query builder. If you had previously ORDER BY expression defined, calling this function will override previously set ORDER BY conditions.
Calling order by without order set will remove all previously set order bys.
Sets ORDER BY condition in the query builder. If you had previously ORDER BY expression defined, calling this function will override previously set ORDER BY conditions.
可选order: "ASC" | "DESC"可选nulls: "NULLS FIRST" | "NULLS LAST"Sets ORDER BY condition in the query builder. If you had previously ORDER BY expression defined, calling this function will override previously set ORDER BY conditions.
Adds new OR HAVING condition in the query builder. Additionally you can add parameters used in where expression.
可选parameters: ObjectLiteralAdds new OR WHERE condition in the query builder. Additionally you can add parameters used in where expression.
可选parameters: ObjectLiteralAdds new OR WHERE with conditions for the given ids.
Ids are mixed. It means if you have single primary key you can pass a simple id values, for example [1, 2, 3]. If you have multiple primary keys you need to pass object with property names and values specified, for example [{ firstId: 1, secondId: 2 }, { firstId: 2, secondId: 3 }, ...]
Prints sql to stdout using console.log.
Sets entity's relation with which this query builder gonna work.
Sets entity's relation with which this query builder gonna work.
受保护replace受保护replaceReplaces all entity's propertyName to name in the given SQL string.
Creates SELECT query. Replaces all previous selections if they exist.
Creates SELECT query. Replaces all previous selections if they exist.
可选selectionAliasName: stringCreates SELECT query and selects given data. Replaces all previous selections if they exist.
可选selectionAliasName: stringCreates SELECT query and selects given data. Replaces all previous selections if they exist.
Sets locking mode.
Sets locking mode.
可选lockVersion: undefined可选lockTables: string[]Sets lock handling by adding NO WAIT or SKIP LOCKED.
Sets extra options that can be used to configure how query builder works.
Sets parameter name and its value.
The key for this parameter may contain numbers, letters, underscores, or periods.
Sets number of entities to skip.
可选skip: numberExecutes built SQL query and returns raw data stream.
Creates a subquery - query that can be used inside other queries.
Sets maximal number of entities to take.
可选take: numberEnables time travelling for the current query (only supported by cockroach currently)
可选timeTravelFn: string | booleanCreates UPDATE query and applies given update values.
Creates UPDATE query and applies given update values.
Creates UPDATE query for the given entity and applies given update values.
可选updateSet: _QueryDeepPartialEntity<ObjectLiteral extends Entity ? unknown : Entity>Creates UPDATE query for the given table name and applies given update values.
可选updateSet: _QueryDeepPartialEntity<ObjectLiteral extends Entity ? unknown : Entity>Set certain index to be used by the query.
Name of index to be used.
If set to true the query will be wrapped into a transaction.
Sets WHERE condition in the query builder. If you had previously WHERE expression defined, calling this function will override previously set WHERE conditions. Additionally you can add parameters used in where expression.
可选parameters: ObjectLiteralAdds new AND WHERE with conditions for the given ids.
Ids are mixed. It means if you have single primary key you can pass a simple id values, for example [1, 2, 3]. If you have multiple primary keys you need to pass object with property names and values specified, for example [{ firstId: 1, secondId: 2 }, { firstId: 2, secondId: 3 }, ...]
Disables the global condition of "non-deleted" for the entity with delete date columns.
静态register
Allows to build complex sql queries in a fashion way and execute those queries.