API 参考
    正在准备搜索索引...

    Runs queries on a single database connection.

    interface QueryRunner {
        broadcaster: Broadcaster;
        connection: DataSource;
        data: ObjectLiteral;
        isReleased: boolean;
        isTransactionActive: boolean;
        loadedTables: Table[];
        loadedViews: View[];
        manager: EntityManager;
        addColumn(table: string | Table, column: TableColumn): Promise<void>;
        addColumns(table: string | Table, columns: TableColumn[]): Promise<void>;
        afterMigration(): Promise<void>;
        beforeMigration(): Promise<void>;
        changeColumn(
            table: string | Table,
            oldColumn: string | TableColumn,
            newColumn: TableColumn,
        ): Promise<void>;
        changeColumns(
            table: string | Table,
            changedColumns: { newColumn: TableColumn; oldColumn: TableColumn }[],
        ): Promise<void>;
        changeTableComment(
            tableOrName: string | Table,
            comment?: string,
        ): Promise<void>;
        clearDatabase(database?: string): Promise<void>;
        clearSqlMemory(): void;
        clearTable(tableName: string): Promise<void>;
        commitTransaction(): Promise<void>;
        connect(): Promise<any>;
        createCheckConstraint(
            table: string | Table,
            checkConstraint: TableCheck,
        ): Promise<void>;
        createCheckConstraints(
            table: string | Table,
            checkConstraints: TableCheck[],
        ): Promise<void>;
        createDatabase(database: string, ifNotExist?: boolean): Promise<void>;
        createExclusionConstraint(
            table: string | Table,
            exclusionConstraint: TableExclusion,
        ): Promise<void>;
        createExclusionConstraints(
            table: string | Table,
            exclusionConstraints: TableExclusion[],
        ): Promise<void>;
        createForeignKey(
            table: string | Table,
            foreignKey: TableForeignKey,
        ): Promise<void>;
        createForeignKeys(
            table: string | Table,
            foreignKeys: TableForeignKey[],
        ): Promise<void>;
        createIndex(table: string | Table, index: TableIndex): Promise<void>;
        createIndices(table: string | Table, indices: TableIndex[]): Promise<void>;
        createPrimaryKey(
            table: string | Table,
            columnNames: string[],
            constraintName?: string,
        ): Promise<void>;
        createSchema(schemaPath: string, ifNotExist?: boolean): Promise<void>;
        createTable(
            table: Table,
            ifNotExist?: boolean,
            createForeignKeys?: boolean,
            createIndices?: boolean,
        ): Promise<void>;
        createUniqueConstraint(
            table: string | Table,
            uniqueConstraint: TableUnique,
        ): Promise<void>;
        createUniqueConstraints(
            table: string | Table,
            uniqueConstraints: TableUnique[],
        ): Promise<void>;
        createView(
            view: View,
            syncWithMetadata?: boolean,
            oldView?: View,
        ): Promise<void>;
        disableSqlMemory(): void;
        dropCheckConstraint(
            table: string | Table,
            checkOrName: string | TableCheck,
        ): Promise<void>;
        dropCheckConstraints(
            table: string | Table,
            checkConstraints: TableCheck[],
        ): Promise<void>;
        dropColumn(
            table: string | Table,
            column: string | TableColumn,
        ): Promise<void>;
        dropColumns(
            table: string | Table,
            columns: string[] | TableColumn[],
        ): Promise<void>;
        dropDatabase(database: string, ifExist?: boolean): Promise<void>;
        dropExclusionConstraint(
            table: string | Table,
            exclusionOrName: string | TableExclusion,
        ): Promise<void>;
        dropExclusionConstraints(
            table: string | Table,
            exclusionConstraints: TableExclusion[],
        ): Promise<void>;
        dropForeignKey(
            table: string | Table,
            foreignKeyOrName: string | TableForeignKey,
        ): Promise<void>;
        dropForeignKeys(
            table: string | Table,
            foreignKeys: TableForeignKey[],
        ): Promise<void>;
        dropIndex(table: string | Table, index: string | TableIndex): Promise<void>;
        dropIndices(table: string | Table, indices: TableIndex[]): Promise<void>;
        dropPrimaryKey(
            table: string | Table,
            constraintName?: string,
        ): Promise<void>;
        dropSchema(
            schemaPath: string,
            ifExist?: boolean,
            isCascade?: boolean,
        ): Promise<void>;
        dropTable(
            table: string | Table,
            ifExist?: boolean,
            dropForeignKeys?: boolean,
            dropIndices?: boolean,
        ): Promise<void>;
        dropUniqueConstraint(
            table: string | Table,
            uniqueOrName: string | TableUnique,
        ): Promise<void>;
        dropUniqueConstraints(
            table: string | Table,
            uniqueConstraints: TableUnique[],
        ): Promise<void>;
        dropView(view: string | View): Promise<void>;
        enableSqlMemory(): void;
        executeMemoryDownSql(): Promise<void>;
        executeMemoryUpSql(): Promise<void>;
        getCurrentDatabase(): Promise<undefined | string>;
        getCurrentSchema(): Promise<undefined | string>;
        getDatabases(): Promise<string[]>;
        getMemorySql(): SqlInMemory;
        getReplicationMode(): ReplicationMode;
        getSchemas(database?: string): Promise<string[]>;
        getTable(tablePath: string): Promise<undefined | Table>;
        getTables(tablePaths?: string[]): Promise<Table[]>;
        getView(viewPath: string): Promise<undefined | View>;
        getViews(viewPaths?: string[]): Promise<View[]>;
        hasColumn(table: string | Table, columnName: string): Promise<boolean>;
        hasDatabase(database: string): Promise<boolean>;
        hasSchema(schema: string): Promise<boolean>;
        hasTable(table: string | Table): Promise<boolean>;
        query(
            query: string,
            parameters: undefined | any[],
            useStructuredResult: true,
        ): Promise<QueryResult>;
        query(query: string, parameters?: any[]): Promise<any>;
        release(): Promise<void>;
        renameColumn(
            table: string | Table,
            oldColumnOrName: string | TableColumn,
            newColumnOrName: string | TableColumn,
        ): Promise<void>;
        renameTable(
            oldTableOrName: string | Table,
            newTableName: string,
        ): Promise<void>;
        rollbackTransaction(): Promise<void>;
        startTransaction(isolationLevel?: IsolationLevel): Promise<void>;
        stream(
            query: string,
            parameters?: any[],
            onEnd?: Function,
            onError?: Function,
        ): Promise<ReadStream>;
        updatePrimaryKeys(
            table: string | Table,
            columns: TableColumn[],
        ): Promise<void>;
    }
    索引

    属性

    broadcaster: Broadcaster

    Broadcaster used on this query runner to broadcast entity events.

    connection: DataSource

    Connection used by this query runner.

    Stores temporarily user data. Useful for sharing data with subscribers.

    isReleased: boolean

    Indicates if connection for this query runner is released. Once its released, query runner cannot run queries anymore.

    isTransactionActive: boolean

    Indicates if transaction is in progress.

    loadedTables: Table[]

    All synchronized tables in the database.

    Call getTables()

    loadedViews: View[]

    All synchronized views in the database.

    Call getViews()

    manager: EntityManager

    Entity manager working only with this query runner.

    方法

    • Adds a new column.

      参数

      返回 Promise<void>

    • Adds new columns.

      参数

      返回 Promise<void>

    • Called after migrations are run.

      返回 Promise<void>

    • Called before migrations are run.

      返回 Promise<void>

    • Changes a column in the table.

      参数

      返回 Promise<void>

    • Changes columns in the table.

      参数

      返回 Promise<void>

    • Change table comment. Only supports MySQL and MariaDB

      参数

      • tableOrName: string | Table
      • 可选comment: string

      返回 Promise<void>

    • Removes all tables from the currently connected database. Be careful with using this method and avoid using it in production or migrations (because it can clear all your database).

      参数

      • 可选database: string

      返回 Promise<void>

    • Flushes all memorized sqls.

      返回 void

    • Clears all table contents. Note: this operation uses SQL's TRUNCATE query which cannot be reverted in transactions.

      参数

      • tableName: string

      返回 Promise<void>

    • Commits transaction. Error will be thrown if transaction was not started.

      返回 Promise<void>

    • Creates/uses database connection from the connection pool to perform further operations. Returns obtained database connection.

      返回 Promise<any>

    • Creates a new check constraint.

      参数

      返回 Promise<void>

    • Creates new check constraints.

      参数

      返回 Promise<void>

    • Creates a new database.

      参数

      • database: string
      • 可选ifNotExist: boolean

      返回 Promise<void>

    • Creates a new exclusion constraint.

      参数

      返回 Promise<void>

    • Creates new exclusion constraints.

      参数

      返回 Promise<void>

    • Creates a new foreign key.

      参数

      返回 Promise<void>

    • Creates new foreign keys.

      参数

      返回 Promise<void>

    • Creates a new index.

      参数

      返回 Promise<void>

    • Creates new indices.

      参数

      返回 Promise<void>

    • Creates a new primary key.

      参数

      • table: string | Table
      • columnNames: string[]
      • 可选constraintName: string

      返回 Promise<void>

    • Creates a new table schema.

      参数

      • schemaPath: string
      • 可选ifNotExist: boolean

      返回 Promise<void>

    • Creates a new table.

      参数

      • table: Table
      • 可选ifNotExist: boolean
      • 可选createForeignKeys: boolean
      • 可选createIndices: boolean

      返回 Promise<void>

    • Creates a new unique constraint.

      参数

      返回 Promise<void>

    • Creates new unique constraints.

      参数

      返回 Promise<void>

    • Creates a new view.

      参数

      • view: View
      • 可选syncWithMetadata: boolean
      • 可选oldView: View

      返回 Promise<void>

    • Disables special query runner mode in which sql queries won't be executed started by calling enableSqlMemory() method.

      Previously memorized sql will be flushed.

      返回 void

    • Drops a check constraint.

      参数

      返回 Promise<void>

    • Drops check constraints.

      参数

      返回 Promise<void>

    • Drops a column in the table.

      参数

      返回 Promise<void>

    • Drops columns in the table.

      参数

      返回 Promise<void>

    • Drops database.

      参数

      • database: string
      • 可选ifExist: boolean

      返回 Promise<void>

    • Drops a exclusion constraint.

      参数

      返回 Promise<void>

    • Drops exclusion constraints.

      参数

      返回 Promise<void>

    • Drops a foreign key.

      参数

      返回 Promise<void>

    • Drops foreign keys.

      参数

      返回 Promise<void>

    • Drops an index.

      参数

      返回 Promise<void>

    • Drops indices.

      参数

      返回 Promise<void>

    • Drops a primary key.

      参数

      • table: string | Table
      • 可选constraintName: string

      返回 Promise<void>

    • Drops table schema. For SqlServer can accept schema path (e.g. 'dbName.schemaName') as parameter. If schema path passed, it will drop schema in specified database.

      参数

      • schemaPath: string
      • 可选ifExist: boolean
      • 可选isCascade: boolean

      返回 Promise<void>

    • Drops a table.

      参数

      • table: string | Table
      • 可选ifExist: boolean
      • 可选dropForeignKeys: boolean
      • 可选dropIndices: boolean

      返回 Promise<void>

    • Drops an unique constraint.

      参数

      返回 Promise<void>

    • Drops unique constraints.

      参数

      返回 Promise<void>

    • Drops a view.

      参数

      返回 Promise<void>

    • Enables special query runner mode in which sql queries won't be executed, instead they will be memorized into a special variable inside query runner. You can get memorized sql using getMemorySql() method.

      返回 void

    • Executes down sql queries.

      返回 Promise<void>

    • Executes up sql queries.

      返回 Promise<void>

    • Loads currently using database

      返回 Promise<undefined | string>

    • Loads currently using database schema

      返回 Promise<undefined | string>

    • Returns all available database names including system databases.

      返回 Promise<string[]>

    • Gets sql stored in the memory. Parameters in the sql are already replaced.

      返回 SqlInMemory

    • Returns replication mode (ex: master or slave).

      返回 ReplicationMode

    • Returns all available schema names including system schemas. If database parameter specified, returns schemas of that database. Useful for SQLServer and Postgres only.

      参数

      • 可选database: string

      返回 Promise<string[]>

    • Loads a table by a given name from the database.

      参数

      • tablePath: string

      返回 Promise<undefined | Table>

    • Loads all tables from the database and returns them.

      参数

      • 可选tablePaths: string[]

      返回 Promise<Table[]>

    • Loads a view by a given name from the database.

      参数

      • viewPath: string

      返回 Promise<undefined | View>

    • Loads all views from the database and returns them.

      参数

      • 可选viewPaths: string[]

      返回 Promise<View[]>

    • Checks if a column exist in the table.

      参数

      • table: string | Table
      • columnName: string

      返回 Promise<boolean>

    • Checks if a database with the given name exist.

      参数

      • database: string

      返回 Promise<boolean>

    • Checks if a schema with the given name exist.

      参数

      • schema: string

      返回 Promise<boolean>

    • Checks if a table with the given name exist.

      参数

      返回 Promise<boolean>

    • Executes a given SQL query and returns raw database results.

      参数

      • query: string
      • parameters: undefined | any[]
      • useStructuredResult: true

      返回 Promise<QueryResult>

    • Executes a given SQL query and returns raw database results.

      参数

      • query: string
      • 可选parameters: any[]

      返回 Promise<any>

    • Releases used database connection. You cannot use query runner methods after connection is released.

      返回 Promise<void>

    • Renames a column.

      参数

      返回 Promise<void>

    • Renames a table.

      参数

      • oldTableOrName: string | Table
      • newTableName: string

      返回 Promise<void>

    • Rollbacks transaction. Error will be thrown if transaction was not started.

      返回 Promise<void>

    • Starts transaction.

      参数

      • 可选isolationLevel: IsolationLevel

      返回 Promise<void>

    • Returns raw data stream.

      参数

      • query: string
      • 可选parameters: any[]
      • 可选onEnd: Function
      • 可选onError: Function

      返回 Promise<ReadStream>

    • Updates composite primary keys.

      参数

      返回 Promise<void>