333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
1
{"version":3,"sources":["../browser/src/query-runner/QueryRunner.ts"],"names":[],"mappings":"","file":"QueryRunner.js","sourcesContent":["import {TableColumn} from \"../schema-builder/table/TableColumn\";\nimport {Table} from \"../schema-builder/table/Table\";\nimport {TableForeignKey} from \"../schema-builder/table/TableForeignKey\";\nimport {TableIndex} from \"../schema-builder/table/TableIndex\";\nimport {Connection} from \"../connection/Connection\";\nimport {ReadStream} from \"../platform/PlatformTools\";\nimport {EntityManager} from \"../entity-manager/EntityManager\";\nimport {ObjectLiteral} from \"../common/ObjectLiteral\";\nimport {SqlInMemory} from \"../driver/SqlInMemory\";\nimport {TableUnique} from \"../schema-builder/table/TableUnique\";\nimport {View} from \"../schema-builder/view/View\";\nimport {Broadcaster} from \"../subscriber/Broadcaster\";\nimport {TableCheck} from \"../schema-builder/table/TableCheck\";\nimport {IsolationLevel} from \"../driver/types/IsolationLevel\";\nimport {TableExclusion} from \"../schema-builder/table/TableExclusion\";\n\n/**\n * Runs queries on a single database connection.\n */\nexport interface QueryRunner {\n\n    /**\n     * Connection used by this query runner.\n     */\n    readonly connection: Connection;\n\n    /**\n     * Broadcaster used on this query runner to broadcast entity events.\n     */\n    readonly broadcaster: Broadcaster;\n\n    /**\n     * Entity manager working only with this query runner.\n     */\n    readonly manager: EntityManager;\n\n    /**\n     * Indicates if connection for this query runner is released.\n     * Once its released, query runner cannot run queries anymore.\n     */\n    readonly isReleased: boolean;\n\n    /**\n     * Indicates if transaction is in progress.\n     */\n    readonly isTransactionActive: boolean;\n\n    /**\n     * Stores temporarily user data.\n     * Useful for sharing data with subscribers.\n     */\n    data: ObjectLiteral;\n\n    /**\n     * All synchronized tables in the database.\n     */\n    loadedTables: Table[];\n\n    /**\n     * All synchronized views in the database.\n     */\n    loadedViews: View[];\n\n    /**\n     * Creates/uses database connection from the connection pool to perform further operations.\n     * Returns obtained database connection.\n     */\n    connect(): Promise<any>;\n\n    /**\n     * Releases used database connection.\n     * You cannot use query runner methods after connection is released.\n     */\n    release(): Promise<void>;\n\n    /**\n     * Removes all tables from the currently connected database.\n     * Be careful with using this method and avoid using it in production or migrations\n     * (because it can clear all your database).\n     */\n    clearDatabase(database?: string): Promise<void>;\n\n    /**\n     * Starts transaction.\n     */\n    startTransaction(isolationLevel?: IsolationLevel): Promise<void>;\n\n    /**\n     * Commits transaction.\n     * Error will be thrown if transaction was not started.\n     */\n    commitTransaction(): Promise<void>;\n\n    /**\n     * Ends transaction.\n     * Error will be thrown if transaction was not started.\n     */\n    rollbackTransaction(): Promise<void>;\n\n    /**\n     * Executes a given SQL query and returns raw database results.\n     */\n    query(query: string, parameters?: any[]): Promise<any>;\n\n    /**\n     * Returns raw data stream.\n     */\n    stream(query: string, parameters?: any[], onEnd?: Function, onError?: Function): Promise<ReadStream>;\n\n    /**\n     * Returns all available database names including system databases.\n     */\n    getDatabases(): Promise<string[]>;\n\n    /**\n     * Returns all available schema names including system schemas.\n     * If database parameter specified, returns schemas of that database.\n     * Useful for SQLServer and Postgres only.\n     */\n    getSchemas(database?: string): Promise<string[]>;\n\n    /**\n     * Loads a table by a given name from the database.\n     */\n    getTable(tablePath: string): Promise<Table|undefined>;\n\n    /**\n     * Loads all tables from the database and returns them.\n     *\n     * todo: make tablePaths optional\n     */\n    getTables(tablePaths: string[]): Promise<Table[]>;\n\n    /**\n     * Loads a view by a given name from the database.\n     */\n    getView(viewPath: string): Promise<View|undefined>;\n\n    /**\n     * Loads all views from the database and returns them.\n     */\n    getViews(viewPaths: string[]): Promise<View[]>;\n\n    /**\n     * Checks if a database with the given name exist.\n     */\n    hasDatabase(database: string): Promise<boolean>;\n\n    /**\n     * Checks if a schema with the given name exist.\n     */\n    hasSchema(schema: string): Promise<boolean>;\n\n    /**\n     * Checks if a table with the given name exist.\n     */\n    hasTable(table: Table|string): Promise<boolean>;\n\n    /**\n     * Checks if a column exist in the table.\n     */\n    hasColumn(table: Table|string, columnName: string): Promise<boolean>;\n\n    /**\n     * Creates a new database.\n     */\n    createDatabase(database: string, ifNotExist?: boolean): Promise<void>;\n\n    /**\n     * Drops database.\n     */\n    dropDatabase(database: string, ifExist?: boolean): Promise<void>;\n\n    /**\n     * Creates a new table schema.\n     */\n    createSchema(schemaPath: string, ifNotExist?: boolean): Promise<void>;\n\n    /**\n     * Drops table schema.\n     * For SqlServer can accept schema path (e.g. 'dbName.schemaName') as parameter.\n     * If schema path passed, it will drop schema in specified database.\n     */\n    dropSchema(schemaPath: string, ifExist?: boolean, isCascade?: boolean): Promise<void>;\n\n    /**\n     * Creates a new table.\n     */\n    createTable(table: Table, ifNotExist?: boolean, createForeignKeys?: boolean, createIndices?: boolean): Promise<void>;\n\n    /**\n     * Drops a table.\n     */\n    dropTable(table: Table|string, ifExist?: boolean, dropForeignKeys?: boolean, dropIndices?: boolean): Promise<void>;\n\n    /**\n     * Creates a new view.\n     */\n    createView(view: View, oldView?: View): Promise<void>;\n\n    /**\n     * Drops a view.\n     */\n    dropView(view: View|string): Promise<void>;\n\n    /**\n     * Renames a table.\n     */\n    renameTable(oldTableOrName: Table|string, newTableName: string): Promise<void>;\n\n    /**\n     * Adds a new column.\n     */\n    addColumn(table: Table|string, column: TableColumn): Promise<void>;\n\n    /**\n     * Adds new columns.\n     */\n    addColumns(table: Table|string, columns: TableColumn[]): Promise<void>;\n\n    /**\n     * Renames a column.\n     */\n    renameColumn(table: Table|string, oldColumnOrName: TableColumn|string, newColumnOrName: TableColumn|string): Promise<void>;\n\n    /**\n     * Changes a column in the table.\n     */\n    changeColumn(table: Table|string, oldColumn: TableColumn|string, newColumn: TableColumn): Promise<void>;\n\n    /**\n     * Changes columns in the table.\n     */\n    changeColumns(table: Table|string, changedColumns: { oldColumn: TableColumn, newColumn: TableColumn }[]): Promise<void>;\n\n    /**\n     * Drops a column in the table.\n     */\n    dropColumn(table: Table|string, column: TableColumn|string): Promise<void>;\n\n    /**\n     * Drops columns in the table.\n     */\n    dropColumns(table: Table|string, columns: TableColumn[]): Promise<void>;\n\n    /**\n     * Creates a new primary key.\n     */\n    createPrimaryKey(table: Table|string, columnNames: string[]): Promise<void>;\n\n    /**\n     * Updates composite primary keys.\n     */\n    updatePrimaryKeys(table: Table|string, columns: TableColumn[]): Promise<void>;\n\n    /**\n     * Drops a primary key.\n     */\n    dropPrimaryKey(table: Table|string): Promise<void>;\n\n    /**\n     * Creates a new unique constraint.\n     */\n    createUniqueConstraint(table: Table|string, uniqueConstraint: TableUnique): Promise<void>;\n\n    /**\n     * Creates new unique constraints.\n     */\n    createUniqueConstraints(table: Table|string, uniqueConstraints: TableUnique[]): Promise<void>;\n\n    /**\n     * Drops an unique constraint.\n     */\n    dropUniqueConstraint(table: Table|string, uniqueOrName: TableUnique|string): Promise<void>;\n\n    /**\n     * Drops unique constraints.\n     */\n    dropUniqueConstraints(table: Table|string, uniqueConstraints: TableUnique[]): Promise<void>;\n\n    /**\n     * Creates a new check constraint.\n     */\n    createCheckConstraint(table: Table|string, checkConstraint: TableCheck): Promise<void>;\n\n    /**\n     * Creates new check constraints.\n     */\n    createCheckConstraints(table: Table|string, checkConstraints: TableCheck[]): Promise<void>;\n\n    /**\n     * Drops a check constraint.\n     */\n    dropCheckConstraint(table: Table|string, checkOrName: TableCheck|string): Promise<void>;\n\n    /**\n     * Drops check constraints.\n     */\n    dropCheckConstraints(table: Table|string, checkConstraints: TableCheck[]): Promise<void>;\n\n    /**\n     * Creates a new exclusion constraint.\n     */\n    createExclusionConstraint(table: Table|string, exclusionConstraint: TableExclusion): Promise<void>;\n\n    /**\n     * Creates new exclusion constraints.\n     */\n    createExclusionConstraints(table: Table|string, exclusionConstraints: TableExclusion[]): Promise<void>;\n\n    /**\n     * Drops a exclusion constraint.\n     */\n    dropExclusionConstraint(table: Table|string, exclusionOrName: TableExclusion|string): Promise<void>;\n\n    /**\n     * Drops exclusion constraints.\n     */\n    dropExclusionConstraints(table: Table|string, exclusionConstraints: TableExclusion[]): Promise<void>;\n\n    /**\n     * Creates a new foreign key.\n     */\n    createForeignKey(table: Table|string, foreignKey: TableForeignKey): Promise<void>;\n\n    /**\n     * Creates new foreign keys.\n     */\n    createForeignKeys(table: Table|string, foreignKeys: TableForeignKey[]): Promise<void>;\n\n    /**\n     * Drops a foreign key.\n     */\n    dropForeignKey(table: Table|string, foreignKeyOrName: TableForeignKey|string): Promise<void>;\n\n    /**\n     * Drops foreign keys.\n     */\n    dropForeignKeys(table: Table|string, foreignKeys: TableForeignKey[]): Promise<void>;\n\n    /**\n     * Creates a new index.\n     */\n    createIndex(table: Table|string, index: TableIndex): Promise<void>;\n\n    /**\n     * Creates new indices.\n     */\n    createIndices(table: Table|string, indices: TableIndex[]): Promise<void>;\n\n    /**\n     * Drops an index.\n     */\n    dropIndex(table: Table|string, index: TableIndex|string): Promise<void>;\n\n    /**\n     * Drops indices.\n     */\n    dropIndices(table: Table|string, indices: TableIndex[]): Promise<void>;\n\n    /**\n     * Clears all table contents.\n     * Note: this operation uses SQL's TRUNCATE query which cannot be reverted in transactions.\n     */\n    clearTable(tableName: string): Promise<void>;\n\n    /**\n     * Enables special query runner mode in which sql queries won't be executed,\n     * instead they will be memorized into a special variable inside query runner.\n     * You can get memorized sql using getMemorySql() method.\n     */\n    enableSqlMemory(): void;\n\n    /**\n     * Disables special query runner mode in which sql queries won't be executed\n     * started by calling enableSqlMemory() method.\n     *\n     * Previously memorized sql will be flushed.\n     */\n    disableSqlMemory(): void;\n\n    /**\n     * Flushes all memorized sqls.\n     */\n    clearSqlMemory(): void;\n\n    /**\n     * Gets sql stored in the memory. Parameters in the sql are already replaced.\n     */\n    getMemorySql(): SqlInMemory;\n\n    /**\n     * Executes up sql queries.\n     */\n    executeMemoryUpSql(): Promise<void>;\n\n    /**\n     * Executes down sql queries.\n     */\n    executeMemoryDownSql(): Promise<void>;\n\n}\n"],"sourceRoot":".."}