UNPKG

quicklite

Version:

A lightweight ORM toolkit for SQLite in Node.js applications

80 lines (79 loc) 1.75 kB
import Database from 'better-sqlite3'; /** * 查询计划项,表示SQL执行计划中的一个节点 * * @interface QueryPlan */ export interface QueryPlan { /** * 计划ID */ id: number; /** * 父计划ID */ parentId: number | null; /** * 详细说明 */ detail: string; } /** * 查询分析结果 * * @interface QueryAnalysisResult */ export interface QueryAnalysisResult { /** * SQL语句 */ sql: string; /** * 查询执行计划 */ queryPlan: QueryPlan[]; /** * 执行时间(毫秒) */ executionTime: number; /** * 性能建议 */ suggestions: string[]; } /** * SQL查询分析器类 * 提供分析查询性能、生成优化建议和索引推荐的功能 * * 兼容 better-sqlite3 v11.8.1 及 SQLite 3.48.0 */ export declare class QueryAnalyzer { /** * 分析SQL查询 * @param db 数据库实例 * @param sql SQL查询语句 * @param params 查询参数 * @returns 分析结果 */ static analyze(db: Database.Database, sql: string, params?: any[]): QueryAnalysisResult; /** * 分析查询计划,提供优化建议 * @param queryPlan 查询计划 * @param sql 原始SQL * @returns 优化建议 */ private static analyzePlan; /** * 查找查询中使用的表名 * @param sql SQL查询语句 * @returns 表名数组 */ static extractTableNames(sql: string): string[]; /** * 生成可能有用的索引建议 * @param db 数据库实例 * @param sql SQL查询语句 * @returns 索引建议 */ static suggestIndices(db: Database.Database, sql: string): string[]; }