gpt4 book ai didi

sql-server - 用 mssql Sequelize afterConnect 钩子(Hook)(乏味)

转载 作者:行者123 更新时间:2023-12-03 22:25:45 30 4
gpt4 key购买 nike

在尝试使用 MSSQL 注入(inject)准备好的语句时(乏味) - 一旦我尝试执行请求,我就会收到以下错误:
Database connection failed: Requests can only be made in the LoggedIn state, not the SentClientRequest state
进口:

import { Connection, Request } from 'tedious';

钩子(Hook):

public static async afterConnect(connection, options): Promise<void> {
const client = connection['resource'] as Connection;

let request = new Request('select 42',(err, rowCount, rows) => {
console.log(`${err} ${rowCount} rows`);
});

client.execSql(request);
}

根据 tedious 我需要在前一个请求之后链接请求,sequelize 似乎没有传递该数据,有没有办法解决这个问题?

我还在 Sequelize GitHub 上创建了一个问题

最佳答案

在 sequelize 代码中进行了一些挖掘,但找到了解决方法 - 如果有人有类似的问题。

public static async afterConnect(connection, options): Promise<void> {
const mssql = connection as { resource: Connection; previous: Promise<unknown> };

await new Promise((resolve) => {
let request = new Request('select 42', (err, rowCount) => {
logger.debug(method, `${err} - ${rowCount} rows`);

resolve();
});

await mssql.previous; // failsafe?
mssql.resource.execSql(request);
});
}

关于sql-server - 用 mssql Sequelize afterConnect 钩子(Hook)(乏味),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62066046/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com