UNPKG

ts-mysql-analyzer

Version:

A MySQL query analyzer.

61 lines (60 loc) 2.25 kB
import { ParserOptions } from 'ts-mysql-parser'; import { Schema } from 'ts-mysql-schema'; /** Represents a diagnostic uncovered during analysis */ export interface MySQLAnalyzerDiagnostic { readonly severity: DiagnosticSeverity; /** Helpful message describing the diagnostic */ readonly message: string; /** The starting position of the diagnostic in the source text */ readonly start: number; /** The stopping position of the diagnostic in the source text */ readonly stop: number; /** The unique diagnostic code */ readonly code: number; } /** Represents the severity of the diagnostic */ export declare enum DiagnosticSeverity { /** Something suspicious but allowed */ Warning = 0, /** Something not allowed by any means */ Error = 1, /** Something to suggest a better way of doing things */ Suggestion = 2 } /** Represents the code of the diagnostic */ export declare enum DiagnosticCode { /** An empty MySQL query */ EmptyQuery = 1000, /** A query that contains a lexer error */ LexerError = 1001, /** A query that contains a parser error */ ParserError = 1002, /** A mismatch in the number of rows and columns in an INSERT statement */ ColumnRowMismatch = 1003, /** A table reference that does not exist in the schema */ MissingTable = 1004, /** A column reference that does not exist in the referenced table in the schema */ MissingColumn = 1005, /** An invalid type assignment */ TypeMismatch = 1006, /** A missing database index for a referenced column */ MissingIndex = 1007 } /** Represents the options passed to the analyzer */ export interface MySQLAnalyzerOptions { /** The options passed to the underlying MySQL parser */ readonly parserOptions?: ParserOptions; /** The schema that represents the structure of a MySQL database */ readonly schema?: Schema; } export declare class MySQLAnalyzer { parserOptions?: ParserOptions; schema?: Schema; constructor(options?: MySQLAnalyzerOptions); analyze(text: string): MySQLAnalyzerDiagnostic[]; private analyzeSyntax; private analyzeSemantics; private analyzeTables; private analyzeColumns; private analyzeColumn; }