當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。