当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript mysql2Types.IConnection类代码示例

本文整理汇总了TypeScript中mysql2Types.IConnection的典型用法代码示例。如果您正苦于以下问题:TypeScript IConnection类的具体用法?TypeScript IConnection怎么用?TypeScript IConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IConnection类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: rootTransaction

  /**
   * Create and execute a stored procedure as root.
   */
  async rootTransaction(body: string): Promise<void> {
    // Hash proc body to get a unique proc name.
    // This makes sure we have a unique name for each proc operation.
    const name = this.getProcedureName(body);
    const transactionQuery = `
      CREATE PROCEDURE \`${name}\`()
      BEGIN
          DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
          BEGIN
            ROLLBACK;
            RESIGNAL;
          END;
          START TRANSACTION;
          ${body}
          COMMIT;
      END;`;

    // Ensure root.
    await this.ensureRootConnection();

    // Here we'll try to create the proc, but if the proc name
    // already exists we can be sure it's the same operation
    // so we will trap the error and call the pre-defined proc.
    try {
      await this.rootConn.query(transactionQuery);
    } catch (err) {
      // If proc already exists, we are good to go.
      if (err.code !== 'ER_SP_ALREADY_EXISTS') {
        throw err;
      }
    }

    // Attempting to call proc.
    await this.callProc(name);
  }
开发者ID:WordToken,项目名称:voice-web,代码行数:38,代码来源:mysql.ts

示例2: endConnection

 /**
  * Close all connections to the database.
  */
 endConnection(): void {
   console.log(this.pool.end);
   if (this.pool) {
     this.pool.end().catch((e: any) => console.error(e));
     this.pool = null;
   }
   if (this.rootConn) {
     this.rootConn.destroy();
     this.rootConn = null;
   }
 }
开发者ID:WordToken,项目名称:voice-web,代码行数:14,代码来源:mysql.ts

示例3: rootQuery

 /**
  * Execute a regular query on the root connection.
  */
 async rootQuery(sql: string): Promise<any> {
   await this.ensureRootConnection();
   return this.rootConn.query(sql);
 }
开发者ID:WordToken,项目名称:voice-web,代码行数:7,代码来源:mysql.ts

示例4: rootExec

 /**
  * Execute a prepared statement on the root connection.
  */
 async rootExec(sql: string, values?: any[]): Promise<any> {
   values = values || [];
   await this.ensureRootConnection();
   return this.rootConn.execute(sql, values);
 }
开发者ID:WordToken,项目名称:voice-web,代码行数:8,代码来源:mysql.ts

示例5: callProc

 /**
  * Call a stored procedure by procedure name generated in getProcedureName.
  */
 async callProc(name: string): Promise<any> {
   return this.rootConn.query(`CALL \`${name}\``);
 }
开发者ID:WordToken,项目名称:voice-web,代码行数:6,代码来源:mysql.ts


注:本文中的mysql2Types.IConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。