In Parts 1 and 2, I set up the development environment and implemented the schema parsing functionality. Now, I’ll explore the data generation system and final implementation details that make DataDiluvium a complete solution.
Data Generation System
1. Generator Registry
I’ve implemented the generator system in src/app/lib/generators/registry.ts. This registry manages different types of data generators:
import { Generator } from './types';
import { SequentialNumberGenerator } from './basic';
import { UsernameGenerator } from './basic';
import { DateGenerator } from './basic';
import { ForeignKeyGenerator } from './basic';
export const generatorRegistry = new Map<string, Generator>();
// Register built-in generators
generatorRegistry.set('Sequential Number', new SequentialNumberGenerator());
generatorRegistry.set('Username', new UsernameGenerator());
generatorRegistry.set('Date', new DateGenerator());
generatorRegistry.set('Foreign Key', new ForeignKeyGenerator());
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-parser library
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:
DataDiluvium is a web-based tool I’ve built designed to help developers, database administrators, and data engineers generate realistic test data based on SQL schema definitions. The tool takes SQL table definitions as input and produces sample data in various formats, making it easier to populate development and testing environments with meaningful data.
DataDiluvium is a web-based tool available at datadiluvium.com that helps developers, database administrators, and data engineers generate realistic test data from SQL schema definitions. Whether you’re setting up a development environment, creating test scenarios, or preparing data for demonstrations, DataDiluvium streamlines the process of data generation.
What is DataDiluvium?
Purpose
DataDiluvium serves several key purposes:
Development Environment Setup: Quickly populate development databases with meaningful test data
Testing: Generate consistent test data for automated testing scenarios
Demonstrations: Create realistic data sets for product demonstrations
Data Migration Testing: Validate data migration scripts with generated test data
Schema Validation: Test database schema designs with realistic data
Enter your SQL schema definition in the text area
Example:
CREATE TABLE users (
id INT PRIMARY KEY,
username VARCHAR(50) NOT NULL,
email VARCHAR(100) NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE orders (
id INT PRIMARY KEY,
user_id INT,
total_amount DECIMAL(10,2),
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id)
);
The application will automatically:
Parse your schema
Validate the structure
Suggest appropriate data generators
Show a preview of the parsed schema
3. Configuring Data Generation
For each column, you can:
Select a data generator
Set custom parameters
Define relationships
Available generators include:
Sequential Numbers
Usernames
Email addresses
Dates
Foreign Keys
Custom text
And more…
Set the number of rows to generate:
Global row count for all tables
Table-specific row counts
Preview sample data before generation
4. Generating Data
Click the “Generate” button
Review the generation summary
Confirm the generation
Wait for the process to complete
5. Exporting Data
Choose your preferred export format:
JSON: Standard JSON format with columns and rows
JSON (rich): Array of objects with column names as keys
CSV: Comma-separated values with headers
XML: Structured XML format
Plain Text: Human-readable format with numbered rows
SQL Inserts: Ready-to-use SQL INSERT statements
Click the “Export” button
Files will be downloaded automatically:
One file per table
Named according to the table name
Appropriate file extension based on format
Best Practices
1. Schema Design
Use clear, descriptive table and column names
Include appropriate constraints
Define foreign key relationships
Use appropriate data types
2. Data Generation
Start with a small number of rows for testing
Use appropriate generators for each column type
Consider data relationships when setting up foreign keys
Preview data before generating large sets
3. Export Selection
Choose JSON for application development
Use CSV for spreadsheet applications
Select SQL Inserts for direct database population
Consider Plain Text for human review
Example Workflow
Scenario: Setting up a Development Environment
Define Schema
CREATE TABLE products (
id INT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
price DECIMAL(10,2),
category_id INT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE categories (
id INT PRIMARY KEY,
name VARCHAR(50) NOT NULL
);
Configure Generators
id: Sequential Number
name: Product Name
price: Random Decimal (10-1000)
category_id: Foreign Key to categories
created_at: Current Date
Generate Data
Set 100 rows for products
Set 10 rows for categories
Generate and review
Export
Choose SQL Inserts format
Download and execute in your development database
Tips and Tricks
1. Performance
Generate data in smaller batches for large schemas
DataDiluvium provides a user-friendly and powerful solution for generating test data from SQL schemas. Whether you’re a developer setting up a new project or a database administrator preparing test environments, DataDiluvium streamlines the process of data generation and helps ensure data quality and consistency.
Hello fellow coders, AI nerdists (ok, IYKYK, “machine learning LLMs nerdists), and language enthusiasts! Adron here, ready to dive into an exciting new series that’s all about pushing the boundaries of our programming prowess. If you’ve followed my work, you know I’m often delving into exploring the depths of code (or systems in general), optimizing it, and sharing those insights with all of you. This time, we’re taking things up a notch by blending the art of manual code slinging and then shifting over and giving the power of artificial intelligence (AI) a try. Ok, my nitpick has already struck. This isn’t really AI but is really just the power of LLMs and machine learning, the ole’ Chat GPT and CoPilot and Claude and whatever else, that I’ll be diving into. Let’s go and put em’ to the test.
The Journey
Our journey starts with tackling programming problems the old-fashioned way: rolling up our sleeves and solving them manually. This is where we lay the groundwork, understand the problem’s intricacies, and come up with a solution that, while not perfect, gets the job done. Then, we refactor our code, streamlining and optimizing it to make it more efficient and elegant.
Enter the AI
Once we’ve got a solid foundation, it’s time to bring in the big guns – artificial intelligence. We’ll explore various AI tools, from ChatGPT-4 to Claude and beyond, to see how they tackle the same problems. Each AI brings its unique approach and strengths to the table, and we’ll break down their solutions, comparing them to our manual efforts.
Why This Matters
In today’s fast-paced tech world, understanding how to leverage AI in our coding practices is crucial. This series isn’t just about showcasing cool AI tools; it’s about understanding their capabilities, limitations, and how they can augment our problem-solving skills. By the end of this journey, you’ll have a deeper appreciation for both human ingenuity and AI’s potential.
What to Expect
In each post, you’ll find:
The Hand Crafted Solution: A detailed walkthrough of solving the problem by hand.
Refactoring: Steps to optimize and clean up the manual solution.
AI Solution: A deep dive into how different AI tools approach the problem.
Comparative Analysis: A side-by-side comparison of manual and AI-generated solutions, highlighting strengths, weaknesses, and key takeaways.
The links to the code repository and respective before and after of each code base commits.
A video walk through of the code and process I went through to get to the solution presented in each video & blog post.
A ordered list of the posts as I complete them at the bottom of this post. For starters, as this post has gone live the first post of the series is also live now.
So, get those keyboards and processors ready, grab your favorite code editor, overclock your proc, and join me on this ride through the world of coding with AI. Let’s push the boundaries of what’s possible, one problem at a time.
Stay tuned and happy thrashing coding!
The Ordered List of Coding with AI: A Comparative Series Posts
You must be logged in to post a comment.