Hari SQL Generator
A VS Code extension that provides intelligent SQL query generation using GitHub Copilot Chat with real database schema context.
Features
- Real-time Schema Access: Connects directly to your PostgreSQL database to get actual table and column information
- Smart SQL Generation: AI generates queries based on your actual database structure
- Query Execution: Run generated queries and see results directly in VS Code
- Single File Workflow: Reuses the same SQL file to maintain database connections
Quick Start
1. Install & Setup
- Install the extension in VS Code
- Ensure you have GitHub Copilot Chat extension installed
- Open Command Palette (
Ctrl+Shift+P )
- Run "Configure Database Connection"
- Choose between:
- Connection String:
postgresql://username:password@host:port/database
- Individual Settings: Enter host, port, database, username, password separately
3. Test Connection
- Run "Test Database Connection" command
- Check console for connection status
4. Use the Extension
- Open Copilot Chat
- Type:
@sql-generator show me all orders
- Click "Run Query" to execute and see results
Example Usage
@sql-generator show me all customers from New York
@sql-generator get total sales by month
@sql-generator find orders with amount > 1000
How It Works
- Schema Retrieval: Extension queries your database's
information_schema to get real table/column information
- Context Passing: Sends actual schema as context to GitHub Copilot Chat
- Smart Generation: AI generates SQL using your exact table names and columns
- Direct Execution: Runs queries against your database and displays results
Requirements
- VS Code 1.102.0 or higher
- GitHub Copilot Chat extension
- PostgreSQL database (local or remote)
- Node.js and npm (for development)
Extension Settings
This extension contributes the following settings:
hariSqlGenerator.postgresql.host - Database host (default: localhost)
hariSqlGenerator.postgresql.port - Database port (default: 5432)
hariSqlGenerator.postgresql.database - Database name
hariSqlGenerator.postgresql.username - Username
hariSqlGenerator.postgresql.password - Password
hariSqlGenerator.connectionString - Full connection string (overrides individual settings)
Development & Testing
- Clone the repository
- Run
npm install
- Run
npm run compile
- Press
F5 to launch Extension Development Host
- Test the extension in the new VS Code window
Commands
Configure Database Connection - Set up database credentials
Test Database Connection - Verify connectivity
Run PostgreSQL Query - Execute queries with results
Architecture
Based on the proven architecture from Microsoft's copilot-pg extension, featuring:
- Direct database connectivity using pg-promise
- Real-time schema introspection
- DDL format conversion for optimal AI understanding
- Persistent connection pooling
| |