'use client'; import { ExportedStats } from "../optimizer/statistics.mjs"; import { RootIndexCandidate } from "../optimizer/genalgo.mjs"; import { Nudge } from "./nudges.mjs"; import { ColumnReferencePart } from "./walker.mjs"; import { NullTestType, SortByDir, SortByNulls } from "@pgsql/types"; //#region src/sql/analyzer.d.ts interface DatabaseDriver { query(query: string, params: unknown[]): Promise; } declare const ignoredIdentifier = "__qd_placeholder"; interface SQLCommenterTag { key: string; value: string; } type SortContext = { dir: SortByDir; nulls: SortByNulls; }; type DiscoveredColumnReference = { /** How often the column reference appears in the query. */frequency: number; /** * Representation of the column reference exactly * as it appears in the query. */ representation: string; /** * Parts of the column reference separated by dots in the query. * The table reference (if it exists) is resolved if the query * uses an alias. * * Has 3 different potential configurations (in theory) * `a.b.c` - a column reference with a table and a schema reference * `a.b` - a column reference with a table reference but no schema * `a` - a column reference with no table reference. * * We use a simple array here to allow parsing of any syntactically correct * but logically incorrect query. The checks happen later when we're deriving * potential indexes from parts of a column reference in `deriveIndexes` */ parts: ColumnReferencePart[]; /** * Whether the column reference is invalid. This */ ignored: boolean; /** The position of the column reference in the query. */ position: { start: number; end: number; }; /** * A sort direction associated by the column reference. * Only relevant to references from sorts */ sort?: SortContext; where?: { nulltest?: NullTestType; }; jsonbOperator?: JsonbOperator; jsonbExtraction?: string; }; type JsonbOperator = "@>" | "?" | "?|" | "?&" | "@@" | "@?"; type StatementType = "select" | "insert" | "update" | "delete" | "merge" | "other"; /** A function defined by @pgsql/parser */ type Parser = (query: string) => Promise; type TableReference = { schema?: string; table: string; }; type AnalysisResult = { statementType: StatementType; indexesToCheck: DiscoveredColumnReference[]; ansiHighlightedQuery: string; referencedTables: TableReference[]; shadowedAliases: ColumnReferencePart[]; tags: SQLCommenterTag[]; queryWithoutTags: string; formattedQueryWithoutTags?: string; nudges: Nudge[]; }; type SQLCommenterExtraction = { tags: SQLCommenterTag[]; queryWithoutTags: string; }; /** * Analyzes a query and returns a list of column references that * should be indexed. * * This should be instantiated once per analyzed query. */ declare class Analyzer { private readonly parser; constructor(parser: Parser); analyze(query: string, formattedQuery?: string): Promise; deriveIndexes(tables: ExportedStats[], discovered: DiscoveredColumnReference[], referencedTables: TableReference[]): RootIndexCandidate[]; private filterReferences; private hasColumn; private colorizeKeywords; /** * Resolves aliases such as `a.b` to `x.b` if `a` is a known * alias to a table called x. * * Ignores all other combination of parts such as `a.b.c` */ private resolveTableAliases; private normalize; private extractSqlcommenter; } //#endregion export { AnalysisResult, Analyzer, DatabaseDriver, DiscoveredColumnReference, JsonbOperator, Parser, SQLCommenterExtraction, SQLCommenterTag, SortContext, StatementType, TableReference, ignoredIdentifier }; //# sourceMappingURL=analyzer.d.mts.map