Skip to main content
Module

x/typeorm/src/persistence/SubjectExecutor.ts>SubjectExecutor

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

Executes all database operations (inserts, updated, deletes) that must be executed with given persistence subjects.

Constructors

new
SubjectExecutor(
queryRunner: QueryRunner,
subjects: Subject[],
options?: SaveOptions & RemoveOptions,
)

Properties

protected
allSubjects: Subject[]

All subjects that needs to be operated.

protected
insertSubjects: Subject[]

Subjects that must be inserted.

protected
optional
options: SaveOptions & RemoveOptions

Persistence options.

protected
queryRunner: QueryRunner

QueryRunner used to execute all queries with a given subjects.

protected
removeSubjects: Subject[]

Subjects that must be removed.

protected
updateSubjects: Subject[]

Subjects that must be updated.

hasExecutableOperations: boolean

Indicates if executor has any operations to execute (e.g. has insert / update / delete operations to be executed).

Methods

protected
broadcastAfterEventsForAll(): BroadcasterResult

Broadcasts "AFTER_INSERT", "AFTER_UPDATE", "AFTER_REMOVE" events for all given subjects. Returns void if there wasn't any listener or subscriber executed. Note: this method has a performance-optimized code organization.

protected
broadcastBeforeEventsForAll(): BroadcasterResult

Broadcasts "BEFORE_INSERT", "BEFORE_UPDATE", "BEFORE_REMOVE" events for all given subjects.

protected
executeInsertOperations(): Promise<void>

Executes insert operations.

protected
executeRemoveOperations(): Promise<void>

Removes all given subjects from the database.

todo: we need to apply topological sort here as well

protected
executeUpdateOperations(): Promise<void>

Updates all given subjects in the database.

protected
groupBulkSubjects(subjects: Subject[], type: "insert" | "delete"): [{ [key: string]: Subject[]; }, string[]]

Groups subjects by metadata names (by tables) to make bulk insertions and deletions possible. However there are some limitations with bulk insertions of data into tables with generated (increment) columns in some drivers. Some drivers like mysql and sqlite does not support returning multiple generated columns after insertion and can only return a single generated column value, that's why its not possible to do bulk insertion, because it breaks insertion result's generatedMap and leads to problems when this subject is used in other subjects saves. That's why we only support bulking in junction tables for those drivers.

Other drivers like postgres and sql server support RETURNING / OUTPUT statement which allows to return generated id for each inserted row, that's why bulk insertion is not limited to junction tables in there.

protected
recompute(): void

Performs entity re-computations - finds changed columns, re-builds insert/update/remove subjects.

protected
updateSpecialColumnsInInsertedAndUpdatedEntities(subjects: Subject[]): void

Updates all special columns of the saving entities (create date, update date, version, etc.). Also updates nullable columns and columns with default values.

Updates all special columns of the saving entities (create date, update date, version, etc.). Also updates nullable columns and columns with default values.

protected
validate()

Validates all given subjects.

execute(): Promise<void>

Executes all operations over given array of subjects. Executes queries using given query runner.