UNPKG

rhombic

Version:

SQL parsing, lineage extraction and manipulation

81 lines 3.02 kB
import { StatementContext } from "./SqlBaseParser"; import { Cursor } from "./Cursor"; import { LineageParserOptions, SqlLineageParseTree } from "./SqlLineageParseTree"; /** * Additional options when parsing for suggestions. Contains the cursor position. */ export interface CompletionParserOptions extends LineageParserOptions { /** * The cursor position used to identify the completion "context". Completion suggestions do often have to * be provided for invalid queries, for example due to trailing commas (after which a user expects suggestions). * To make sure the parser can handle such queries, it will first insert a parseable placeholder at the * specified position. When computing completions, we can then look for that placeholder to identify the * context (subquery clause) in which to complete. */ cursorPosition: { lineNumber: number; column: number; }; } export declare const isCompletionOptions: (options: LineageParserOptions | CompletionParserOptions) => options is CompletionParserOptions; interface Named { name: string; } /** * A `MetadataProvider` allows access to metadata of a project. It's used to compute * completion suggestions. */ export interface MetadataProvider<Catalog extends Named = Named, Schema extends Named = Named, Table extends Named = Named, Column extends Named = Named> { getCatalogs: () => Catalog[]; getSchemas: (arg?: { catalog: string; }) => Schema[]; getTables: (args?: { catalogOrSchema: string; schema?: string; }) => Table[]; getColumns: (args: { table: string; catalogOrSchema?: string; schema?: string; }) => Column[]; } /** * Possible suggestion items for auto completion. * "keyword" is not used right now but will likely be added later */ export declare type CompletionItem<Catalog = Named, Schema = Named, Table = Named, Column = Named> = { type: "keyword"; value: string; } | { type: "catalog"; value: Catalog; } | { type: "schema"; value: Schema; } | { type: "relation"; value: string; desc?: Table; } | { type: "column"; relation?: string; value: string; desc?: Column; } | { type: "snippet"; label: string; template: string; }; export declare class SqlCompletionParseTree extends SqlLineageParseTree { constructor(tree: StatementContext, cursor: Cursor); /** * This method computes completion suggestions at the cursor position for the parsed query. * * @param metadataProvider Metadata lookup functions * @returns A list of possible completions at the cursor position in the parsed query */ getSuggestions<Catalog extends Named = Named, Schema extends Named = Named, Table extends Named = Named, Column extends Named = Named>(metadataProvider: MetadataProvider<Catalog, Schema, Table, Column>): CompletionItem<Catalog, Schema, Table, Column>[]; } export {}; //# sourceMappingURL=SqlCompletionParseTree.d.ts.map