@debugr/sql-common

中文文档
4.0.2发布于 2026/09/01MITTypeScriptESM + CJS构建来源已验证近 30 天下载 9111

Common interfaces and utility functions for SQL plugins

原始使用文档

Common SQL interfaces and utilities

This package defines the shape of the data included in entries which represent an SQL query. Plugins which produce or consume such entries should conform to this shape. Unless you're developing a Debugr plugin or log handler, you usually don't need to worry about this package, as it will be installed and used automatically when required.

For plugin developers

The package exports the following type definitions:

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;
}

There are also a couple of utility functions exported:

  • formatQueryTime(ms: number, html: boolean = false): string - This function formats the duration of an SQL query as a fraction of seconds if the duration was over 1000ms, or as milliseconds if the duration was lower, with the numeric part optionally wrapped in a HTML <strong> tag when html is set to true. For example: 35.753241 would result in 35.75 ms or <strong>35.75</strong> ms and 5645.6768576 would result in 5.64 s or <strong>5.64</strong> s.
  • createQueryFormatter(): (query: string) => string - This function attempts to load the @sqltools/formatter package and returns a preconfigured callback which converts reserved words to uppercase and inserts some strategic newlines to make the query easier to read; if the package isn't installed, it simply returns a noop callback which just returns the passed query as-is.

版本与发布记录

@debugr/sql-common 共发布 9 个版本,首次发布于 2022/08/02;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
4.0.2latest2026/09/012 个月前
4.0.12026/09/012 个月前
4.0.02026/08/142 个月前
3.0.0-rc.62023/08/153 年前
3.0.0-rc.52022/12/243 年前
3.0.0-rc.42022/11/233 年前

关于 @debugr/sql-common 的常见问题

@debugr/sql-common 是什么?

Common interfaces and utility functions for SQL plugins

如何安装 @debugr/sql-common?

在项目目录运行 npm install @debugr/sql-common,或使用 pnpm add / yarn add / bun add。

@debugr/sql-common 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@debugr/sql-common 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@debugr/sql-common 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@debugr/sql-common 可以商用吗?

@debugr/sql-common 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@debugr/sql-common 的下载量有多少?

根据 npm 官方下载统计,@debugr/sql-common 在 2026/10/12 – 2026/11/10 这 30 天内被下载 9,111 次,日均约 304 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@debugr/sql-common 还在维护吗?

最新版本 4.0.2 发布于 2026/09/01(2 个月前);至今共发布 9 个版本,其中过去 12 个月发布了 3 个;首次发布于 2022/08/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。