UNPKG

typeorm

Version:

Data-Mapper ORM for TypeScript and ES2023+. Supports MySQL/MariaDB, PostgreSQL, MS SQL Server, Oracle, SAP HANA, SQLite, MongoDB databases.

149 lines (148 loc) 5.67 kB
import type { EntityTarget } from "../common/EntityTarget"; import type { ObjectLiteral } from "../common/ObjectLiteral"; import type { ColumnMetadata } from "../metadata/ColumnMetadata"; import type { InsertOrUpdateOptions } from "./InsertOrUpdateOptions"; import { QueryBuilder } from "./QueryBuilder"; import type { QueryDeepPartialEntity } from "./QueryPartialEntity"; import { InsertResult } from "./result/InsertResult"; import type { SelectQueryBuilder } from "./SelectQueryBuilder"; /** * Allows to build complex sql queries in a fashion way and execute those queries. */ export declare class InsertQueryBuilder<Entity extends ObjectLiteral> extends QueryBuilder<Entity> { readonly "@instanceof": symbol; /** * Gets generated SQL query without parameters being replaced. */ getQuery(): string; /** * Executes sql generated by query builder and returns raw database results. */ execute(): Promise<InsertResult>; /** * Specifies INTO which entity's table insertion will be executed. * * @param entityTarget * @param columns */ into<T extends ObjectLiteral>(entityTarget: EntityTarget<T>, columns?: string[]): InsertQueryBuilder<T>; /** * Values needs to be inserted into table. * * @param values */ values(values: QueryDeepPartialEntity<Entity> | QueryDeepPartialEntity<Entity>[]): this; /** * Specifies a SELECT query to use as the source of values for the INSERT. * This creates an INSERT INTO ... SELECT FROM statement. */ valuesFromSelect(queryBuilder: SelectQueryBuilder<any>): this; /** * Specifies a SELECT query to use as the source of values for the INSERT. * This creates an INSERT INTO ... SELECT FROM statement. */ valuesFromSelect(subQueryFactory: (qb: SelectQueryBuilder<any>) => SelectQueryBuilder<any>): this; /** * Optional returning/output clause. * This will return given column values. */ output(columns: string[]): this; /** * Optional returning/output clause. * Returning is a SQL string containing returning statement. */ output(output: string): this; /** * Optional returning/output clause. */ output(output: string | string[]): this; /** * Optional returning/output clause. * This will return given column values. */ returning(columns: string[]): this; /** * Optional returning/output clause. * Returning is a SQL string containing returning statement. */ returning(returning: string): this; /** * Optional returning/output clause. */ returning(returning: string | string[]): this; /** * Indicates if entity must be updated after insertion operations. * This may produce extra query or use RETURNING / OUTPUT statement (depend on database). * Enabled by default. * * @param enabled */ updateEntity(enabled: boolean): this; /** * Adds additional ignore statement supported in databases. * * @param statement */ orIgnore(statement?: string | boolean): this; /** * Adds an "upsert" clause to the insert query — when a row with the same * conflict target already exists the listed columns are updated instead. * * @param overwrite - Column names to overwrite on conflict. * @param conflictTarget - Column name(s) or constraint name used to detect * conflicts. When an array is given the columns form a composite key; * when a string is given it is treated as a constraint name. * @param orUpdateOptions - Additional options such as `skipUpdateIfNoValuesChanged`, * `indexPredicate`, `upsertType`, or `overwriteCondition`. */ orUpdate(overwrite: string[], conflictTarget?: string | string[], orUpdateOptions?: InsertOrUpdateOptions): this; /** * Creates INSERT express used to perform insert query. */ protected createInsertExpression(): string; /** * Gets list of columns where values must be inserted to. */ protected getInsertedColumns(): ColumnMetadata[]; /** * Creates a columns string where values must be inserted to for INSERT INTO expression. */ protected createColumnNamesExpression(): string; /** * Creates list of values needs to be inserted in the VALUES expression. */ protected createValuesExpression(): string; /** * Gets array of values need to be inserted into the target table. */ protected getValueSets(): ObjectLiteral[]; /** * Checks if column is an auto-generated primary key, but the current insertion specifies a value for it. * * @param column */ protected isOverridingAutoIncrementBehavior(column: ColumnMetadata): boolean; /** * Creates MERGE express used to perform insert query. */ protected createMergeExpression(): string; /** * Creates list of values needs to be inserted in the VALUES expression. * * @param mergeSourceAlias */ protected createMergeIntoSourceExpression(mergeSourceAlias: string): string; /** * Creates list of values needs to be inserted in the VALUES expression. * * @param mergeSourceAlias */ protected createMergeIntoInsertValuesExpression(mergeSourceAlias: string): string; /** * Create upsert search condition expression. * * @param mainTableOrAlias */ protected createUpsertConditionExpression(mainTableOrAlias: string): string; protected createColumnValueExpression(valueSets: ObjectLiteral[], valueSetIndex: number, column: ColumnMetadata): string; }