Skip to main content
Module

x/typeorm/src/index.ts>QueryBuilder

Forked from https://github.com/typeorm/typeorm
Latest
class QueryBuilder
Abstract
import { QueryBuilder } from "https://deno.land/x/typeorm@v0.2.23-rc10/src/index.ts";

Allows to build complex sql queries in a fashion way and execute those queries.

Constructors

new
QueryBuilder(queryBuilderFactory: AbstractQueryBuilderFactory, queryBuilder: QueryBuilder<any>)

QueryBuilder can be initialized from given Connection and QueryRunner objects or from given other QueryBuilder.

new
QueryBuilder(
queryBuilderFactory: AbstractQueryBuilderFactory,
connection: Connection,
queryRunner?: QueryRunner,
)

QueryBuilder can be initialized from given Connection and QueryRunner objects or from given other QueryBuilder.

new
QueryBuilder(
queryBuilderFactory: AbstractQueryBuilderFactory,
connectionOrQueryBuilder: Connection | QueryBuilder<any>,
queryRunner?: QueryRunner,
)

QueryBuilder can be initialized from given Connection and QueryRunner objects or from given other QueryBuilder.

Properties

protected
readonly
queryBuilderFactory: AbstractQueryBuilderFactory
protected
optional
queryRunner: QueryRunner

Query runner used to execute query builder query.

readonly
alias: string

Gets the main alias string used in this query builder.

readonly
connection: Connection

Connection on which QueryBuilder was created.

readonly
expressionMap: QueryExpressionMap

Contains all properties of the QueryBuilder that needs to be build a final query.

Methods

protected
computeWhereParameter(where:
| string
| ((qb: this) => string)
| Brackets
| ObjectLiteral
| ObjectLiteral[]
)

Computes given where argument - transforms to a where string all forms it can take.

protected
createFromAlias(entityTarget: Function | string | ((qb: SelectQueryBuilder<any>) => SelectQueryBuilder<any>), aliasName?: string): Alias

Specifies FROM which entity's table select/update/delete will be executed. Also sets a main string alias of the selection data.

protected
createReturningExpression(): string

Creates "RETURNING" / "OUTPUT" expression.

Creates "WHERE" expression.

protected
createWhereExpressionString(): string

Concatenates all added where expressions into one string.

protected
createWhereIdsExpression(ids: any | any[]): string

Creates "WHERE" expression and variables for the given "ids".

protected
getMainTableName(): string

Gets name of the table where insert should be performed.

protected
getReturningColumns(): ColumnMetadata[]

If returning / output cause is set to array of column names, then this method will return all column metadatas of those column names.

protected
getTableName(tablePath: string): string

Gets escaped table name with schema name if SqlServer driver used with custom schema name, otherwise returns escaped table name.

Creates a query builder used to execute sql queries inside this query builder.

protected
replacePropertyNames(statement: string)

Replaces all entity's propertyName to name in the given statement.

callListeners(enabled: boolean): this

Indicates if listeners and subscribers must be called before and after query execution. Enabled by default.

clone(): this

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.

Creates a completely new query builder. Uses same query runner as current QueryBuilder.

delete(): DeleteQueryBuilder<Entity>

Creates DELETE query.

Disables escaping.

escape(name: string): string

Escapes table name, column name or alias name using current database's escaping character.

execute(): Promise<any>

Executes sql generated by query builder and returns raw database results.

getParameters(): ObjectLiteral

Gets all parameters.

abstract
getQuery(): string

Gets generated sql query without parameters being replaced.

getQueryAndParameters(): [string, any[]]

Gets query to be executed with all parameters used in it.

getSql(): string

Gets generated sql that will be executed. Parameters in the query are escaped for the currently used driver.

hasRelation<T>(target: ObjectType<T> | string, relation: string): boolean

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?

hasRelation<T>(target: ObjectType<T> | string, relation: string[]): boolean

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?

insert(): InsertQueryBuilder<Entity>

Creates INSERT query.

printSql(): this

Prints sql to stdout using console.log.

relation(propertyPath: string): RelationQueryBuilder<Entity>

Sets entity's relation with which this query builder gonna work.

relation<T>(entityTarget: ObjectType<T> | string, propertyPath: string): RelationQueryBuilder<T>

Sets entity's relation with which this query builder gonna work.

select(): SelectQueryBuilder<Entity>

Creates SELECT query. Replaces all previous selections if they exist.

select(selection: string, selectionAliasName?: string): SelectQueryBuilder<Entity>

Creates SELECT query and selects given data. Replaces all previous selections if they exist.

select(selection: string[]): SelectQueryBuilder<Entity>

Creates SELECT query and selects given data. Replaces all previous selections if they exist.

setNativeParameters(parameters: ObjectLiteral): this

Adds native parameters from the given object.

setParameter(key: string, value: any): this

Sets parameter name and its value.

setParameters(parameters: ObjectLiteral): this

Adds all parameters from the given object.

setQueryRunner(queryRunner: QueryRunner): this

Sets or overrides query builder's QueryRunner.

update(): UpdateQueryBuilder<Entity>

Creates UPDATE query and applies given update values.

update(updateSet: QueryDeepPartialEntity<Entity>): UpdateQueryBuilder<Entity>

Creates UPDATE query and applies given update values.

update<T>(entity: ObjectType<T>, updateSet?: QueryDeepPartialEntity<T>): UpdateQueryBuilder<T>

Creates UPDATE query for the given entity and applies given update values.

update<T>(entity: EntitySchema<T>, updateSet?: QueryDeepPartialEntity<T>): UpdateQueryBuilder<T>

Creates UPDATE query for the given entity and applies given update values.

update(entity: Function | EntitySchema<Entity> | string, updateSet?: QueryDeepPartialEntity<Entity>): UpdateQueryBuilder<Entity>

Creates UPDATE query for the given entity and applies given update values.

update(tableName: string, updateSet?: QueryDeepPartialEntity<Entity>): UpdateQueryBuilder<Entity>

Creates UPDATE query for the given table name and applies given update values.

useTransaction(enabled: boolean): this

If set to true the query will be wrapped into a transaction.