【问题标题】:How can I get the real underlying database connection from an existing QueryRunner in TypeORM?如何从 TypeORM 中的现有 QueryRunner 获取真正的底层数据库连接?
【发布时间】:2021-02-17 04:50:16
【问题描述】:

我有一个QueryRunner 的实例,我需要获取通过驱动程序建立的真正的底层数据库连接,在本例中是mysqljs。

【问题讨论】:

    标签: mysql node.js typeorm


    【解决方案1】:

    我最终通读了 TypeORMs 代码,碰巧我只需要再次调用QueryRunner#connect(),它就会返回已经建立的连接。

    https://github.com/typeorm/typeorm/blob/master/src/driver/mysql/MysqlQueryRunner.ts

    以下是源代码中的相关文档:

       /**
         * Creates/uses database connection from the connection pool to perform further operations.
         * Returns obtained database connection.
         */
        connect(): Promise<any> {
            if (this.databaseConnection)
                return Promise.resolve(this.databaseConnection);
    

    【讨论】:

      猜你喜欢
      • 2011-04-14
      • 2011-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-02
      • 2016-04-10
      • 2020-10-22
      相关资源
      最近更新 更多