UNPKG

rawsql-ts

Version:

High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.

42 lines (41 loc) 2.01 kB
import type { ColumnDefinition, SchemaRegistry } from '../utils/SchemaManager'; import type { ValueComponent } from './ValueComponent'; import type { CreateTableQuery } from './CreateTableQuery'; /** * Column metadata that augments the SchemaManager definition with * type, nullability, and default information for insert simulation. */ export interface TableColumnDefinitionModel extends ColumnDefinition { /** SQL type that should be used when casting inserted values. */ typeName?: string; /** Whether a value is required in the INSERT statement (NOT NULL without default). */ required?: boolean; /** Expression text or AST from DDL that represents the column default, if any. */ defaultValue?: string | ValueComponent | null; /** Whether the column can accept null values, based on DDL constraints. */ isNotNull?: boolean; } /** * A description of a table that is rich enough to drive insert simulation. */ export interface TableDefinitionModel { /** The actual name of the table (including schema if provided). */ name: string; /** Columns in the order they are defined in the table. */ columns: TableColumnDefinitionModel[]; } /** Registry keyed by table name (case-sensitive as provided by the caller). */ export type TableDefinitionRegistry = Record<string, TableDefinitionModel>; /** * Helper to reformat a SchemaManager registry into the format consumed * by the insert-to-select transformer. */ export declare function createTableDefinitionRegistryFromSchema(schema: SchemaRegistry): TableDefinitionRegistry; /** * Convert a parsed CREATE TABLE query into the table definition model used by transformers. */ export declare function createTableDefinitionFromCreateTableQuery(query: CreateTableQuery): TableDefinitionModel; /** * Build a registry of table definitions from a batch of CREATE TABLE AST results. */ export declare function createTableDefinitionRegistryFromCreateTableQueries(queries: CreateTableQuery[]): TableDefinitionRegistry;