DataContext for VS Code
Features
📊 Database Explorer
Browse your database schema directly in VS Code. See tables, columns, types, and primary keys at a glance.
Supported Databases:
- PostgreSQL
- MySQL/MariaDB
- SQLite
- MongoDB (NEW!) — Schema inferred from sample documents
💡 SQL Autocomplete
Intelligent code completion based on your database schema:
- Table names after
FROM, JOIN, INTO
- Column names with
table. notation
- SQL keywords with snippets
- Context-aware suggestions
📝 Inline Descriptions
Hover over table or column names in SQL files to see business descriptions, data types, and constraints.
🚀 SQL Execution
Execute SQL queries directly from VS Code with Cmd+Enter:
- Results displayed in a formatted table panel
- Copy results as CSV or JSON
- Execution time and row count metrics
🤖 AI-Powered SQL Generation
Generate, fix, and explain SQL using LLM providers:
- Generate SQL — Describe what you want in natural language
- Fix SQL — Let AI correct your query based on context
- Explain SQL — Get human-readable explanations
📚 Knowledge Panel
View and manage stored knowledge:
- Relationships — Table relationships and foreign keys ✨
- Business Glossary — Business terms with SQL expressions
- Table Descriptions — What each table represents
- Business Rules — Domain constraints and conventions
- Query Examples — Verified SQL patterns
🕸️ Knowledge Graph ✨ NEW
Automatically discover and visualize table relationships:
- Show Relationships — View all FK relationships in a table
- Find Join Path — Discover how two tables connect (multi-hop)
- Graph Summary — Overview of your schema connections
🌾 Auto-Harvesting
Automatically extract metadata from your database:
- Table/column comments
- Primary keys and indexes
- Foreign key relationships
🛡️ Safety & Cost Estimation
Before running expensive queries:
- Estimate Cost — Preview query impact
- Warnings — Get alerts for potentially slow queries
📊 Feedback & Learning
Record query corrections to improve AI suggestions over time:
- Record Feedback — Track successful queries and corrections
- View Metrics — See success rates and correction patterns
Quick Start
1. Start DataContext Server
npx @kiyeonjeon21/datacontext serve postgres://user:pass@localhost:5432/mydb --port 3000
2. Connect in VS Code
- Open Command Palette (
Cmd+Shift+P)
- Run "DataContext: Connect to Database"
- Enter API URL:
http://localhost:3000
3. Explore
- Click the DataContext icon in the Activity Bar (left sidebar)
- Browse Tables → expand to see columns
- View Knowledge → see descriptions, rules, examples
- Create a
.sql file to test autocomplete
Commands
Connection & Schema
| Command |
Keybinding |
Description |
DataContext: Connect to Database |
— |
Connect to DataContext API server |
DataContext: Disconnect |
— |
Disconnect from server |
DataContext: Switch Connection |
— |
Switch between saved connections |
DataContext: Remove Connection |
— |
Remove a saved connection |
DataContext: Clear All Connections |
— |
Clear all connections |
SQL Execution
| Command |
Keybinding |
Description |
DataContext: Execute Query |
Cmd+Enter |
Execute SQL in editor |
DataContext: Estimate Query Cost |
— |
Analyze query before running |
AI Features
| Command |
Keybinding |
Description |
DataContext: Generate SQL with AI |
Cmd+Shift+G |
Generate SQL from natural language |
DataContext: Fix SQL with AI |
— |
Fix selected SQL with AI |
DataContext: Explain SQL with AI |
— |
Get explanation of SQL query |
DataContext: Set API Key (Secure) |
— |
Store API key securely |
DataContext: Clear API Key |
— |
Remove stored API key |
Knowledge Graph ✨
| Command |
Keybinding |
Description |
DataContext: Show Table Relationships |
— |
View all FK relationships |
DataContext: Find Join Path |
— |
Find path between two tables |
DataContext: Show Knowledge Graph Summary |
— |
View graph statistics |
Knowledge Management
| Command |
Keybinding |
Description |
DataContext: Harvest Metadata |
— |
Auto-extract database metadata |
DataContext: Describe Table/Column |
— |
Add description to table or column |
DataContext: Add Business Rule |
— |
Add a business rule |
DataContext: Add Query Example |
— |
Add a verified query example |
DataContext: Refresh Knowledge |
— |
Refresh knowledge panel |
Business Glossary ✨
| Command |
Keybinding |
Description |
DataContext: Add Term |
— |
Add a business term manually |
DataContext: Generate Glossary with AI |
— |
Generate terms from natural language |
DataContext: Search Terms |
— |
Search business glossary |
DataContext: Delete Term |
— |
Delete a business term |
Feedback & Metrics
| Command |
Keybinding |
Description |
DataContext: Record Feedback |
— |
Record query feedback for learning |
DataContext: View Metrics |
— |
View query success metrics |
DataContext: Show Context Panel |
— |
Show context for current SQL |
Configuration
Basic Settings
{
"datacontext.connections": [
{
"name": "Local Dev",
"connectionString": "http://localhost:3000",
"schema": "public"
}
],
"datacontext.autoHarvest": true,
"datacontext.showInlineDescriptions": true
}
LLM Settings (for AI features)
Configure an LLM provider to enable AI-powered SQL generation:
{
"datacontext.llm.provider": "openai",
"datacontext.llm.apiKey": "sk-your-api-key",
"datacontext.llm.model": "gpt-4o-mini"
}
Supported Providers
| Provider |
Config Value |
Models |
| OpenAI |
"openai" |
gpt-4o-mini, gpt-4o, gpt-3.5-turbo |
| Anthropic |
"anthropic" |
claude-3-haiku-20240307, claude-3-sonnet-20240229 |
| Mock (testing) |
"mock" |
— |
| None (disabled) |
"none" |
— |
Custom Endpoint (Local LLMs)
For local LLMs or proxies:
{
"datacontext.llm.provider": "openai",
"datacontext.llm.endpoint": "http://localhost:11434/v1/chat/completions",
"datacontext.llm.model": "llama2"
}
Right-click in SQL files for quick access:
- Execute Query — Run the current SQL
- Generate SQL with AI — Create SQL from description
- Fix SQL with AI — Fix selected SQL (when text selected)
- Explain SQL with AI — Get explanation
Requirements
- VS Code 1.85.0 or higher
- DataContext API server running (
npx @kiyeonjeon21/datacontext serve ...)
How It Works
This extension connects to a DataContext REST API server (not directly to your database). This architecture:
- Separates concerns — Extension handles UI, server handles database
- Enables sharing — Multiple developers can connect to the same server
- Improves security — Database credentials stay on the server
┌─────────────────┐ HTTP ┌─────────────────┐ SQL ┌──────────┐
│ VS Code Ext │ ───────────▶ │ DataContext │ ──────────▶ │ Database │
│ (This) │ │ API Server │ │ │
└─────────────────┘ └─────────────────┘ └──────────┘
API Endpoints Used
This extension uses the following REST API endpoints from the DataContext server:
Schema & Query
| Endpoint |
Method |
Purpose |
/health |
GET |
Connection health check |
/api/tables |
GET |
List all tables |
/api/tables/:name |
GET |
Get table details with context |
/api/tables/:name/description |
PUT |
Set table description |
/api/tables/:table/columns/:column/description |
PUT |
Set column description |
/api/query |
POST |
Execute SQL query |
/api/query/estimate |
POST |
Estimate query cost |
Knowledge Graph ✨
| Endpoint |
Method |
Purpose |
/api/relationships |
GET |
Get all relationships |
/api/relationships?table=orders |
GET |
Get relationships for a table |
/api/relationships/path?from=X&to=Y |
GET |
Find join path between tables |
/api/graph/summary |
GET |
Get graph statistics |
Knowledge
| Endpoint |
Method |
Purpose |
/api/harvest |
POST |
Run auto-harvesting |
/api/knowledge |
GET |
Get all knowledge (incl. relationships) |
/api/feedback |
POST |
Record query feedback |
/api/metrics |
GET |
Get query metrics |
/api/examples |
POST |
Add query example |
/api/rules |
POST |
Add business rule |
Business Glossary ✨
| Endpoint |
Method |
Purpose |
/api/terms |
GET |
List all business terms |
/api/terms |
POST |
Add a business term |
/api/terms/search?q=query |
GET |
Search terms |
/api/terms/generate |
POST |
Generate glossary with AI |
/api/terms/:id |
DELETE |
Delete a term |
See API Reference for full documentation.
Changelog
See CHANGELOG.md for version history.
License
MIT © DataContext