In Part 1, we set up our development environment and outlined the project structure. Now, we’ll dive into implementing the core functionality of DataDiluvium, starting with SQL schema parsing and the user interface for schema input.
SQL Schema Parsing Implementation
1. SQL Parser Setup
The SQL parser is implemented in src/app/lib/parsers/sqlParser.ts. This module is responsible for:
- Parsing SQL schema definitions using the
node-sql-parserlibrary - Extracting table and column information
- Mapping SQL data types to appropriate data generators
The parser works by:
- Taking a SQL string input
- Converting it to an Abstract Syntax Tree (AST)
- Traversing the AST to extract:
- Table names
- Column names
- Data types
- Default values
- Foreign key relationships
The SchemaColumn type defines the structure of our parsed columns:
export type SchemaColumn = {
tableName: string;
columnName: string;
dataType: string;
defaultValue: string | null;
generator?: string;
referencedTable?: string;
referencedColumn?: string;
};
You must be logged in to post a comment.