-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
Description
Summary
Add schema-aware validation to catch semantic errors (missing tables, wrong column types, etc.).
Problem
Current validation is syntax-only. Can't detect:
- References to non-existent tables
- References to non-existent columns
- Type mismatches in comparisons
- Foreign key violations
Action Items
-
Add schema definition support:
- Load from DDL files
- Load from database connection
- Load from JSON schema
- Manual schema definition
-
Validate queries against schema:
- Table existence: All referenced tables exist
- Column existence: All referenced columns exist in tables
- Data type compatibility: Comparisons use compatible types
- Foreign key relationships: JOINs respect FK constraints
- Aggregate compatibility: GROUP BY includes all non-aggregated columns
- Function signatures: Correct argument types
-
CLI integration:
gosqlx validate --schema schema.sql query.sql gosqlx validate --db "postgres://..." query.sql -
API for programmatic use
Acceptance Criteria
- Schema loading from multiple sources (DDL, database, JSON)
- Semantic validation implemented
- Helpful error messages with suggestions
- Examples for common use cases
- Performance: < 2x syntax-only validation
Technical Details
Priority: Low
Effort: Large (120h)
Phase: Phase 7 - Advanced Features
Dependencies: FEAT-001 (SQL-99 compliance)
Example
-- Schema
CREATE TABLE users (id INT, name VARCHAR);
-- Query
SELECT email FROM users;
-- Error
Column 'email' does not exist in table 'users'
Available columns: id, name
Did you mean 'name'?