本文整理汇总了TypeScript中mysql2Types.IConnection.query方法的典型用法代码示例。如果您正苦于以下问题:TypeScript IConnection.query方法的具体用法?TypeScript IConnection.query怎么用?TypeScript IConnection.query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mysql2Types.IConnection
的用法示例。
在下文中一共展示了IConnection.query方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例2: rootQuery
/**
* Execute a regular query on the root connection.
*/
async rootQuery(sql: string): Promise<any> {
await this.ensureRootConnection();
return this.rootConn.query(sql);
}
示例3: callProc
/**
* Call a stored procedure by procedure name generated in getProcedureName.
*/
async callProc(name: string): Promise<any> {
return this.rootConn.query(`CALL \`${name}\``);
}