rawsql-ts
Version:
High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.
44 lines (43 loc) • 1.81 kB
TypeScript
import { CreateTableQuery } from '../models/CreateTableQuery';
import { QualifiedName } from '../models/ValueComponent';
export type RelationConstraintKind = 'column-reference' | 'table-foreign-key';
export type RelationEvidenceKind = RelationConstraintKind | 'primary-key' | 'unique-key';
export type RelationConfidence = 'confirmed' | 'inferred' | 'unknown';
export interface RelationGraphEdge {
childTable: string;
parentTable: string;
childColumns: string[];
parentColumns: string[];
constraintKind: RelationConstraintKind;
constraintName: string | null;
/**
* Evidence behind the relation edge. v1 uses FK evidence, but callers can
* keep the same edge shape when PK / UNIQUE inference is added later.
*/
evidenceKind: RelationEvidenceKind;
/**
* Indicates whether the relation is directly confirmed or inferred from
* broader schema evidence.
*/
confidence: RelationConfidence;
isSelfReference: boolean;
}
export interface RelationGraph {
relations: RelationGraphEdge[];
byChildTable: Map<string, RelationGraphEdge[]>;
byParentTable: Map<string, RelationGraphEdge[]>;
tableNames: Set<string>;
}
/**
* Build a direction-aware relation graph from parsed CREATE TABLE statements.
*/
export declare function buildRelationGraphFromCreateTableQueries(queries: CreateTableQuery[]): RelationGraph;
/**
* Return the known parent relations for a child table.
*/
export declare function getOutgoingRelations(graph: RelationGraph, childTable: string): RelationGraphEdge[];
/**
* Return the known child relations for a parent table.
*/
export declare function getIncomingRelations(graph: RelationGraph, parentTable: string): RelationGraphEdge[];
export declare function getQualifiedNameText(value: QualifiedName): string;