通用SQL接口和公用事业
此软件包定义了 data 包含在条目中
代表 SQL 查询。 生成或消耗此类条目的插件
应该符合这个形状。 除非你正在开发调试器插件
或日志处理器,你通常不需要担心 这个包,因为它会
在需要时自动安装和使用.
用于插件开发者
该套件输出以下类型定义:
export interface SqlQueryData {
query: string; // The SQL query
parameters?: any[]; // Any parameters passed to the SQL query
error?: string; // Any error message produced by the query
stack?: string; // Stack trace for the call which issued a query
affectedRows?: number; // The number of rows affected by a DML query
rows?: number; // The number of rows selected by a DQL query
time?: number; // The time the query took to execute
}
export interface SqlQueryLogEntry<
TTaskContext extends TContextBase = TContextBase,
TGlobalContext extends TContextShape = TContextShape,
> extends LogEntry<TTaskContext, TGlobalContext> {
type: 'sql.query';
data: SqlQueryData;
}
另外还输出了几种公用功能:
formatQueryTime(ms: number, html: boolean = false): string- 此函数格式化 SQL 查询的持续时间 如果持续时间超过1 000毫秒,则作为分秒数;如果持续时间低于1 000毫秒,则作为分秒数 在 HTML 中可选择包裹的数字部分<strong>标记当html设置为true。例如:35.753241会导致35.75 ms或者说<strong>35.75</strong> ms财务报告和审定财务报表5645.6768576会导致5.64 s或者说<strong>5.64</strong> s。 。 。 .createQueryFormatter(): (query: string) => string- 此函数试图加载@sqltools/formatter软件包并返回预配置回调,将保留的单词转换为大写并插入一些策略 使查询更容易读取的新行; 如果软件包没有安装, 它只返回一个 noop 调用 返回所经过的查询.